Skip to content

Commit 0d0f3a7

Browse files
committed
merge rebase to master
1 parent 4429b20 commit 0d0f3a7

14 files changed

+70
-72
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"scripts": {
3939
"lint": "eslint lib --env mocha test",
4040
"clean": "rm -Rf ./coverage",
41-
"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",
41+
"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",
4242
"doc": "jsdoc -c .jsdoc.json"
4343
}
4444
}

test/assertions.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable no-octal */
22

3-
const
3+
var
44
assert = require('assert'),
55
fs = require('fs'),
66
path = require('path'),
@@ -18,7 +18,7 @@ module.exports.assertName = function assertName(name, expected) {
1818

1919

2020
module.exports.assertMode = function assertMode(name, mode) {
21-
const stat = fs.statSync(name);
21+
var stat = fs.statSync(name);
2222

2323
// mode values do not work properly on Windows. Ignore “group” and
2424
// “other” bits then. Ignore execute bit on that platform because it
@@ -57,7 +57,7 @@ module.exports.assertProperResult = function assertProperResult(result, withfd)
5757

5858
module.exports.assertExists = function assertExists(name, isfile) {
5959
assert.ok(existsSync(name), name + ' should exist');
60-
const stat = fs.statSync(name);
60+
var stat = fs.statSync(name);
6161
if (isfile) assert.ok(stat.isFile(), name + ' should be a file');
6262
else assert.ok(stat.isDirectory(), name + ' should be a directory');
6363
};

test/child-process.js

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,80 @@
11
// vim: expandtab:ts=2:sw=2
22

3-
const
3+
var
44
fs = require('fs'),
55
path = require('path'),
6-
existsSync = fs.existsSync || path.existsSync,
6+
exists = fs.exists || path.exists,
77
spawn = require('child_process').spawn;
88

9+
const ISTANBUL_PATH = path.join(__dirname, '..', 'node_modules', 'istanbul', 'lib', 'cli.js');
910

10-
module.exports.genericChildProcess = function spawnGenericChildProcess(configFile, cb) {
11-
const
12-
configFilePath = path.join(__dirname, 'outband', configFile),
13-
command_args = [path.join(__dirname, 'spawn-generic.js'), configFilePath];
11+
module.exports.genericChildProcess = _spawnProcess('spawn-generic.js');
12+
module.exports.childProcess = _spawnProcess('spawn-custom.js');
1413

15-
// make sure that the config file exists
16-
if (!existsSync(configFilePath))
17-
return cb(new Error('ENOENT: configFile ' + configFilePath + ' does not exist'));
14+
function _spawnProcess(spawnFile) {
15+
return function (testCase, configFile, cb) {
16+
var
17+
configFilePath = path.join(__dirname, 'outband', configFile),
18+
commandArgs = [path.join(__dirname, spawnFile), configFilePath];
1819

19-
_do_spawn(command_args, cb);
20-
};
20+
exists(configFilePath, function (configExists) {
21+
if (configExists) return _doSpawn(commandArgs, cb);
2122

22-
module.exports.childProcess = function spawnChildProcess(configFile, cb, detach) {
23-
var
24-
configFilePath = path.join(__dirname, 'outband', configFile),
25-
command_args = [path.join(__dirname, 'spawn-custom.js'), configFilePath];
26-
27-
// make sure that the config file exists
28-
if (!existsSync(configFilePath))
29-
return cb(new Error('ENOENT: configFile ' + configFilePath + ' does not exist'));
30-
31-
if (arguments.length > 2) {
32-
for (var i=2; i < arguments.length; i++) {
33-
command_args.push(arguments[i]);
34-
}
35-
}
36-
37-
_do_spawn(command_args, cb, detach);
23+
cb(new Error('ENOENT: configFile ' + configFilePath + ' does not exist'));
24+
});
25+
};
3826
}
3927

40-
function _do_spawn(command_args, cb, detach) {
41-
const
28+
function _doSpawn(commandArgs, cb) {
29+
var
4230
node_path = process.argv[0],
4331
stdoutBufs = [],
44-
stderrBufs = [];
45-
46-
var
32+
stderrBufs = [],
4733
child,
4834
done = false,
4935
stderrDone = false,
5036
stdoutDone = false;
5137

38+
if (process.env.running_under_istanbul) {
39+
commandArgs = [
40+
ISTANBUL_PATH, 'cover', '--report' , 'none', '--print', 'none',
41+
'--dir', path.join('coverage', 'json'), '--include-pid',
42+
commandArgs[0], '--', commandArgs[1]
43+
];
44+
}
45+
5246
// spawn doesn’t have the quoting problems that exec does,
5347
// especially when going for Windows portability.
54-
child = spawn(node_path, command_args, detach ? { detached: true } : undefined);
48+
child = spawn(node_path, commandArgs);
5549
child.stdin.end();
56-
// TODO:we no longer support node <0.10.0
50+
51+
// TODO we no longer support node 0.6
5752
// Cannot use 'close' event because not on node-0.6.
5853
function _close() {
59-
const
54+
var
6055
stderr = _bufferConcat(stderrBufs).toString(),
6156
stdout = _bufferConcat(stdoutBufs).toString();
57+
6258
if (stderrDone && stdoutDone && !done) {
6359
done = true;
6460
cb(null, stderr, stdout);
6561
}
6662
}
63+
6764
child.on('error', function _spawnError(err) {
6865
if (!done) {
6966
done = true;
7067
cb(err);
7168
}
7269
});
70+
7371
child.stdout.on('data', function _stdoutData(data) {
7472
stdoutBufs.push(data);
7573
}).on('close', function _stdoutEnd() {
7674
stdoutDone = true;
7775
_close();
7876
});
77+
7978
child.stderr.on('data', function _stderrData(data) {
8079
stderrBufs.push(data);
8180
}).on('close', function _stderrEnd() {
@@ -87,13 +86,13 @@ function _do_spawn(command_args, cb, detach) {
8786
function _bufferConcat(buffers) {
8887
if (Buffer.concat) {
8988
return Buffer.concat.apply(this, arguments);
90-
} else {
91-
return new Buffer(buffers.reduce(function (acc, buf) {
92-
for (var i = 0; i < buf.length; i++) {
93-
acc.push(buf[i]);
94-
}
95-
return acc;
96-
}, []));
9789
}
90+
91+
return new Buffer(buffers.reduce(function (acc, buf) {
92+
for (var i = 0; i < buf.length; i++) {
93+
acc.push(buf[i]);
94+
}
95+
return acc;
96+
}, []));
9897
}
9998

test/dir-sync-test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-octal */
22
// vim: expandtab:ts=2:sw=2
33

4-
const
4+
var
55
assert = require('assert'),
66
fs = require('fs'),
77
path = require('path'),
@@ -125,10 +125,11 @@ describe('tmp', function () {
125125
try {
126126
assertions.assertExists(stdout);
127127
assertions.assertExists(path.join(stdout, 'should-be-removed.file'), true);
128-
if (process.platform == 'win32')
128+
if (process.platform == 'win32') {
129129
assertions.assertExists(path.join(stdout, 'symlinkme-target'), true);
130-
else
130+
} else {
131131
assertions.assertExists(path.join(stdout, 'symlinkme-target'));
132+
}
132133
} catch (err) {
133134
rimraf.sync(stdout);
134135
return done(err);

test/dir-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-octal */
22
// vim: expandtab:ts=2:sw=2
33

4-
const
4+
var
55
assert = require('assert'),
66
fs = require('fs'),
77
path = require('path'),
@@ -20,7 +20,7 @@ describe('tmp', function () {
2020
describe('#dir()', function () {
2121
describe('when running inband standard tests', function () {
2222
inbandStandardTests(false, function before(done) {
23-
const that = this;
23+
var that = this;
2424
tmp.dir(this.opts, function (err, name, removeCallback) {
2525
if (err) return done(err);
2626
that.topic = { name: name, removeCallback: removeCallback };

test/file-sync-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-octal */
22
// vim: expandtab:ts=2:sw=2
33

4-
const
4+
var
55
assert = require('assert'),
66
fs = require('fs'),
77
inbandStandardTests = require('./inband-standard'),

test/inband-standard.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-octal */
22
// vim: expandtab:ts=2:sw=2
33

4-
const
4+
var
55
assert = require('assert'),
66
fs = require('fs'),
77
path = require('path'),
@@ -12,7 +12,7 @@ const
1212

1313

1414
module.exports = function inbandStandard(isFile, beforeHook) {
15-
const testMode = isFile ? 0600 : 0700;
15+
var testMode = isFile ? 0600 : 0700;
1616
describe('without any parameters', inbandStandardTests({ mode: testMode, prefix: 'tmp-' }, null, isFile, beforeHook));
1717
describe('with prefix', inbandStandardTests({ mode: testMode }, { prefix: 'something' }, isFile, beforeHook));
1818
describe('with postfix', inbandStandardTests({ mode: testMode }, { postfix: '.txt' }, isFile, beforeHook));

test/issue121-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const
1010
describe('tmp', function () {
1111
describe('issue121 - clean up on terminating signals', function () {
1212
for (var i=0; i < signals.length; i++) {
13-
it(signals[i], issue121Tests(signals[i]));
13+
issue121Tests(signals[i]);
1414
}
1515
});
1616
});

test/issue129-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-octal */
22
// vim: expandtab:ts=2:sw=2
33

4-
const
4+
var
55
assert = require('assert'),
66
assertions = require('./assertions'),
77
childProcess = require('./child-process').childProcess;

test/name-sync-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-octal */
22
// vim: expandtab:ts=2:sw=2
33

4-
const
4+
var
55
assert = require('assert'),
66
inbandStandardTests = require('./name-inband-standard'),
77
tmp = require('../lib/tmp');

0 commit comments

Comments
 (0)