Skip to content

zeekay/joseph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Note: Deprecated!

This is no longer necessary as Nightmare now supports async evaluations out of the box :)

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);
});

About

Better dream interpretation support for Nightmare.

Resources

License

Stars

Watchers

Forks

Packages

No packages published