Skip to content

Commit

Permalink
fix test for #121
Browse files Browse the repository at this point in the history
  • Loading branch information
silkentrance committed Mar 16, 2019
1 parent 0c5bc5c commit 980438c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 26 deletions.
16 changes: 1 addition & 15 deletions lib/tmp.js
Expand Up @@ -575,7 +575,7 @@ function _is_legacy_listener(listener) {

/**
* Safely install process exit listeners.
*
*
* @private
*/
function _safely_install_listener() {
Expand All @@ -593,20 +593,6 @@ function _safely_install_listener() {
}
}

// windows does not support signals
// it'd never had won if it wasn't a major PITA
// with node v8.x and win 10 this is no longer an issue
if (process.platform == 'win32') {
var rl = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});

rl.on('SIGINT', function () {
process.emit('SIGINT');
});
}

process.on('SIGINT', function () {
process.exit(0);
});
Expand Down
2 changes: 0 additions & 2 deletions test/child-process.js
Expand Up @@ -48,8 +48,6 @@ function _doSpawn(commandArgs, cb) {
child = spawn(node_path, commandArgs);
child.stdin.end();

// TODO we no longer support node 0.6
// Cannot use 'close' event because not on node-0.6.
function _close() {
var
stderr = _bufferConcat(stderrBufs).toString(),
Expand Down
12 changes: 7 additions & 5 deletions test/issue121-test.js
Expand Up @@ -2,25 +2,27 @@
// vim: expandtab:ts=2:sw=2

const
assert = require('assert'),
assertions = require('./assertions'),
childProcess = require('./child-process').childProcess,
signals = ['SIGINT', 'SIGTERM'];

describe('tmp', function () {
describe('issue121 - clean up on terminating signals', function () {
for (var i=0; i < signals.length; i++) {
issue121Tests(signals[i]);
for (var i = 0; i < signals.length; i++) {
it('for signal ' + signals[i], function (done) {
issue121Tests(signals[i])(done);
});
}
});
});

function issue121Tests(signal) {
return function (done) {
childProcess('issue121.json', function (err, stderr, stdout) {
childProcess(this, 'issue121.json', function (err, stderr, stdout) {
if (err) return done(err);
else if (stderr) return done(new Error(stderr));
else assertions.assertDoesNotExist(stdout);
console.log(stdout);
assertions.assertDoesNotExist(stdout);
done();
}, true);
};
Expand Down
15 changes: 11 additions & 4 deletions test/outband/issue121.js
Expand Up @@ -11,10 +11,17 @@ tmp.setGracefulCleanup();

// https://github.com/raszi/node-tmp/issues/121
module.exports = function (signal) {
fixture.apply(this, [tmp.dirSync({ unsafeCleanup: true }), tmp]);

// make sure that the process keeps running
setTimeout(function () {}, 1000000);
try {
fixture.apply(this, [tmp.dirSync({ unsafeCleanup: true }), tmp]);
}
catch (ex) {
console.err(ex);
throw ex;
}

this.kill(signal);
var othis = this;

// we will now end this process, triggering tmp's exit handler
setTimeout(function () { othis.kill(signal) }, 1000);
};

0 comments on commit 980438c

Please sign in to comment.