Skip to content

Commit

Permalink
shim error object returned by exec() to make it consistent between OS…
Browse files Browse the repository at this point in the history
…X and Linux see #14
  • Loading branch information
Benjamin Coe committed Dec 26, 2015
1 parent 8d50231 commit 42b0b0e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"homepage": "https://github.com/bcoe/signal-exit",
"devDependencies": {
"chai": "^2.3.0",
"code-to-signal": "^1.0.2",
"coveralls": "^2.11.2",
"nyc": "^2.1.2",
"standard": "^3.9.0",
Expand Down
11 changes: 7 additions & 4 deletions test/all-integration-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* global describe, it */

var exec = require('child_process').exec,
assert = require('assert')
var exec = require('child_process').exec
var assert = require('assert')
var codeToSignal = require('code-to-signal')

require('chai').should()
require('tap').mochaGlobals()
Expand Down Expand Up @@ -33,14 +34,16 @@ describe('all-signals-integration-test', function () {
if (process.env.TRAVIS && sig === 'SIGUSR1') return done()

exec(node + ' ' + js + ' ' + sig, function (err, stdout, stderr) {
codeToSignal.shimError(err)

if (sig) {
assert(err)
if (!isNaN(sig)) {
assert.equal(err.code, sig)
} else if (!weirdSignal(sig)) {
if (!process.env.TRAVIS) err.signal.should.equal(sig)
err.signal.should.equal(sig)
} else if (sig) {
if (!process.env.TRAVIS) assert(err.signal)
assert(err.signal)
}
} else {
assert.ifError(err)
Expand Down
14 changes: 6 additions & 8 deletions test/signal-exit-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* global describe, it */

var exec = require('child_process').exec,
expect = require('chai').expect,
assert = require('assert')
var exec = require('child_process').exec
var expect = require('chai').expect
var assert = require('assert')
var codeToSignal = require('code-to-signal')

require('chai').should()
require('tap').mochaGlobals()
Expand Down Expand Up @@ -81,13 +82,10 @@ describe('signal-exit', function () {
// TODO: test on a few non-OSX machines.
it('removes handlers when fully unwrapped', function (done) {
exec(process.execPath + ' ./test/fixtures/unwrap.js', function (err, stdout, stderr) {
// on Travis CI no err.signal is populated but
// err.code is 129 (which I think tends to be SIGHUP).
var expectedCode = process.env.TRAVIS ? 129 : null
codeToSignal.shimError(err)

assert(err)
if (!process.env.TRAVIS) err.signal.should.equal('SIGHUP')
expect(err.code).to.equal(expectedCode)
err.signal.should.equal('SIGHUP')
done()
})
})
Expand Down

0 comments on commit 42b0b0e

Please sign in to comment.