Skip to content

Commit

Permalink
merge rebase to master
Browse files Browse the repository at this point in the history
  • Loading branch information
silkentrance committed Jul 14, 2018
1 parent 4429b20 commit 0d0f3a7
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 72 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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"
}
}
6 changes: 3 additions & 3 deletions test/assertions.js
@@ -1,6 +1,6 @@
/* eslint-disable no-octal */

const
var
assert = require('assert'),
fs = require('fs'),
path = require('path'),
Expand All @@ -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
Expand Down Expand Up @@ -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');
};
Expand Down
83 changes: 41 additions & 42 deletions 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() {
Expand All @@ -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;
}, []));
}

7 changes: 4 additions & 3 deletions 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'),
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions 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'),
Expand All @@ -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 };
Expand Down
2 changes: 1 addition & 1 deletion 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'),
Expand Down
4 changes: 2 additions & 2 deletions 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'),
Expand All @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion test/issue121-test.js
Expand Up @@ -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]);
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion 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;
Expand Down
2 changes: 1 addition & 1 deletion 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');
Expand Down
4 changes: 2 additions & 2 deletions 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');
Expand All @@ -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;
Expand Down
12 changes: 5 additions & 7 deletions 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);

8 changes: 4 additions & 4 deletions 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;
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions 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);
};

0 comments on commit 0d0f3a7

Please sign in to comment.