Skip to content

Commit f28198c

Browse files
MoLowdanielleadams
authored andcommitted
test_runner: catch errors thrown within describe
PR-URL: #43729 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent 979f469 commit f28198c

File tree

3 files changed

+139
-52
lines changed

3 files changed

+139
-52
lines changed

‎lib/internal/test_runner/test.js‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ class Test extends AsyncResource{
360360
if(this.endTime<this.startTime){
361361
this.endTime=hrtime();
362362
}
363+
this.startTime??=this.endTime;
363364

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

460-
this.runInAsyncScope(this.fn);
461+
try{
462+
this.buildSuite=this.runInAsyncScope(this.fn);
463+
}catch(err){
464+
this.fail(newERR_TEST_FAILURE(err,kTestCodeFailure));
465+
}
461466
this.fn=()=>{};
462467
this.finished=true;// Forbid adding subtests to this suite
463468
}
@@ -467,9 +472,14 @@ class Suite extends Test{
467472
}
468473

469474
asyncrun(){
475+
try{
476+
awaitthis.buildSuite;
477+
}catch(err){
478+
this.fail(newERR_TEST_FAILURE(err,kTestCodeFailure));
479+
}
470480
this.parent.activeSubtests++;
471481
this.startTime=hrtime();
472-
constsubtests=this.skipped ? [] : this.subtests;
482+
constsubtests=this.skipped||this.error? [] : this.subtests;
473483
awaitArrayPrototypeReduce(subtests,async(prev,subtest)=>{
474484
awaitprev;
475485
awaitsubtest.run();

‎test/message/test_runner_describe_it.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ it('async throw fail', async () =>{
4545
thrownewError('thrown from async throw fail');
4646
});
4747

48+
it('async skip fail',async(t)=>{
49+
t.skip();
50+
thrownewError('thrown from async throw fail');
51+
});
52+
4853
it('async assertion fail',async()=>{
4954
// Make sure the assert module is handled.
5055
assert.strictEqual(true,false);
@@ -301,3 +306,13 @@ describe('subtest sync throw fails', () =>{
301306
thrownewError('thrown from subtest sync throw fails at second');
302307
});
303308
});
309+
310+
describe('describe sync throw fails',()=>{
311+
it('should not run',()=>{});
312+
thrownewError('thrown from describe');
313+
});
314+
315+
describe('describe async throw fails',async()=>{
316+
it('should not run',()=>{});
317+
thrownewError('thrown from describe');
318+
});

0 commit comments

Comments
(0)