Skip to content

Commit

Permalink
test: use more informative errors in test-runner-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Oct 8, 2024
1 parent accb239 commit edcd417
Showing 1 changed file with 39 additions and 33 deletions.
72 changes: 39 additions & 33 deletions test/parallel/test-runner-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ for (const isolation of ['none', 'process']) {
`--experimental-${type}-types`, `--experimental-test-isolation=${isolation}`];
const child = spawnSync(process.execPath, args, { cwd: join(testFixtures, 'matching-patterns') });

assert.strictEqual(child.status, 0);
assert.strictEqual(child.signal, null);
assert.strictEqual(child.stderr.toString(), '');
const stdout = child.stdout.toString();

Expand All @@ -78,6 +76,8 @@ for (const isolation of ['none', 'process']) {
assert.match(stdout, /ok 4 - this should pass/);
assert.match(stdout, /ok 5 - this should pass/);
assert.match(stdout, /ok 6 - this should pass/);
assert.strictEqual(child.status, 0);
assert.strictEqual(child.signal, null);
}

{
Expand All @@ -97,9 +97,9 @@ for (const isolation of ['none', 'process']) {
assert.match(stdout, /ok 4 - this should pass/);
assert.match(stdout, /ok 5 - this should be skipped/);
assert.match(stdout, /ok 6 - this should be executed/);
assert.strictEqual(child.stderr.toString(), '');
assert.strictEqual(child.status, 1);
assert.strictEqual(child.signal, null);
assert.strictEqual(child.stderr.toString(), '');
}

{
Expand All @@ -112,11 +112,11 @@ for (const isolation of ['none', 'process']) {
];
const child = spawnSync(process.execPath, args, { cwd: testFixtures });

assert.strictEqual(child.status, 1);
assert.strictEqual(child.signal, null);
assert.strictEqual(child.stderr.toString(), '');
const stdout = child.stdout.toString();
assert.match(stdout, /not ok 1 - .+index\.js/);
assert.strictEqual(child.status, 1);
assert.strictEqual(child.signal, null);
}

{
Expand All @@ -129,11 +129,11 @@ for (const isolation of ['none', 'process']) {
];
const child = spawnSync(process.execPath, args);

assert.strictEqual(child.status, 1);
assert.strictEqual(child.signal, null);
assert.strictEqual(child.stderr.toString(), '');
const stdout = child.stdout.toString();
assert.match(stdout, /not ok 1 - .+test-nm\.js/);
assert.strictEqual(child.status, 1);
assert.strictEqual(child.signal, null);
}

{
Expand All @@ -142,8 +142,6 @@ for (const isolation of ['none', 'process']) {
const options = { cwd: join(testFixtures, 'default-behavior') };
const child = spawnSync(process.execPath, args, options);

assert.strictEqual(child.status, 1);
assert.strictEqual(child.signal, null);
assert.strictEqual(child.stderr.toString(), '');
const stdout = child.stdout.toString();
assert.match(stdout, /this should pass/);
Expand All @@ -152,6 +150,9 @@ for (const isolation of ['none', 'process']) {
assert.match(stdout, /this should pass/);
assert.match(stdout, /this should be skipped/);
assert.match(stdout, /this should be executed/);

assert.strictEqual(child.status, 1);
assert.strictEqual(child.signal, null);
}

{
Expand All @@ -166,8 +167,6 @@ for (const isolation of ['none', 'process']) {
];
const child = spawnSync(process.execPath, args);

assert.strictEqual(child.status, 1);
assert.strictEqual(child.signal, null);
assert.strictEqual(child.stderr.toString(), '');
const stdout = child.stdout.toString();
assert.match(stdout, /# Subtest: this should pass/);
Expand Down Expand Up @@ -204,6 +203,9 @@ for (const isolation of ['none', 'process']) {
assert.match(stdout, /# cancelled 0/);
assert.match(stdout, /# skipped 1/);
assert.match(stdout, /# todo 0/);

assert.strictEqual(child.status, 1);
assert.strictEqual(child.signal, null);
}
}

Expand All @@ -219,11 +221,11 @@ for (const isolation of ['none', 'process']) {
for (const args of flags) {
const child = spawnSync(process.execPath, args);

assert.notStrictEqual(child.status, 0);
assert.strictEqual(child.signal, null);
assert.strictEqual(child.stdout.toString(), '');
const stderr = child.stderr.toString();
assert.match(stderr, /--test/);
assert.notStrictEqual(child.status, 0);
assert.strictEqual(child.signal, null);
}
}

Expand All @@ -236,8 +238,6 @@ for (const isolation of ['none', 'process']) {
];
const child = spawnSync(process.execPath, args);

assert.strictEqual(child.status, 0);
assert.strictEqual(child.signal, null);
assert.strictEqual(child.stderr.toString(), '');
const stdout = child.stdout.toString();
assert.match(stdout, /# stderr 1/);
Expand All @@ -251,6 +251,9 @@ for (const isolation of ['none', 'process']) {
assert.match(stdout, /ok 1 - a test/);
assert.match(stdout, /# tests 1/);
assert.match(stdout, /# pass 1/);

assert.strictEqual(child.status, 0);
assert.strictEqual(child.signal, null);
}

{
Expand All @@ -263,70 +266,70 @@ for (const isolation of ['none', 'process']) {
const child = spawnSync(process.execPath, args);

assert.strictEqual(child.stderr.toString(), '');
assert.strictEqual(child.status, 0);
assert.strictEqual(child.signal, null);
const stdout = child.stdout.toString();
assert.match(stdout, /this should pass/);
assert.strictEqual(child.status, 0);
assert.strictEqual(child.signal, null);
}

{
// --test-shard option validation
const args = ['--test', '--test-shard=1', join(testFixtures, 'index.js')];
const child = spawnSync(process.execPath, args, { cwd: testFixtures });

assert.strictEqual(child.status, 1);
assert.strictEqual(child.signal, null);
assert.match(child.stderr.toString(), /The argument '--test-shard' must be in the form of <index>\/<total>\. Received '1'/);
const stdout = child.stdout.toString();
assert.strictEqual(stdout, '');
assert.strictEqual(child.status, 1);
assert.strictEqual(child.signal, null);
}

{
// --test-shard option validation
const args = ['--test', '--test-shard=1/2/3', join(testFixtures, 'index.js')];
const child = spawnSync(process.execPath, args, { cwd: testFixtures });

assert.strictEqual(child.status, 1);
assert.strictEqual(child.signal, null);
assert.match(child.stderr.toString(), /The argument '--test-shard' must be in the form of <index>\/<total>\. Received '1\/2\/3'/);
const stdout = child.stdout.toString();
assert.strictEqual(stdout, '');
assert.strictEqual(child.status, 1);
assert.strictEqual(child.signal, null);
}

{
// --test-shard option validation
const args = ['--test', '--test-shard=0/3', join(testFixtures, 'index.js')];
const child = spawnSync(process.execPath, args, { cwd: testFixtures });

assert.strictEqual(child.status, 1);
assert.strictEqual(child.signal, null);
assert.match(child.stderr.toString(), /The value of "options\.shard\.index" is out of range\. It must be >= 1 && <= 3\. Received 0/);
const stdout = child.stdout.toString();
assert.strictEqual(stdout, '');
assert.strictEqual(child.status, 1);
assert.strictEqual(child.signal, null);
}

{
// --test-shard option validation
const args = ['--test', '--test-shard=0xf/20abcd', join(testFixtures, 'index.js')];
const child = spawnSync(process.execPath, args, { cwd: testFixtures });

assert.strictEqual(child.status, 1);
assert.strictEqual(child.signal, null);
assert.match(child.stderr.toString(), /The argument '--test-shard' must be in the form of <index>\/<total>\. Received '0xf\/20abcd'/);
const stdout = child.stdout.toString();
assert.strictEqual(stdout, '');
assert.strictEqual(child.status, 1);
assert.strictEqual(child.signal, null);
}

{
// --test-shard option validation
const args = ['--test', '--test-shard=hello', join(testFixtures, 'index.js')];
const child = spawnSync(process.execPath, args, { cwd: testFixtures });

assert.strictEqual(child.status, 1);
assert.strictEqual(child.signal, null);
assert.match(child.stderr.toString(), /The argument '--test-shard' must be in the form of <index>\/<total>\. Received 'hello'/);
const stdout = child.stdout.toString();
assert.strictEqual(stdout, '');
assert.strictEqual(child.status, 1);
assert.strictEqual(child.signal, null);
}

{
Expand All @@ -339,8 +342,6 @@ for (const isolation of ['none', 'process']) {
];
const child = spawnSync(process.execPath, args);

assert.strictEqual(child.status, 0);
assert.strictEqual(child.signal, null);
assert.strictEqual(child.stderr.toString(), '');
const stdout = child.stdout.toString();
assert.match(stdout, /# Subtest: a\.cjs this should pass/);
Expand All @@ -362,6 +363,9 @@ for (const isolation of ['none', 'process']) {
assert.match(stdout, /# pass 5/);
assert.match(stdout, /# fail 0/);
assert.match(stdout, /# skipped 0/);

assert.strictEqual(child.status, 0);
assert.strictEqual(child.signal, null);
}

{
Expand All @@ -374,8 +378,6 @@ for (const isolation of ['none', 'process']) {
];
const child = spawnSync(process.execPath, args);

assert.strictEqual(child.status, 0);
assert.strictEqual(child.signal, null);
assert.strictEqual(child.stderr.toString(), '');
const stdout = child.stdout.toString();
assert.match(stdout, /# Subtest: b\.cjs this should pass/);
Expand All @@ -397,15 +399,16 @@ for (const isolation of ['none', 'process']) {
assert.match(stdout, /# pass 5/);
assert.match(stdout, /# fail 0/);
assert.match(stdout, /# skipped 0/);

assert.strictEqual(child.status, 0);
assert.strictEqual(child.signal, null);
}

{
// Should not match files like latest.js
const args = ['--test', '--test-reporter=tap'];
const child = spawnSync(process.execPath, args, { cwd: join(testFixtures, 'issue-54726') });

assert.strictEqual(child.status, 0);
assert.strictEqual(child.signal, null);
assert.strictEqual(child.stderr.toString(), '');
const stdout = child.stdout.toString();

Expand All @@ -416,4 +419,7 @@ for (const isolation of ['none', 'process']) {
assert.match(stdout, /cancelled 0/);
assert.match(stdout, /skipped 0/);
assert.match(stdout, /todo 0/);

assert.strictEqual(child.status, 0);
assert.strictEqual(child.signal, null);
}

0 comments on commit edcd417

Please sign in to comment.