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
14 changes: 12 additions & 2 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ class Test extends AsyncResource {
if (this.endTime < this.startTime) {
this.endTime = hrtime();
}
this.startTime ??= this.endTime;

// The test has run, so recursively cancel any outstanding subtests and
// mark this test as failed if any subtests failed.
Expand Down Expand Up @@ -457,7 +458,11 @@ class Suite extends Test {
constructor(options) {
super(options);

this.runInAsyncScope(this.fn);
try {
this.buildSuite = this.runInAsyncScope(this.fn);
} catch (err) {
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure));
}
this.fn = () => {};
this.finished = true; // Forbid adding subtests to this suite
}
Expand All @@ -467,9 +472,14 @@ class Suite extends Test {
}

async run() {
try {
await this.buildSuite;
} catch (err) {
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure));
}
this.parent.activeSubtests++;
this.startTime = hrtime();
const subtests = this.skipped ? [] : this.subtests;
const subtests = this.skipped || this.error ? [] : this.subtests;
await ArrayPrototypeReduce(subtests, async (prev, subtest) => {
await prev;
await subtest.run();
Expand Down
15 changes: 15 additions & 0 deletions test/message/test_runner_describe_it.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ it('async throw fail', async () => {
throw new Error('thrown from async throw fail');
});

it('async skip fail', async (t) => {
t.skip();
throw new Error('thrown from async throw fail');
});

it('async assertion fail', async () => {
// Make sure the assert module is handled.
assert.strictEqual(true, false);
Expand Down Expand Up @@ -301,3 +306,13 @@ describe('subtest sync throw fails', () => {
throw new Error('thrown from subtest sync throw fails at second');
});
});

describe('describe sync throw fails', () => {
it('should not run', () => {});
throw new Error('thrown from describe');
});

describe('describe async throw fails', async () => {
it('should not run', () => {});
throw new Error('thrown from describe');
});
Loading