Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ runner.on('test:stdout', (data: any) => {
});

runner.on('test:fail', (data: any) => {
// node:test semantics: a failing `todo` or `skip` test doesn't fail the run. The marker is `true`
// or the reason string, which can be empty (`{ todo: '' }`).
if (data.todo || data.todo === '' || data.skip || data.skip === '') {
return;
}
process.exitCode = 1;
if (data.file) {
failedFiles.add(resolve(data.file));
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/run/empty-reason-todo-fail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { test } from 'node:test';
import assert from 'node:assert';

test('a todo test with an empty reason that fails', { todo: '' }, () => {
assert.strictEqual(1, 2);
});
6 changes: 6 additions & 0 deletions test/fixtures/run/real-fail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { test } from 'node:test';
import assert from 'node:assert';

test('a real failure', () => {
assert.strictEqual(1, 2);
});
9 changes: 9 additions & 0 deletions test/fixtures/run/skip-fail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { test } from 'node:test';
import assert from 'node:assert';

// `t.skip()` from inside the body, not `{ skip: true }`: the option skips the body entirely, so the
// test never fails and never reaches the runner's `data.skip` branch.
test('a skipped test that fails', (t) => {
t.skip('skipped for testing');
assert.strictEqual(1, 2);
});
6 changes: 6 additions & 0 deletions test/fixtures/run/todo-fail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { test } from 'node:test';
import assert from 'node:assert';

test('a todo test that fails', { todo: true }, () => {
assert.strictEqual(1, 2);
});
40 changes: 40 additions & 0 deletions test/run.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { test } from 'node:test';
import { strictEqual, ok } from 'node:assert';
import { spawn } from 'node:child_process';
import { once } from 'node:events';
import { fileURLToPath } from 'node:url';

const RUN_SCRIPT = fileURLToPath(new URL('../src/run.ts', import.meta.url));

function fixture(name: string): string {
return fileURLToPath(new URL(`./fixtures/run/${name}`, import.meta.url));
}

const cleanEnv = Object.fromEntries(Object.entries(process.env).filter(([key]) => !key.startsWith('HARPER_INTEGRATION_TEST_')));

async function runCli(globPattern: string, signal: AbortSignal): Promise<number> {
const child = spawn(process.execPath, [RUN_SCRIPT, '--isolation=none', globPattern], {
stdio: 'ignore',
env: cleanEnv,
signal,
});
Comment thread
kriszyp marked this conversation as resolved.
const [code, exitSignal] = await once(child, 'exit');
ok(exitSignal === null, `run.ts was killed by signal ${exitSignal}`);
return code;
}

test('a suite whose only failure is a todo test exits 0', { timeout: 15_000 }, async (t) => {
strictEqual(await runCli(fixture('todo-fail.ts'), t.signal), 0);
});

test('a suite whose only failure is a skipped test exits 0', { timeout: 15_000 }, async (t) => {
strictEqual(await runCli(fixture('skip-fail.ts'), t.signal), 0);
});

test('a suite whose only failure is a todo test with an empty reason exits 0', { timeout: 15_000 }, async (t) => {
strictEqual(await runCli(fixture('empty-reason-todo-fail.ts'), t.signal), 0);
});

test('a suite with a real failure exits 1 (control)', { timeout: 15_000 }, async (t) => {
strictEqual(await runCli(fixture('real-fail.ts'), t.signal), 1);
});
Loading