From 0c5bc5ccad8696f949090886ec9d3b0c4bbbdd9a Mon Sep 17 00:00:00 2001 From: Carsten Klein Date: Wed, 27 Dec 2017 02:29:02 +0100 Subject: [PATCH] merge rebase to master --- package.json | 2 +- test/assertions.js | 6 +-- test/child-process.js | 83 ++++++++++++++++++++--------------------- test/dir-sync-test.js | 7 ++-- test/dir-test.js | 4 +- test/file-sync-test.js | 2 +- test/inband-standard.js | 4 +- test/issue121-test.js | 2 +- test/issue129-test.js | 2 +- test/name-sync-test.js | 2 +- test/name-test.js | 4 +- test/spawn-custom.js | 12 +++--- test/spawn-generic.js | 8 ++-- test/util.js | 4 +- 14 files changed, 70 insertions(+), 72 deletions(-) diff --git a/package.json b/package.json index fd60e8c..0c178bc 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 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 4eda836..7afe4cc 100644 --- a/test/dir-sync-test.js +++ b/test/dir-sync-test.js @@ -1,7 +1,7 @@ /* eslint-disable no-octal */ // vim: expandtab:ts=2:sw=2 -const +var assert = require('assert'), fs = require('fs'), path = require('path'), @@ -125,10 +125,11 @@ describe('tmp', function () { try { assertions.assertExists(stdout); assertions.assertExists(path.join(stdout, 'should-be-removed.file'), true); - if (process.platform == 'win32') + if (process.platform == 'win32') { assertions.assertExists(path.join(stdout, 'symlinkme-target'), true); - else + } else { assertions.assertExists(path.join(stdout, 'symlinkme-target')); + } } catch (err) { rimraf.sync(stdout); return done(err); diff --git a/test/dir-test.js b/test/dir-test.js index cf1599b..406175a 100644 --- a/test/dir-test.js +++ b/test/dir-test.js @@ -1,7 +1,7 @@ /* eslint-disable no-octal */ // vim: expandtab:ts=2:sw=2 -const +var assert = require('assert'), fs = require('fs'), path = require('path'), @@ -20,7 +20,7 @@ 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) return done(err); that.topic = { name: name, removeCallback: removeCallback }; diff --git a/test/file-sync-test.js b/test/file-sync-test.js index 21d0781..52689c5 100644 --- a/test/file-sync-test.js +++ b/test/file-sync-test.js @@ -1,7 +1,7 @@ /* eslint-disable no-octal */ // vim: expandtab:ts=2:sw=2 -const +var assert = require('assert'), fs = require('fs'), inbandStandardTests = require('./inband-standard'), diff --git a/test/inband-standard.js b/test/inband-standard.js index 7c5c0e8..f56b457 100644 --- a/test/inband-standard.js +++ b/test/inband-standard.js @@ -1,7 +1,7 @@ /* eslint-disable no-octal */ // vim: expandtab:ts=2:sw=2 -const +var assert = require('assert'), fs = require('fs'), path = require('path'), @@ -12,7 +12,7 @@ const 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)); 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 253c326..c157cb3 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; 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 4eaf5c4..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,7 +11,7 @@ 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) return done(err); that.topic = name; 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); };