Skip to content

Commit

Permalink
[Fix] Spawn processes during tests using execPath so that the tests p…
Browse files Browse the repository at this point in the history
…ass 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.
  • Loading branch information
Joris-van-der-Wel committed Jan 9, 2024
1 parent 5c26250 commit ce05ec6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions test/ignore-pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var tapeBin = path.join(process.cwd(), 'bin/tape');

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

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

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

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

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

proc.on('exit', function (code) {
tt.equals(code, 1);
Expand Down
12 changes: 6 additions & 6 deletions test/ignore_from_gitignore.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var stripFullStack = require('./common').stripFullStack;

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

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

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

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

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

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

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

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

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

var ps = spawn(tapeBin, ['**/*.js', '-i'], { cwd: path.join(__dirname, 'ignore') });
var ps = spawn(process.execPath, [tapeBin, '**/*.js', '-i'], { cwd: path.join(__dirname, 'ignore') });
ps.stdout.pipe(concat(testStdout));
ps.stderr.pipe(concat(testStderr));
ps.on('exit', function (code) {
Expand Down
2 changes: 1 addition & 1 deletion test/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var assign = require('object.assign');
function tape(args, options) {
var bin = __dirname + '/../bin/tape';

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

tap.test('importing mjs files', function (t) {
Expand Down
2 changes: 1 addition & 1 deletion test/require.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var stripFullStack = require('./common').stripFullStack;
function tape(args) {
var bin = __dirname + '/../bin/tape';

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

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

0 comments on commit ce05ec6

Please sign in to comment.