Skip to content

Commit 465d6f9

Browse files
committed
Don't use detached or shell for spawn, use terminate
1 parent 91de516 commit 465d6f9

4 files changed

Lines changed: 75 additions & 10 deletions

File tree

package-lock.json

Lines changed: 70 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"pretty-ms": "^3.1.0",
4040
"recursive-copy": "^2.0.9",
4141
"strip-ansi": "^4.0.0",
42+
"terminate": "^2.1.0",
4243
"yargs": "^9.0.1"
4344
},
4445
"devDependencies": {

src/mutantRunner.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const spawn = require('child_process').spawn
33
const Debug = require('debug')
44
const fs = require('fs')
55
const path = require('path')
6+
const terminate = require('terminate')
67

78
/**
89
* @module MutantRunner
@@ -16,19 +17,14 @@ module.exports = function MutantRunner ({mutodeInstance, filePath, contentToWrit
1617
await new Promise(resolve => {
1718
const startTime = process.hrtime()
1819
fs.writeFileSync(`.mutode/mutode-${mutodeInstance.id}-${index}/${filePath}`, contentToWrite)
19-
const child = spawn(mutodeInstance.npmCommand, ['test'], {
20-
cwd: path.resolve(`.mutode/mutode-${mutodeInstance.id}-${index}`),
21-
detached: true,
22-
shell: true
23-
})
20+
const child = spawn(mutodeInstance.npmCommand, ['test'], {cwd: path.resolve(`.mutode/mutode-${mutodeInstance.id}-${index}`)})
2421

2522
child.stderr.on('data', data => {
2623
debug(data.toString())
2724
})
2825

2926
const timeout = setTimeout(() => {
30-
child.kill('SIGKILL')
31-
process.kill(-child.pid)
27+
terminate(child.pid)
3228
}, mutodeInstance.timeout).unref()
3329

3430
child.on('exit', (code, signal) => {

src/mutode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class Mutode {
208208
async timeCleanTests () {
209209
console.log(`Verifying and timing your test suite`)
210210
const start = +new Date()
211-
const child = spawn(this.npmCommand, ['test'], {cwd: path.resolve(`.mutode/mutode-${this.id}-0`), shell: true})
211+
const child = spawn(this.npmCommand, ['test'], {cwd: path.resolve(`.mutode/mutode-${this.id}-0`)})
212212

213213
child.stderr.on('data', data => {
214214
debug(data.toString())

0 commit comments

Comments
 (0)