/
issue121-test.js
54 lines (49 loc) · 1.37 KB
/
issue121-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* eslint-disable no-octal */
// vim: expandtab:ts=2:sw=2
const
assertions = require('./assertions'),
childProcess = require('./child-process').childProcess,
os = require('os'),
rimraf = require('rimraf'),
testCases = [
{ signal: 'SIGINT', expectExists: false },
{ signal: 'SIGTERM', expectExists: true }
];
// skip tests on win32
const isWindows = os.platform() === 'win32';
const tfunc = isWindows ? xit : it;
describe('tmp', function () {
describe('issue121 - clean up on terminating signals', function () {
for (let tc of testCases) {
tfunc('for signal ' + tc.signal, function (done) {
// increase timeout so that the child process may fail
this.timeout(20000);
issue121Tests(tc.signal, tc.expectExists)(done);
});
}
});
});
function issue121Tests(signal, expectExists) {
return function (done) {
childProcess(this, 'issue121.json', function (err, stderr, stdout) {
if (err) return done(err);
else if (stderr) return done(new Error(stderr));
try {
if (expectExists) {
assertions.assertExists(stdout);
}
else {
assertions.assertDoesNotExist(stdout);
}
done();
} catch (err) {
done(err);
} finally {
// cleanup
if (expectExists) {
rimraf.sync(stdout);
}
}
}, signal);
};
}