Skip to content

Commit

Permalink
Merge pull request #10 from fardog/better-exit-messages
Browse files Browse the repository at this point in the history
Report to stderr when phantom exited abnormally
  • Loading branch information
fardog committed Jun 2, 2015
2 parents 0f724fa + 3526eed commit ea66ec7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
23 changes: 18 additions & 5 deletions bin/ghostface.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ var cli = require('../lib/cli')

var error = chalk.bold.red

cli(process.argv.slice(2), function(err, message, options) {
module.exports = {
exit: onExit
, cli: onCli
}

cli(process.argv.slice(2), onCli)

function onCli(err, message, options) {
if(err) {
console.error(
error(
Expand All @@ -27,7 +34,13 @@ cli(process.argv.slice(2), function(err, message, options) {
return
}

lib(options, process, function(code) {
process.exit(code)
})
})
lib(options, process, onExit)
}

function onExit(code, signal) {
if(code > 0) {
console.error(sprintf('\nphantomjs exited abnormally: %d'), code)
}

process.exit(code || signal === 'SIGTERM' ? 0 : 1)
}
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function phantomEval(options, io, _next) {
function onExit(code, signal) {
dead = true

next(code || (signal === 'SIGTERM' ? 0 : 1))
next(code, signal)
}

// TODO: this section requires significant cleanup
Expand Down
18 changes: 9 additions & 9 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ test('executes simple js', function(t) {

lib(options, p, done)

function done(code) {
t.equal(code, 0, 'exit code should be clean')
function done(code, signal) {
t.equal(signal, 'SIGTERM', 'should have been terminated')
}
})

Expand All @@ -50,8 +50,8 @@ test('loads the requested html file', function(t) {

lib(options, p, done)

function done(code) {
t.equal(code, 0, 'exit code should be clean')
function done(code, signal) {
t.equal(signal, 'SIGTERM', 'should have been terminated')
}
})

Expand All @@ -74,8 +74,8 @@ test('executes fibonacci for some reason', function(t) {

lib(options, p, done)

function done(code) {
t.equal(code, 0, 'exit code should be clean')
function done(code, signal) {
t.equal(signal, 'SIGTERM', 'should have been terminated')
}
})

Expand Down Expand Up @@ -107,7 +107,7 @@ test('fails and sets correct exit code', function(t) {

lib(options, p, done)

function done(code) {
function done(code, signal) {
p.stderr.write(null)
t.equal(code, 1, 'exit code should not be clean')
}
Expand All @@ -134,8 +134,8 @@ test('handles timeouts when set', function(t) {

lib(options, p, done)

function done(code) {
t.equal(code, 0, 'exit code should be clean')
function done(code, signal) {
t.equal(signal, 'SIGTERM', 'should have been terminated')
}
})

Expand Down

0 comments on commit ea66ec7

Please sign in to comment.