Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report to stderr when phantom exited abnormally #10

Merged
merged 1 commit into from
Jun 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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