These are chat archives for rosshinkley/nightmare

9th
May 2016
Rob Brackett
@Mr0grog
May 09 2016 05:36
@rosshinkley w/r/t segmentio/nightmare#502, I wonder if I might have done a disservice there with the idea of auto-running XVFB always (instead of at test-time). Maybe the first order of business is to just solve the problem at hand (no make on Windows) by replacing the make script with a node script that calls test/bb-xvfbwhen on Linux and wanting XVFB support. Make the auto-stuff separate work, since it seems vastly more complicated and speculative.
Rick Medina
@rickmed
May 09 2016 18:04
hey guys quick couple of questions
what is the run method used for?
how would I use it let's say if I need to extract info at different times in the script...
nightmare
  .goto('http://cnn.com')
  .evaluate(function(){
    return document.title;
  })
  .then(function(title){
    console.log(title);
  })

nightmare
  .goto('http://google.com')
  .url()
  .end()
  .then(function(url){
    console.log(url);
  })
so, go to cnn.com, get me the title, then go to goole, get met the url
Rick Medina
@rickmed
May 09 2016 18:20
no need to answer 2nd question. I see that return values are async so need to chain promises or use async/await, etc
Rob Brackett
@Mr0grog
May 09 2016 19:01
@rickmed You can think of run() and then() as slightly different ways to do the same thing
then() is the promise-based way—it works just like a promise’s then() and also returns a promise itself (So you can nightmare.something().then(...).then(...).then(...)
run() is the callback-based way—it works like callbacks in most built-in Node.js modules
Rick Medina
@rickmed
May 09 2016 19:04
@Mr0grog thanks, I guess that's why I see no run uses on the home page? intent is to go from run to promises?
Rob Brackett
@Mr0grog
May 09 2016 19:05
So these two scripts do pretty much the same exact thing:
nightmare
  .goto('http://google.com')
  .url()
  .end()
  .then(function(url){
    console.log(url);
  })
  .catch(function(error) {
    console.error(‘uhoh!', error);
  });

nightmare
  .goto('http://google.com')
  .url()
  .end()
  .run(function(error, url){
    if (error) { return console.error('uhoh!' error); }
    console.log(url);
  });
Yeah, run() being the primary API predates me. @matthewmueller pretty much stated that then() (or promises) is the “official” API now
The timeline is something like:
  1. Call run()
  2. Never call run(), just use generators/coroutines (which is when then() came on the scene—async generators work on promises and so required then(), but then was considered an “implementation detail” for Nightmare at this point)
  3. Requiring people to have and understand all the overhead of an async generator library is too much, so just recommend then()
Rob Brackett
@Mr0grog
May 09 2016 19:10

intent is to go from run to promises?

More or less. There’s a lot of contention wrapped up in specifically what it means to be totally focused on promises, but in broad strokes, then intention is to focus on then() which means focusing on promises in at least some sense.

Rick Medina
@rickmed
May 09 2016 19:12
yeap, i get it...
thanks!
Rob Brackett
@Mr0grog
May 09 2016 19:16
np