diff --git a/package.json b/package.json index 5dcc1fd..5d81394 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "scripts": { "lint": "eslint lib --env mocha test", "clean": "rm -Rf ./coverage", - "test": "istanbul cover ./node_modules/mocha/bin/_mocha --report none --print none --dir ./coverage/json -u exports -R test/*-test.js && istanbul report --root ./coverage/json html && istanbul report text-summary", + "test": "npm run clean && istanbul cover ./node_modules/mocha/bin/_mocha --report none --print none --dir ./coverage/json -u exports -R test/*-test.js && istanbul report --root ./coverage/json html && istanbul report text-summary", "doc": "jsdoc -c .jsdoc.json" } } diff --git a/test/assertions.js b/test/assertions.js index e734fd8..8e7a246 100644 --- a/test/assertions.js +++ b/test/assertions.js @@ -1,6 +1,6 @@ /* eslint-disable no-octal */ -const +var assert = require('assert'), fs = require('fs'), path = require('path'), @@ -18,7 +18,7 @@ module.exports.assertName = function assertName(name, expected) { module.exports.assertMode = function assertMode(name, mode) { - const stat = fs.statSync(name); + var stat = fs.statSync(name); // mode values do not work properly on Windows. Ignore “group” and // “other” bits then. Ignore execute bit on that platform because it @@ -57,7 +57,7 @@ module.exports.assertProperResult = function assertProperResult(result, withfd) module.exports.assertExists = function assertExists(name, isfile) { assert.ok(existsSync(name), name + ' should exist'); - const stat = fs.statSync(name); + var stat = fs.statSync(name); if (isfile) assert.ok(stat.isFile(), name + ' should be a file'); else assert.ok(stat.isDirectory(), name + ' should be a directory'); }; diff --git a/test/child-process.js b/test/child-process.js index c7f0e49..ce189e2 100644 --- a/test/child-process.js +++ b/test/child-process.js @@ -1,81 +1,80 @@ // vim: expandtab:ts=2:sw=2 -const +var fs = require('fs'), path = require('path'), - existsSync = fs.existsSync || path.existsSync, + exists = fs.exists || path.exists, spawn = require('child_process').spawn; +const ISTANBUL_PATH = path.join(__dirname, '..', 'node_modules', 'istanbul', 'lib', 'cli.js'); -module.exports.genericChildProcess = function spawnGenericChildProcess(configFile, cb) { - const - configFilePath = path.join(__dirname, 'outband', configFile), - command_args = [path.join(__dirname, 'spawn-generic.js'), configFilePath]; +module.exports.genericChildProcess = _spawnProcess('spawn-generic.js'); +module.exports.childProcess = _spawnProcess('spawn-custom.js'); - // make sure that the config file exists - if (!existsSync(configFilePath)) - return cb(new Error('ENOENT: configFile ' + configFilePath + ' does not exist')); +function _spawnProcess(spawnFile) { + return function (testCase, configFile, cb) { + var + configFilePath = path.join(__dirname, 'outband', configFile), + commandArgs = [path.join(__dirname, spawnFile), configFilePath]; - _do_spawn(command_args, cb); -}; + exists(configFilePath, function (configExists) { + if (configExists) return _doSpawn(commandArgs, cb); -module.exports.childProcess = function spawnChildProcess(configFile, cb, detach) { - var - configFilePath = path.join(__dirname, 'outband', configFile), - command_args = [path.join(__dirname, 'spawn-custom.js'), configFilePath]; - - // make sure that the config file exists - if (!existsSync(configFilePath)) - return cb(new Error('ENOENT: configFile ' + configFilePath + ' does not exist')); - - if (arguments.length > 2) { - for (var i=2; i < arguments.length; i++) { - command_args.push(arguments[i]); - } - } - - _do_spawn(command_args, cb, detach); + cb(new Error('ENOENT: configFile ' + configFilePath + ' does not exist')); + }); + }; } -function _do_spawn(command_args, cb, detach) { - const +function _doSpawn(commandArgs, cb) { + var node_path = process.argv[0], stdoutBufs = [], - stderrBufs = []; - - var + stderrBufs = [], child, done = false, stderrDone = false, stdoutDone = false; + if (process.env.running_under_istanbul) { + commandArgs = [ + ISTANBUL_PATH, 'cover', '--report' , 'none', '--print', 'none', + '--dir', path.join('coverage', 'json'), '--include-pid', + commandArgs[0], '--', commandArgs[1] + ]; + } + // spawn doesn’t have the quoting problems that exec does, // especially when going for Windows portability. - child = spawn(node_path, command_args, detach ? { detached: true } : undefined); + child = spawn(node_path, commandArgs); child.stdin.end(); - // TODO:we no longer support node <0.10.0 + + // TODO we no longer support node 0.6 // Cannot use 'close' event because not on node-0.6. function _close() { - const + var stderr = _bufferConcat(stderrBufs).toString(), stdout = _bufferConcat(stdoutBufs).toString(); + if (stderrDone && stdoutDone && !done) { done = true; cb(null, stderr, stdout); } } + child.on('error', function _spawnError(err) { if (!done) { done = true; cb(err); } }); + child.stdout.on('data', function _stdoutData(data) { stdoutBufs.push(data); }).on('close', function _stdoutEnd() { stdoutDone = true; _close(); }); + child.stderr.on('data', function _stderrData(data) { stderrBufs.push(data); }).on('close', function _stderrEnd() { @@ -87,13 +86,13 @@ function _do_spawn(command_args, cb, detach) { function _bufferConcat(buffers) { if (Buffer.concat) { return Buffer.concat.apply(this, arguments); - } else { - return new Buffer(buffers.reduce(function (acc, buf) { - for (var i = 0; i < buf.length; i++) { - acc.push(buf[i]); - } - return acc; - }, [])); } + + return new Buffer(buffers.reduce(function (acc, buf) { + for (var i = 0; i < buf.length; i++) { + acc.push(buf[i]); + } + return acc; + }, [])); } diff --git a/test/dir-sync-test.js b/test/dir-sync-test.js index 4f43bda..fb5d410 100644 --- a/test/dir-sync-test.js +++ b/test/dir-sync-test.js @@ -1,13 +1,14 @@ /* eslint-disable no-octal */ // vim: expandtab:ts=2:sw=2 -const +var assert = require('assert'), fs = require('fs'), path = require('path'), inbandStandardTests = require('./inband-standard'), childProcess = require('./child-process').genericChildProcess, assertions = require('./assertions'), + rimraf = require('rimraf'), tmp = require('../lib/tmp'); @@ -50,8 +51,13 @@ describe('tmp', function () { it('on graceful cleanup', function (done) { childProcess(this, 'graceful-dir-sync.json', function (err, stderr, stdout) { if (err) return done(err); - else if (!stderr) assert.fail('stderr expected'); - else assertions.assertDoesNotExist(stdout); + if (!stderr) return done(new Error('stderr expected')); + try { + assertions.assertDoesNotExist(stdout); + } catch (err) { + rimraf.sync(stdout); + return done(err); + } done(); }); }); @@ -59,10 +65,12 @@ describe('tmp', function () { it('on non graceful cleanup', function (done) { childProcess(this, 'non-graceful-dir-sync.json', function (err, stderr, stdout) { if (err) return done(err); - else if (!stderr) assert.fail('stderr expected'); - else { + if (!stderr) return done(new Error('stderr expected')); + try { assertions.assertExists(stdout); - fs.rmdirSync(stdout); + rimraf.sync(stdout); + } catch (err) { + return done(err); } done(); }); @@ -71,10 +79,12 @@ describe('tmp', function () { it('on keep', function (done) { childProcess(this, 'keep-dir-sync.json', function (err, stderr, stdout) { if (err) return done(err); - else if (stderr) assert.fail(stderr); - else { + if (stderr) return done(new Error(stderr)); + try { assertions.assertExists(stdout); - fs.rmdirSync(stdout); + rimraf.sync(stdout); + } catch (err) { + return done(err); } done(); }); @@ -83,8 +93,13 @@ describe('tmp', function () { it('on unlink (keep == false)', function (done) { childProcess(this, 'unlink-dir-sync.json', function (err, stderr, stdout) { if (err) return done(err); - else if (stderr) assert.fail(stderr); - else assertions.assertDoesNotExist(stdout); + if (stderr) return done(new Error(stderr)); + try { + assertions.assertDoesNotExist(stdout); + } catch (err) { + rimraf.sync(stdout); + return done(err); + } done(); }); }); @@ -92,12 +107,12 @@ describe('tmp', function () { it('on unsafe cleanup', function (done) { childProcess(this, 'unsafe-sync.json', function (err, stderr, stdout) { if (err) return done(err); - else if (stderr) assert.fail(stderr); - else { + if (stderr) return done(new Error(stderr)); + try { assertions.assertDoesNotExist(stdout); - const basepath = path.join(__dirname, 'outband', 'fixtures', 'symlinkme'); - assertions.assertExists(basepath); - assertions.assertExists(path.join(basepath, 'file.js'), true); + } catch (err) { + rimraf.sync(stdout); + return done(err); } done(); }); @@ -106,17 +121,17 @@ describe('tmp', function () { it('on non unsafe cleanup', function (done) { childProcess(this, 'non-unsafe-sync.json', function (err, stderr, stdout) { if (err) return done(err); - else if (stderr) assert.fail(stderr); - else { + if (stderr) return done(new Error(stderr)); + try { assertions.assertExists(stdout); assertions.assertExists(path.join(stdout, 'should-be-removed.file'), true); if (process.platform == 'win32') assertions.assertExists(path.join(stdout, 'symlinkme-target'), true); else assertions.assertExists(path.join(stdout, 'symlinkme-target')); - fs.unlinkSync(path.join(stdout, 'should-be-removed.file')); - fs.unlinkSync(path.join(stdout, 'symlinkme-target')); - fs.rmdirSync(stdout); + rimraf.sync(stdout); + } catch (err) { + return done(err); } done(); }); @@ -127,8 +142,13 @@ describe('tmp', function () { it('on issue #62', function (done) { childProcess(this, 'issue62-sync.json', function (err, stderr, stdout) { if (err) return done(err); - else if (stderr) assert.fail(stderr); - else assertions.assertDoesNotExist(stdout); + if (stderr) return done(new Error(stderr)); + try { + assertions.assertDoesNotExist(stdout); + } catch (err) { + rimraf.sync(stdout); + return done(err); + } done(); }); }); diff --git a/test/dir-test.js b/test/dir-test.js index d52e89a..774ec89 100644 --- a/test/dir-test.js +++ b/test/dir-test.js @@ -1,13 +1,14 @@ /* eslint-disable no-octal */ // vim: expandtab:ts=2:sw=2 -const +var assert = require('assert'), fs = require('fs'), path = require('path'), inbandStandardTests = require('./inband-standard'), childProcess = require('./child-process').genericChildProcess, assertions = require('./assertions'), + rimraf = require('rimraf'), tmp = require('../lib/tmp'); @@ -19,27 +20,33 @@ describe('tmp', function () { describe('#dir()', function () { describe('when running inband standard tests', function () { inbandStandardTests(false, function before(done) { - const that = this; + var that = this; tmp.dir(this.opts, function (err, name, removeCallback) { - if (err) done(err); - else { - that.topic = { name: name, removeCallback: removeCallback }; - done(); - } + if (err) return done(err); + that.topic = { name: name, removeCallback: removeCallback }; + done(); }); }); describe('with invalid tries', function () { it('should result in an error on negative tries', function (done) { tmp.dir({ tries: -1 }, function (err) { - assert.ok(err instanceof Error, 'should have failed'); + try { + assert.ok(err instanceof Error, 'should have failed'); + } catch (err) { + return done(err); + } done(); }); }); it('should result in an error on non numeric tries', function (done) { tmp.dir({ tries: 'nan' }, function (err) { - assert.ok(err instanceof Error, 'should have failed'); + try { + assert.ok(err instanceof Error, 'should have failed'); + } catch (err) { + return done(err); + } done(); }); }); @@ -54,8 +61,13 @@ describe('tmp', function () { it('on graceful cleanup', function (done) { childProcess(this, 'graceful-dir.json', function (err, stderr, stdout) { if (err) return done(err); - else if (!stderr) assert.fail('stderr expected'); - else assertions.assertDoesNotExist(stdout); + if (!stderr) return done(new Error('stderr expected')); + try { + assertions.assertDoesNotExist(stdout); + } catch (err) { + rimraf.sync(stdout); + return done(err); + } done(); }); }); @@ -63,10 +75,12 @@ describe('tmp', function () { it('on non graceful cleanup', function (done) { childProcess(this, 'non-graceful-dir.json', function (err, stderr, stdout) { if (err) return done(err); - else if (!stderr) assert.fail('stderr expected'); - else { + if (!stderr) return done(new Error('stderr expected')); + try { assertions.assertExists(stdout); - fs.rmdirSync(stdout); + rimraf.sync(stdout); + } catch (err) { + return done(err); } done(); }); @@ -75,10 +89,12 @@ describe('tmp', function () { it('on keep', function (done) { childProcess(this, 'keep-dir.json', function (err, stderr, stdout) { if (err) return done(err); - else if (stderr) assert.fail(stderr); - else { + if (stderr) return done(new Error(stderr)); + try { assertions.assertExists(stdout); - fs.rmdirSync(stdout); + rimraf.sync(stdout); + } catch (err) { + return done(err); } done(); }); @@ -87,8 +103,13 @@ describe('tmp', function () { it('on unlink (keep == false)', function (done) { childProcess(this, 'unlink-dir.json', function (err, stderr, stdout) { if (err) return done(err); - else if (stderr) assert.fail(stderr); - else assertions.assertDoesNotExist(stdout); + if (stderr) return done(new Error(stderr)); + try { + assertions.assertDoesNotExist(stdout); + } catch (err) { + rimraf.sync(stdout); + return done(err); + } done(); }); }); @@ -96,12 +117,12 @@ describe('tmp', function () { it('on unsafe cleanup', function (done) { childProcess(this, 'unsafe.json', function (err, stderr, stdout) { if (err) return done(err); - else if (stderr) assert.fail(stderr); - else { + if (stderr) return done(new Error(stderr)); + try { assertions.assertDoesNotExist(stdout); - const basepath = path.join(__dirname, 'outband', 'fixtures', 'symlinkme'); - assertions.assertExists(basepath); - assertions.assertExists(path.join(basepath, 'file.js'), true); + } catch (err) { + rimraf.sync(stdout); + return done(err); } done(); }); @@ -110,17 +131,17 @@ describe('tmp', function () { it('on non unsafe cleanup', function (done) { childProcess(this, 'non-unsafe.json', function (err, stderr, stdout) { if (err) return done(err); - else if (stderr) assert.fail(stderr); - else { + if (stderr) return done(new Error(stderr)); + try { assertions.assertExists(stdout); assertions.assertExists(path.join(stdout, 'should-be-removed.file'), true); if (process.platform == 'win32') assertions.assertExists(path.join(stdout, 'symlinkme-target'), true); else assertions.assertExists(path.join(stdout, 'symlinkme-target')); - fs.unlinkSync(path.join(stdout, 'should-be-removed.file')); - fs.unlinkSync(path.join(stdout, 'symlinkme-target')); - fs.rmdirSync(stdout); + rimraf.sync(stdout); + } catch (err) { + return done(err); } done(); }); @@ -131,8 +152,13 @@ describe('tmp', function () { it('on issue #62', function (done) { childProcess(this, 'issue62.json', function (err, stderr, stdout) { if (err) return done(err); - else if (stderr) assert.fail(stderr); - else assertions.assertDoesNotExist(stdout); + if (stderr) return done(new Error(stderr)); + try { + assertions.assertDoesNotExist(stdout); + } catch (err) { + rimraf.sync(stdout); + return done(err); + } done(); }); }); diff --git a/test/file-sync-test.js b/test/file-sync-test.js index ae9d29d..18622b2 100644 --- a/test/file-sync-test.js +++ b/test/file-sync-test.js @@ -1,12 +1,13 @@ /* eslint-disable no-octal */ // vim: expandtab:ts=2:sw=2 -const +var assert = require('assert'), fs = require('fs'), inbandStandardTests = require('./inband-standard'), assertions = require('./assertions'), childProcess = require('./child-process').genericChildProcess, + rimraf = require('rimraf'), tmp = require('../lib/tmp'); @@ -49,8 +50,13 @@ describe('tmp', function () { it('on graceful', function (done) { childProcess(this, 'graceful-file-sync.json', function (err, stderr, stdout) { if (err) return done(err); - else if (!stderr) assert.fail('stderr expected'); - else assertions.assertDoesNotExist(stdout); + if (!stderr) return done(new Error('stderr expected')); + try { + assertions.assertDoesNotExist(stdout); + } catch (err) { + rimraf.sync(stdout); + return done(err); + } done(); }); }); @@ -58,10 +64,12 @@ describe('tmp', function () { it('on non graceful', function (done) { childProcess(this, 'non-graceful-file-sync.json', function (err, stderr, stdout) { if (err) return done(err); - else if (!stderr) assert.fail('stderr expected'); - else { + if (!stderr) return done(new Error('stderr expected')); + try { assertions.assertExists(stdout, true); - fs.unlinkSync(stdout); + rimraf.sync(stdout); + } catch (err) { + return done(err); } done(); }); @@ -70,10 +78,12 @@ describe('tmp', function () { it('on keep', function (done) { childProcess(this, 'keep-file-sync.json', function (err, stderr, stdout) { if (err) return done(err); - else if (stderr) assert.fail(stderr); - else { + if (stderr) return done(new Error(stderr)); + try { assertions.assertExists(stdout, true); - fs.unlinkSync(stdout); + rimraf.sync(stdout); + } catch (err) { + return done(err); } done(); }); @@ -82,8 +92,13 @@ describe('tmp', function () { it('on unlink (keep == false)', function (done) { childProcess(this, 'unlink-file-sync.json', function (err, stderr, stdout) { if (err) return done(err); - else if (stderr) assert.fail(stderr); - else assertions.assertDoesNotExist(stdout); + if (stderr) return done(new Error(stderr)); + try { + assertions.assertDoesNotExist(stdout); + } catch (err) { + rimraf.sync(stdout); + return done(err); + } done(); }); }); @@ -93,8 +108,13 @@ describe('tmp', function () { it('on issue #115', function (done) { childProcess(this, 'issue115-sync.json', function (err, stderr, stdout) { if (err) return done(err); - else if (stderr) assert.fail(stderr); - else assertions.assertDoesNotExist(stdout); + if (stderr) return done(new Error(stderr)); + try { + assertions.assertDoesNotExist(stdout); + } catch (err) { + rimraf.sync(stdout); + return done(err); + } done(); }); }); diff --git a/test/inband-standard.js b/test/inband-standard.js index 10756e2..f56b457 100644 --- a/test/inband-standard.js +++ b/test/inband-standard.js @@ -1,17 +1,18 @@ /* eslint-disable no-octal */ // vim: expandtab:ts=2:sw=2 -const +var assert = require('assert'), fs = require('fs'), path = require('path'), existsSync = fs.existsSync || path.existsSync, assertions = require('./assertions'), + rimraf = require('rimraf'), tmp = require('../lib/tmp'); module.exports = function inbandStandard(isFile, beforeHook) { - const testMode = isFile ? 0600 : 0700; + var testMode = isFile ? 0600 : 0700; describe('without any parameters', inbandStandardTests({ mode: testMode, prefix: 'tmp-' }, null, isFile, beforeHook)); describe('with prefix', inbandStandardTests({ mode: testMode }, { prefix: 'something' }, isFile, beforeHook)); describe('with postfix', inbandStandardTests({ mode: testMode }, { postfix: '.txt' }, isFile, beforeHook)); @@ -72,9 +73,18 @@ function inbandStandardTests(testOpts, opts, isFile, beforeHook) { }.bind(topic)); } - it('should have a working removeCallback', function () { - this.topic.removeCallback(); - assert.ok(!existsSync(this.topic.name)); + it('should have a working removeCallback', function (done) { + const self = this; + this.topic.removeCallback(function (err) { + if (err) return done(err); + try { + assertions.assertDoesNotExist(self.topic.name); + } catch (err) { + rimraf.sync(self.topic.name); + return done(err); + } + done(); + }); }.bind(topic)); }; } diff --git a/test/issue121-test.js b/test/issue121-test.js index e723720..69a24f3 100644 --- a/test/issue121-test.js +++ b/test/issue121-test.js @@ -10,7 +10,7 @@ const describe('tmp', function () { describe('issue121 - clean up on terminating signals', function () { for (var i=0; i < signals.length; i++) { - it(signals[i], issue121Tests(signals[i])); + issue121Tests(signals[i]); } }); }); diff --git a/test/issue129-test.js b/test/issue129-test.js index 959b3cf..13e3e3f 100644 --- a/test/issue129-test.js +++ b/test/issue129-test.js @@ -1,7 +1,7 @@ /* eslint-disable no-octal */ // vim: expandtab:ts=2:sw=2 -const +var assert = require('assert'), assertions = require('./assertions'), childProcess = require('./child-process').childProcess; @@ -9,16 +9,27 @@ const describe('tmp', function () { describe('issue129: safely install listeners', function () { it('when simulating sandboxed behavior', function (done) { - childProcess(this, 'issue129.json', function (err, stderr) { + childProcess(this, 'issue129.json', function (err, stderr, stdout) { if (err) return done(err); - else if (stderr) { - assertions.assertDoesNotStartWith(stderr, 'EEXISTS:LEGACY:EXIT'); - assertions.assertDoesNotStartWith(stderr, 'EEXISTS:LEGACY:UNCAUGHT'); - assertions.assertDoesNotStartWith(stderr, 'EEXISTS:NEWSTYLE'); - assertions.assertDoesNotStartWith(stderr, 'ENOAVAIL:LEGACY:EXIT'); - assertions.assertDoesNotStartWith(stderr, 'EAVAIL:LEGACY:UNCAUGHT'); - assertions.assertDoesNotStartWith(stderr, 'ENOAVAIL:NEWSTYLE'); - assert.equal(stderr, 'EOK', 'existing listeners should have been removed and called'); + if (!stdout && !stderr) return done(new Error('stderr or stdout expected')); + if (stderr) { + try { + assertions.assertDoesNotStartWith(stderr, 'EEXISTS:LEGACY:EXIT'); + assertions.assertDoesNotStartWith(stderr, 'EEXISTS:LEGACY:UNCAUGHT'); + assertions.assertDoesNotStartWith(stderr, 'EEXISTS:NEWSTYLE'); + assertions.assertDoesNotStartWith(stderr, 'ENOAVAIL:LEGACY:EXIT'); + assertions.assertDoesNotStartWith(stderr, 'EAVAIL:LEGACY:UNCAUGHT'); + assertions.assertDoesNotStartWith(stderr, 'ENOAVAIL:NEWSTYLE'); + } catch (err) { + return done(err); + } + } + if (stdout) { + try { + assert.equal(stdout, 'EOK', 'existing listeners should have been removed and called'); + } catch (err) { + return done(err); + } } done(); diff --git a/test/name-sync-test.js b/test/name-sync-test.js index 7aa312b..e784668 100644 --- a/test/name-sync-test.js +++ b/test/name-sync-test.js @@ -1,7 +1,7 @@ /* eslint-disable no-octal */ // vim: expandtab:ts=2:sw=2 -const +var assert = require('assert'), inbandStandardTests = require('./name-inband-standard'), tmp = require('../lib/tmp'); diff --git a/test/name-test.js b/test/name-test.js index 9616236..564ad32 100644 --- a/test/name-test.js +++ b/test/name-test.js @@ -1,7 +1,7 @@ /* eslint-disable no-octal */ // vim: expandtab:ts=2:sw=2 -const +var assert = require('assert'), inbandStandardTests = require('./name-inband-standard'), tmp = require('../lib/tmp'); @@ -11,27 +11,33 @@ describe('tmp', function () { describe('#tmpName()', function () { describe('when running inband standard tests', function () { inbandStandardTests(function before(done) { - const that = this; + var that = this; tmp.dir(this.opts, function (err, name) { - if (err) done(err); - else { - that.topic = name; - done(); - } + if (err) return done(err); + that.topic = name; + done(); }); }); describe('with invalid tries', function () { it('should result in an error on negative tries', function (done) { tmp.tmpName({ tries: -1 }, function (err) { - assert.ok(err instanceof Error, 'should have failed'); + try { + assert.ok(err instanceof Error, 'should have failed'); + } catch (err) { + return done(err); + } done(); }); }); it('should result in an error on non numeric tries', function (done) { tmp.tmpName({ tries: 'nan' }, function (err) { - assert.ok(err instanceof Error, 'should have failed'); + try { + assert.ok(err instanceof Error, 'should have failed'); + } catch (err) { + return done(err); + } done(); }); }); diff --git a/test/outband/issue115.js b/test/outband/issue115.js index 427f6ad..dc44ccc 100644 --- a/test/outband/issue115.js +++ b/test/outband/issue115.js @@ -3,8 +3,10 @@ var fs = require('fs'); module.exports = function (result) { // creates a tmp file and then closes the file descriptor as per issue 115 // https://github.com/raszi/node-tmp/issues/115 + const self = this; fs.closeSync(result.fd); - result.removeCallback(); - this.out(result.name, this.exit); + result.removeCallback(function () { + self.out(result.name, self.exit); + }); }; diff --git a/test/spawn-custom.js b/test/spawn-custom.js index cc0a1d2..bb1cc27 100644 --- a/test/spawn-custom.js +++ b/test/spawn-custom.js @@ -1,16 +1,14 @@ // vim: expandtab:ts=2:sw=2 -const +var path = require('path'), readJsonConfig = require('./util').readJsonConfig, - spawn = require('./spawn'), - config = readJsonConfig(process.argv[2]); + spawn = require('./spawn'); +var config = readJsonConfig(process.argv[2]); spawn.graceful = !!config.graceful; -const args = Array.prototype.slice.call(process.argv, 3); - // import the test case function and execute it -const fn = require(path.join(__dirname, 'outband', config.tc)); -fn.apply(spawn, args); +var fn = require(path.join(__dirname, 'outband', config.tc)); +fn.apply(spawn); diff --git a/test/spawn-generic.js b/test/spawn-generic.js index 85001fe..6b4cb5b 100644 --- a/test/spawn-generic.js +++ b/test/spawn-generic.js @@ -1,12 +1,12 @@ // vim: expandtab:ts=2:sw=2 -const +var path = require('path'), readJsonConfig = require('./util').readJsonConfig, spawn = require('./spawn'), - tmp = require('../lib/tmp'), - config = readJsonConfig(process.argv[2]); + tmp = require('../lib/tmp'); +var config = readJsonConfig(process.argv[2]); spawn.graceful = !!config.graceful; var fnUnderTest = null; @@ -18,7 +18,7 @@ else fnUnderTest = (config.file) ? tmp.fileSync : tmp.dirSync; if (config.graceful) tmp.setGracefulCleanup(); // import the test case function and execute it -const fn = require(path.join(__dirname, 'outband', config.tc)); +var fn = require(path.join(__dirname, 'outband', config.tc)); if (config.async) fnUnderTest(config.options, function (err, name, fdOrCallback, cb) { if (err) spawn.err(err); diff --git a/test/util.js b/test/util.js index 4369bcb..478148c 100644 --- a/test/util.js +++ b/test/util.js @@ -1,9 +1,9 @@ // vim: expandtab:ts=2:sw=2 -const +var fs = require('fs'); module.exports.readJsonConfig = function readJsonConfig(path) { - const contents = fs.readFileSync(path); + var contents = fs.readFileSync(path); return JSON.parse(contents); };