Skip to content

Commit

Permalink
cr: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MoLow committed Jul 10, 2022
1 parent 35602f9 commit bcf53ef
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 57 deletions.
10 changes: 9 additions & 1 deletion lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,9 @@ class Test extends AsyncResource {
if (this.endTime < this.startTime) {
this.endTime = hrtime();
}
if (this.startTime === null) {
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 @@ -458,7 +461,7 @@ class Suite extends Test {
super(options);

try {
this.runInAsyncScope(this.fn);
this.buildSuite = this.runInAsyncScope(this.fn);
} catch (err) {
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure));
}
Expand All @@ -471,6 +474,11 @@ 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.error ? [] : this.subtests;
Expand Down
15 changes: 15 additions & 0 deletions test/message/test_runner_desctibe_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

0 comments on commit bcf53ef

Please sign in to comment.