Created
December 13, 2016 18:13
-
-
Save isaacs/9b05a4010304bdacd01fd8400fd74d94 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sw = require('../') | |
if (process.argv[2] === 'wrapper') { | |
// note: this should never happen, | |
// because -e invocations aren't wrapped | |
console.error('wrapper') | |
sw.runMain() | |
return | |
} | |
var t = require('tap') | |
var cp = require('child_process') | |
var spawn = cp.spawn | |
var exec = cp.exec | |
var node = process.execPath | |
t.test('wrap a -e invocation', function (t) { | |
sw([__filename, 'wrapper']) | |
var script = [ | |
"process.on('SIGTERM', function() { console.log('ignore!') })", | |
"setInterval(function() {", | |
" console.log('wtf')", | |
"}, 40)" | |
].join('\n') | |
var child = spawn(node, ['-e', script]) | |
var out = '' | |
var err = '' | |
child.stdout.on('data', function (c) { out += c }) | |
child.stderr.on('data', function (c) { err += c }) | |
child.on('close', function (code, signal) { | |
clearTimeout(timer) | |
var actual = { | |
out: out, | |
err: err, | |
code: code, | |
signal: signal | |
} | |
var expect = { | |
out: /^(wtf\n)*ignore!\n(wtf\n)*$/, | |
err: '', | |
code: null, | |
signal: 'SIGKILL' | |
} | |
t.match(actual, expect) | |
t.end() | |
}) | |
var timer= setTimeout(function () { | |
child.kill('SIGTERM') | |
timer = setTimeout(function () { | |
child.kill('SIGKILL') | |
}, 150) | |
}, 150) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment