Skip to content

Commit

Permalink
fixup: switch from spawn to exec
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jan 25, 2022
1 parent 567b106 commit 709aa1c
Showing 1 changed file with 35 additions and 49 deletions.
84 changes: 35 additions & 49 deletions test/no_only.js
Expand Up @@ -2,8 +2,7 @@

var tap = require('tap');
var path = require('path');
var spawn = require('child_process').spawn;
var concat = require('concat-stream');
var exec = require('child_process').exec;

var stripFullStack = require('./common').stripFullStack;

Expand All @@ -15,16 +14,14 @@ tap.test(
'Should throw error when --no-only is passed via cli and there is a .only test',
{ todo: expectedFailure ? 'Fails on these node versions' : false },
function (tt) {
tt.plan(2);

var testStderr = function (rows) {
tt.ok((/Error: `only` tests are prohibited\n/).test(stripFullStack(rows.toString('utf8')).join('\n')));
};

var ps = spawn(tapeBin, ['--no-only', '**/*.js'], { cwd: path.join(__dirname, 'no_only') });
ps.stderr.pipe(concat(testStderr));
ps.on('exit', function (code) {
tt.equal(code, 1);
tt.plan(3);

exec(tapeBin + ' --no-only "**/*.js"', {
cwd: path.join(__dirname, 'no_only')
}, function (err, stdout, stderr) {
tt.same(stdout.toString('utf8'), '');
tt.ok((/Error: `only` tests are prohibited\n/).test(stripFullStack(stderr.toString('utf8')).join('\n')));
tt.equal(err.code, 1);
});
}
);
Expand All @@ -33,18 +30,15 @@ tap.test(
'Should throw error when NODE_TAPE_NO_ONLY_TEST is passed via envs and there is an .only test',
{ todo: expectedFailure ? 'Fails on these node versions' : false },
function (tt) {
tt.plan(2);
tt.plan(3);

var testStderr = function (rows) {
tt.ok((/Error: `only` tests are prohibited\n/).test(stripFullStack(rows.toString('utf8')).join('\n')));
};
var ps = spawn(tapeBin, ['**/*.js'], {
exec(tapeBin + ' "**/*.js"', {
cwd: path.join(__dirname, 'no_only'),
env: { PATH: process.env.PATH, NODE_TAPE_NO_ONLY_TEST: 'true' }
});
ps.stderr.pipe(concat(testStderr));
ps.on('exit', function (code) {
tt.equal(code, 1);
}, function (err, stdout, stderr) {
tt.same(stdout.toString('utf8'), '');
tt.ok((/Error: `only` tests are prohibited\n/).test(stripFullStack(stderr.toString('utf8')).join('\n')));
tt.equal(err.code, 1);
});
}
);
Expand All @@ -53,28 +47,27 @@ tap.test(
'Should override NODE_TAPE_NO_ONLY_TEST env if --no-only is passed from cli',
{ todo: expectedFailure ? 'Fails on these node versions' : false },
function (tt) {
tt.plan(2);

var testStderr = function (rows) {
tt.ok((/Error: `only` tests are prohibited\n/).test(stripFullStack(rows.toString('utf8')).join('\n')));
};
tt.plan(3);

var ps = spawn(tapeBin, ['--no-only', '**/*.js'], {
exec(tapeBin + ' --no-only "**/*.js"', {
cwd: path.join(__dirname, 'no_only'),
env: { PATH: process.env.PATH, NODE_TAPE_NO_ONLY_TEST: 'false' }
});
ps.stderr.pipe(concat(testStderr));
ps.on('exit', function (code) {
tt.equal(code, 1);
}, function (err, stdout, stderr) {
tt.same(stdout.toString('utf8'), '');
tt.ok((/Error: `only` tests are prohibited\n/).test(stripFullStack(stderr.toString('utf8')).join('\n')));
tt.equal(err.code, 1);
});
}
);

tap.test('Should run successfully if there is no only test', function (tt) {
tt.plan(2);
tt.plan(3);

var testStdout = function (rows) {
tt.same(stripFullStack(rows.toString('utf8')), [
exec(tapeBin + ' --no-only "**/test-a.js"', {
cwd: path.join(__dirname, 'no_only')
}, function (err, stdout, stderr) {
tt.same(stderr.toString('utf8'), '');
tt.same(stripFullStack(stdout.toString('utf8')), [
'TAP version 13',
'# should pass',
'ok 1 should be truthy',
Expand All @@ -87,20 +80,17 @@ tap.test('Should run successfully if there is no only test', function (tt) {
'',
''
]);
};

var ps = spawn(tapeBin, ['**/test-a.js', '--no-only'], { cwd: path.join(__dirname, 'no_only') });
ps.stdout.pipe(concat(testStdout));
ps.on('exit', function (code) {
tt.equal(code, 0);
tt.equal(err, null); // code 0
});
});

tap.test('Should run successfully if there is an only test and no --no-only flag', function (tt) {
tt.plan(2);
tt.plan(3);

var testStdout = function (rows) {
tt.same(stripFullStack(rows.toString('utf8')), [
exec(tapeBin + ' "**/test-b.js"', {
cwd: path.join(__dirname, 'no_only')
}, function (err, stdout, stderr) {
tt.same(stripFullStack(stdout.toString('utf8')), [
'TAP version 13',
'# should pass again',
'ok 1 should be truthy',
Expand All @@ -113,11 +103,7 @@ tap.test('Should run successfully if there is an only test and no --no-only flag
'',
''
]);
};

var ps = spawn(tapeBin, ['**/test-b.js'], { cwd: path.join(__dirname, 'no_only') });
ps.stdout.pipe(concat(testStdout));
ps.on('exit', function (code) {
tt.equal(code, 0);
tt.same(String(stderr), '');
tt.equal(err, null); // code 0
});
});

0 comments on commit 709aa1c

Please sign in to comment.