Skip to content

Commit 4a57fbe

Browse files
Joris-van-der-Welljharb
authored andcommitted
[Tests] Spawn processes during tests using execPath so that the tests pass on windows
In some parts of the code the `bin/tape` script was executed directly. This does not always work on windows, causing those tests to fail. So instead `process.execPath` is executed (which is the path to the node binary), and the script is passed as an argument. In other parts of the code, argv[0] was used. This has been made consistent so that execPath is used everywhere.
1 parent a2b74f9 commit 4a57fbe

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

test/ignore-pattern.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var tapeBin = path.join(process.cwd(), 'bin/tape');
88

99
tap.test('should allow ignore file together with --ignore-pattern', function (tt) {
1010
tt.plan(1);
11-
var proc = execFile(tapeBin, ['--ignore', '.ignore', '--ignore-pattern', 'fake_other_ignored_dir', '**/*.js'], { cwd: path.join(__dirname, 'ignore-pattern') });
11+
var proc = execFile(process.execPath, [tapeBin, '--ignore', '.ignore', '--ignore-pattern', 'fake_other_ignored_dir', '**/*.js'], { cwd: path.join(__dirname, 'ignore-pattern') });
1212

1313
proc.on('exit', function (code) {
1414
tt.equals(code, 0);
@@ -17,7 +17,7 @@ tap.test('should allow ignore file together with --ignore-pattern', function (tt
1717

1818
tap.test('should allow --ignore-pattern without ignore file', function (tt) {
1919
tt.plan(1);
20-
var proc = execFile(tapeBin, ['--ignore-pattern', 'fake_*', '**/*.js'], { cwd: path.join(__dirname, 'ignore-pattern') });
20+
var proc = execFile(process.execPath, [tapeBin, '--ignore-pattern', 'fake_*', '**/*.js'], { cwd: path.join(__dirname, 'ignore-pattern') });
2121

2222
proc.on('exit', function (code) {
2323
tt.equals(code, 0);
@@ -26,7 +26,7 @@ tap.test('should allow --ignore-pattern without ignore file', function (tt) {
2626

2727
tap.test('should fail if not ignoring', function (tt) {
2828
tt.plan(1);
29-
var proc = execFile(tapeBin, ['**/*.js'], { cwd: path.join(__dirname, 'ignore-pattern') });
29+
var proc = execFile(process.execPath, [tapeBin, '**/*.js'], { cwd: path.join(__dirname, 'ignore-pattern') });
3030

3131
proc.on('exit', function (code) {
3232
tt.equals(code, 1);

test/ignore_from_gitignore.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var stripFullStack = require('./common').stripFullStack;
99

1010
var tapeBin = path.join(process.cwd(), 'bin/tape');
1111

12-
tap.test('Should pass with ignoring', { skip: process.platform === 'win32' }, function (tt) {
12+
tap.test('Should pass with ignoring', function (tt) {
1313
tt.plan(2);
1414

1515
var tc = function (rows) {
@@ -38,14 +38,14 @@ tap.test('Should pass with ignoring', { skip: process.platform === 'win32' }, fu
3838
]);
3939
};
4040

41-
var ps = spawn(tapeBin, ['**/*.js', '-i', '.ignore'], { cwd: path.join(__dirname, 'ignore') });
41+
var ps = spawn(process.execPath, [tapeBin, '**/*.js', '-i', '.ignore'], { cwd: path.join(__dirname, 'ignore') });
4242
ps.stdout.pipe(concat(tc));
4343
ps.on('exit', function (code) {
4444
tt.equal(code, 0); // code 0
4545
});
4646
});
4747

48-
tap.test('Should pass', { skip: process.platform === 'win32' }, function (tt) {
48+
tap.test('Should pass', function (tt) {
4949
tt.plan(2);
5050

5151
var tc = function (rows) {
@@ -95,14 +95,14 @@ tap.test('Should pass', { skip: process.platform === 'win32' }, function (tt) {
9595
]);
9696
};
9797

98-
var ps = spawn(tapeBin, ['**/*.js'], { cwd: path.join(__dirname, 'ignore') });
98+
var ps = spawn(process.execPath, [tapeBin, '**/*.js'], { cwd: path.join(__dirname, 'ignore') });
9999
ps.stdout.pipe(concat(tc));
100100
ps.on('exit', function (code) {
101101
tt.equal(code, 1);
102102
});
103103
});
104104

105-
tap.test('Should fail when ignore file does not exist', { skip: process.platform === 'win32' }, function (tt) {
105+
tap.test('Should fail when ignore file does not exist', function (tt) {
106106
tt.plan(3);
107107

108108
var testStdout = function (rows) {
@@ -113,7 +113,7 @@ tap.test('Should fail when ignore file does not exist', { skip: process.platform
113113
tt.ok((/^ENOENT[:,] no such file or directory,? (?:open )?'\$TEST\/ignore\/.gitignore'\n$/m).test(stripFullStack(rows.toString('utf8')).join('\n')));
114114
};
115115

116-
var ps = spawn(tapeBin, ['**/*.js', '-i'], { cwd: path.join(__dirname, 'ignore') });
116+
var ps = spawn(process.execPath, [tapeBin, '**/*.js', '-i'], { cwd: path.join(__dirname, 'ignore') });
117117
ps.stdout.pipe(concat(testStdout));
118118
ps.stderr.pipe(concat(testStderr));
119119
ps.on('exit', function (code) {

test/import.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var assign = require('object.assign');
99
function tape(args, options) {
1010
var bin = __dirname + '/../bin/tape';
1111

12-
return spawn(process.argv[0], [bin].concat(args.split(' ')), assign({ cwd: __dirname }, options));
12+
return spawn(process.execPath, [bin].concat(args.split(' ')), assign({ cwd: __dirname }, options));
1313
}
1414

1515
tap.test('importing mjs files', function (t) {

test/require.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var stripFullStack = require('./common').stripFullStack;
88
function tape(args) {
99
var bin = __dirname + '/../bin/tape';
1010

11-
return spawn('node', [bin].concat(args.split(' ')), { cwd: __dirname });
11+
return spawn(process.execPath, [bin].concat(args.split(' ')), { cwd: __dirname });
1212
}
1313

1414
tap.test('requiring a single module', function (t) {

0 commit comments

Comments
 (0)