Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit 3e63d0a

Browse files
authored
Merge pull request #65 from apiaryio/honzajavorek/fixes
Wait for process to be killed before temporary directory gets removed
2 parents 9be7727 + d3431ca commit 3e63d0a

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

features/support/steps.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const fs = require('fs-extra');
77
const net = require('net');
88
const url = require('url');
99
const which = require('which');
10-
const kill = require('tree-kill');
10+
const pidtree = require('pidtree');
1111
const {
1212
Given,
1313
When,
@@ -25,8 +25,24 @@ Before(function hook() {
2525
});
2626

2727
After(async function hook() {
28-
fs.remove(this.dir);
29-
await util.promisify(kill)(this.proc.pid);
28+
// kill all running processes
29+
const pids = [];
30+
try {
31+
pids.push(...await pidtree(this.proc.pid));
32+
} catch (error) {
33+
// the process doesn't exist anymore
34+
}
35+
pids.forEach((pid) => {
36+
try {
37+
process.kill(pid, 'SIGKILL');
38+
} catch (error) {
39+
// re-throw except in case it is 'ESRCH' (process cannot be found)
40+
if (error.code !== 'ESRCH') throw error;
41+
}
42+
});
43+
44+
// remove the temporary directory
45+
return fs.remove(this.dir);
3046
});
3147

3248

package-lock.json

Lines changed: 5 additions & 5 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"dredd": "11.2.6",
1515
"fs-extra": "8.0.1",
1616
"glob": "7.1.4",
17-
"tree-kill": "1.2.1",
17+
"pidtree": "0.3.0",
1818
"which": "1.3.1"
1919
},
2020
"devDependencies": {

0 commit comments

Comments
 (0)