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

Commit

Permalink
Merge pull request #65 from apiaryio/honzajavorek/fixes
Browse files Browse the repository at this point in the history
Wait for process to be killed before temporary directory gets removed
  • Loading branch information
honzajavorek authored Jun 6, 2019
2 parents 9be7727 + d3431ca commit 3e63d0a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
22 changes: 19 additions & 3 deletions features/support/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const fs = require('fs-extra');
const net = require('net');
const url = require('url');
const which = require('which');
const kill = require('tree-kill');
const pidtree = require('pidtree');
const {
Given,
When,
Expand All @@ -25,8 +25,24 @@ Before(function hook() {
});

After(async function hook() {
fs.remove(this.dir);
await util.promisify(kill)(this.proc.pid);
// kill all running processes
const pids = [];
try {
pids.push(...await pidtree(this.proc.pid));
} catch (error) {
// the process doesn't exist anymore
}
pids.forEach((pid) => {
try {
process.kill(pid, 'SIGKILL');
} catch (error) {
// re-throw except in case it is 'ESRCH' (process cannot be found)
if (error.code !== 'ESRCH') throw error;
}
});

// remove the temporary directory
return fs.remove(this.dir);
});


Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"dredd": "11.2.6",
"fs-extra": "8.0.1",
"glob": "7.1.4",
"tree-kill": "1.2.1",
"pidtree": "0.3.0",
"which": "1.3.1"
},
"devDependencies": {
Expand Down

0 comments on commit 3e63d0a

Please sign in to comment.