| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 22c1e91 commit cade2fc
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -508,6 +508,11 @@ class Test extends AsyncResource { | |||
| 508 | 508 | } | |
| 509 | 509 | ||
| 510 | 510 | const { args, ctx } = this.getRunArgs(); | |
| 511 | + const after = runOnce(async () => { | ||
| 512 | + if (this.hooks.after.length > 0) { | ||
| 513 | + await this.runHook('after', { args, ctx }); | ||
| 514 | + } | ||
| 515 | + }); | ||
| 511 | 516 | const afterEach = runOnce(async () => { | |
| 512 | 517 | if (this.parent?.hooks.afterEach.length > 0) { | |
| 513 | 518 | await this.parent.runHook('afterEach', { args, ctx }); | |
@@ -549,10 +554,11 @@ class Test extends AsyncResource { | |||
| 549 | 554 | return; | |
| 550 | 555 | } | |
| 551 | 556 | ||
| 552 | - await this.runHook('after', { args, ctx }); | ||
| 557 | + await after(); | ||
| 553 | 558 | await afterEach(); | |
| 554 | 559 | this.pass(); | |
| 555 | 560 | } catch (err) { | |
| 561 | + try { await after(); } catch { /* Ignore error. */ } | ||
| 556 | 562 | try { await afterEach(); } catch { /* test is already failing, let's the error */ } | |
| 557 | 563 | if (isTestFailureError(err)) { | |
| 558 | 564 | if (err.failureType === kTestTimeoutFailure) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -142,3 +142,10 @@ test('afterEach throws and test fails', async (t) => { | |||
| 142 | 142 | await t.test('1', () => { throw new Error('test'); }); | |
| 143 | 143 | await t.test('2', () => {}); | |
| 144 | 144 | }); | |
| 145 | + | ||
| 146 | + test('t.after() is called if test body throws', (t) => { | ||
| 147 | + t.after(() => { | ||
| 148 | + t.diagnostic('- after() called'); | ||
| 149 | + }); | ||
| 150 | + throw new Error('bye'); | ||
| 151 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -475,10 +475,28 @@ not ok 12 - afterEach throws and test fails | |||
| 475 | 475 | error: '2 subtests failed' | |
| 476 | 476 | code: 'ERR_TEST_FAILURE' | |
| 477 | 477 | ... | |
| 478 | - 1..12 | ||
| 479 | - # tests 12 | ||
| 478 | + # Subtest: t.after() is called if test body throws | ||
| 479 | + not ok 13 - t.after() is called if test body throws | ||
| 480 | + --- | ||
| 481 | + duration_ms: * | ||
| 482 | + failureType: 'testCodeFailure' | ||
| 483 | + error: 'bye' | ||
| 484 | + code: 'ERR_TEST_FAILURE' | ||
| 485 | + stack: |- | ||
| 486 | + * | ||
| 487 | + * | ||
| 488 | + * | ||
| 489 | + * | ||
| 490 | + * | ||
| 491 | + * | ||
| 492 | + * | ||
| 493 | + * | ||
| 494 | + ... | ||
| 495 | + # - after() called | ||
| 496 | + 1..13 | ||
| 497 | + # tests 13 | ||
| 480 | 498 | # pass 2 | |
| 481 | - # fail 10 | ||
| 499 | + # fail 11 | ||
| 482 | 500 | # cancelled 0 | |
| 483 | 501 | # skipped 0 | |
| 484 | 502 | # todo 0 | |
| Back | FazBrowse Home | New Git URL |
0 commit comments