Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created December 13, 2016 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacs/9b05a4010304bdacd01fd8400fd74d94 to your computer and use it in GitHub Desktop.
Save isaacs/9b05a4010304bdacd01fd8400fd74d94 to your computer and use it in GitHub Desktop.
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