Medium / phantomjs

NPM wrapper for installing phantomjs
Other
1.43k stars 435 forks source link

Adds methods: exec() and run() #588

Closed cognitom closed 8 years ago

cognitom commented 8 years ago

To use phantomjs-prebuilt with WebDriver, we needed to detect when PhantomJS gets ready. But that was little bit messy, like this:

new Promise((resolve, reject) => {
  const program = spawn(phantomjs.path, ['--webdriver=4444'])
  let isFirst = true
  program.stdout.on('data', data => {
    // This detects PhantomJS instance get ready.
    if (!isFirst) return
    isFirst = false
    resolve(program)
  })
}).then(program => {
  // do something
  program.kill()
})

By this PR, it'll be easy and readable:

phantomjs.run('--webdriver=4444').then(program => {
  // do something
  program.kill()
})

If you like this PR, I'd like to add some README text, too. Thanks.

nicks commented 8 years ago

cool! i like this!

can you fill out a CLA real quick? https://github.com/Medium/opensource/blob/master/sign-cla.md

cognitom commented 8 years ago

@nicks sure! Will do.

cognitom commented 8 years ago

@nicks the logic is wrapped by try block now 😄 Could you have a look?

Updated: README.md, too.

nicks commented 8 years ago

thanks!