Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

joseph

0.2.10 • Public • Published

joseph Build Status Coverage Status NPM version Gitter chat

Do promises and asynchronous code give you nightmares? We're here to help!

Updates Nightmare's evaluate with support for promises, Node.js style callbacks, generators and more.

Install

$ npm install joseph

Usage

 
// Patch Nightmare
var Nightmare = require('joseph')(require('nightmare'))
// ...or
var Nightmare = require('joseph/nightmare');
 
function *run() {
  var nightmare = Nightmare();
 
  // Go somewhere
  nightmare.goto('about:config')
 
  // Return promises
  var res = yield nightmare.evaluate(function() {
    return Promise.resolve('promise all the things')
  });
  console.log(res);
 
  // Generators for control-flow
  var res = yield nightmare.evaluate(function *() {
    var msg = '';
    msg += yield Promise.resolve('generators');
    msg += yield Promise.resolve(' + ');
    msg += yield Promise.resolve('promises');
    msg += yield Promise.resolve(' = <3 ');
    yield msg;
  });
  console.log(res);
 
  // Callbacks are okay too!
  var res = yield nightmare.evaluate(function (cb) {
    cb(null, 'callbacks are still hip')
  });
  console.log(res);
 
  yield nightmare.end();
}
 
// Run with vo
require('vo')(run)(function (err) {
  if (err) console.error(err.stack);
});

Install

npm i joseph

DownloadsWeekly Downloads

1

Version

0.2.10

License

MIT

Last publish

Collaborators

  • avatar