| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -132,6 +132,14 @@ class TestContext { | |||
| 132 | 132 | return this.#test.name; | |
| 133 | 133 | } | |
| 134 | 134 | ||
| 135 | + get error() { | ||
| 136 | + return this.#test.error; | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + get passed() { | ||
| 140 | + return this.#test.passed; | ||
| 141 | + } | ||
| 142 | + | ||
| 135 | 143 | diagnostic(message) { | |
| 136 | 144 | this.#test.diagnostic(message); | |
| 137 | 145 | } | |
@@ -637,12 +645,17 @@ class Test extends AsyncResource { | |||
| 637 | 645 | return; | |
| 638 | 646 | } | |
| 639 | 647 | ||
| 640 | - await afterEach(); | ||
| 641 | - await after(); | ||
| 642 | 648 | this.pass(); | |
| 649 | + try { | ||
| 650 | + await afterEach(); | ||
| 651 | + await after(); | ||
| 652 | + } catch (err) { | ||
| 653 | + // If one of the after hooks has thrown unset endTime so that the | ||
| 654 | + // catch below can do its cancel/fail logic. | ||
| 655 | + this.endTime = null; | ||
| 656 | + throw err; | ||
| 657 | + } | ||
| 643 | 658 | } catch (err) { | |
| 644 | - try { await afterEach(); } catch { /* test is already failing, let's ignore the error */ } | ||
| 645 | - try { await after(); } catch { /* Ignore error. */ } | ||
| 646 | 659 | if (isTestFailureError(err)) { | |
| 647 | 660 | if (err.failureType === kTestTimeoutFailure) { | |
| 648 | 661 | this.#cancel(err); | |
@@ -652,6 +665,8 @@ class Test extends AsyncResource { | |||
| 652 | 665 | } else { | |
| 653 | 666 | this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure)); | |
| 654 | 667 | } | |
| 668 | + try { await afterEach(); } catch { /* test is already failing, let's ignore the error */ } | ||
| 669 | + try { await after(); } catch { /* Ignore error. */ } | ||
| 655 | 670 | } finally { | |
| 656 | 671 | stopPromise?.[SymbolDispose](); | |
| 657 | 672 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -152,6 +152,25 @@ test('afterEach when test fails', async (t) => { | |||
| 152 | 152 | await t.test('2', () => {}); | |
| 153 | 153 | }); | |
| 154 | 154 | ||
| 155 | + test('afterEach context when test passes', async (t) => { | ||
| 156 | + t.afterEach(common.mustCall((ctx) => { | ||
| 157 | + assert.strictEqual(ctx.name, '1'); | ||
| 158 | + assert.strictEqual(ctx.passed, true); | ||
| 159 | + assert.strictEqual(ctx.error, null); | ||
| 160 | + })); | ||
| 161 | + await t.test('1', () => {}); | ||
| 162 | + }); | ||
| 163 | + | ||
| 164 | + test('afterEach context when test fails', async (t) => { | ||
| 165 | + const err = new Error('test'); | ||
| 166 | + t.afterEach(common.mustCall((ctx) => { | ||
| 167 | + assert.strictEqual(ctx.name, '1'); | ||
| 168 | + assert.strictEqual(ctx.passed, false); | ||
| 169 | + assert.strictEqual(ctx.error, err); | ||
| 170 | + })); | ||
| 171 | + await t.test('1', () => { throw err }); | ||
| 172 | + }); | ||
| 173 | + | ||
| 155 | 174 | test('afterEach throws and test fails', async (t) => { | |
| 156 | 175 | t.after(common.mustCall()); | |
| 157 | 176 | t.afterEach(() => { throw new Error('afterEach'); }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -505,6 +505,41 @@ not ok 12 - afterEach when test fails | |||
| 505 | 505 | error: '1 subtest failed' | |
| 506 | 506 | code: 'ERR_TEST_FAILURE' | |
| 507 | 507 | ... | |
| 508 | + # Subtest: afterEach context when test passes | ||
| 509 | + # Subtest: 1 | ||
| 510 | + ok 1 - 1 | ||
| 511 | + --- | ||
| 512 | + duration_ms: * | ||
| 513 | + ... | ||
| 514 | + 1..1 | ||
| 515 | + ok 13 - afterEach context when test passes | ||
| 516 | + --- | ||
| 517 | + duration_ms: * | ||
| 518 | + ... | ||
| 519 | + # Subtest: afterEach context when test fails | ||
| 520 | + # Subtest: 1 | ||
| 521 | + not ok 1 - 1 | ||
| 522 | + --- | ||
| 523 | + duration_ms: * | ||
| 524 | + location: '/test/fixtures/test-runner/output/hooks.js:(LINE):11' | ||
| 525 | + failureType: 'testCodeFailure' | ||
| 526 | + error: 'test' | ||
| 527 | + code: 'ERR_TEST_FAILURE' | ||
| 528 | + stack: |- | ||
| 529 | + * | ||
| 530 | + * | ||
| 531 | + * | ||
| 532 | + * | ||
| 533 | + ... | ||
| 534 | + 1..1 | ||
| 535 | + not ok 14 - afterEach context when test fails | ||
| 536 | + --- | ||
| 537 | + duration_ms: * | ||
| 538 | + location: '/test/fixtures/test-runner/output/hooks.js:(LINE):1' | ||
| 539 | + failureType: 'subtestsFailed' | ||
| 540 | + error: '1 subtest failed' | ||
| 541 | + code: 'ERR_TEST_FAILURE' | ||
| 542 | + ... | ||
| 508 | 543 | # Subtest: afterEach throws and test fails | |
| 509 | 544 | # Subtest: 1 | |
| 510 | 545 | not ok 1 - 1 | |
@@ -546,7 +581,7 @@ not ok 12 - afterEach when test fails | |||
| 546 | 581 | * | |
| 547 | 582 | ... | |
| 548 | 583 | 1..2 | |
| 549 | - not ok 13 - afterEach throws and test fails | ||
| 584 | + not ok 15 - afterEach throws and test fails | ||
| 550 | 585 | --- | |
| 551 | 586 | duration_ms: * | |
| 552 | 587 | location: '/test/fixtures/test-runner/output/hooks.js:(LINE):1' | |
@@ -555,7 +590,7 @@ not ok 13 - afterEach throws and test fails | |||
| 555 | 590 | code: 'ERR_TEST_FAILURE' | |
| 556 | 591 | ... | |
| 557 | 592 | # Subtest: t.after() is called if test body throws | |
| 558 | - not ok 14 - t.after() is called if test body throws | ||
| 593 | + not ok 16 - t.after() is called if test body throws | ||
| 559 | 594 | --- | |
| 560 | 595 | duration_ms: * | |
| 561 | 596 | location: '/test/fixtures/test-runner/output/hooks.js:(LINE):1' | |
@@ -580,7 +615,7 @@ not ok 14 - t.after() is called if test body throws | |||
| 580 | 615 | code: 'ERR_TEST_FAILURE' | |
| 581 | 616 | ... | |
| 582 | 617 | 1..1 | |
| 583 | - not ok 15 - run after when before throws | ||
| 618 | + not ok 17 - run after when before throws | ||
| 584 | 619 | --- | |
| 585 | 620 | duration_ms: * | |
| 586 | 621 | type: 'suite' | |
@@ -599,15 +634,15 @@ not ok 15 - run after when before throws | |||
| 599 | 634 | * | |
| 600 | 635 | * | |
| 601 | 636 | ... | |
| 602 | - 1..15 | ||
| 637 | + 1..17 | ||
| 603 | 638 | # before 1 called | |
| 604 | 639 | # before 2 called | |
| 605 | 640 | # after 1 called | |
| 606 | 641 | # after 2 called | |
| 607 | - # tests 39 | ||
| 642 | + # tests 43 | ||
| 608 | 643 | # suites 9 | |
| 609 | - # pass 14 | ||
| 610 | - # fail 22 | ||
| 644 | + # pass 16 | ||
| 645 | + # fail 24 | ||
| 611 | 646 | # cancelled 3 | |
| 612 | 647 | # skipped 0 | |
| 613 | 648 | # todo 0 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -258,6 +258,20 @@ | |||
| 258 | 258 | 2 (*ms) | |
| 259 | 259 | afterEach when test fails (*ms) | |
| 260 | 260 | ||
| 261 | + afterEach context when test passes | ||
| 262 | + 1 (*ms) | ||
| 263 | + afterEach context when test passes (*ms) | ||
| 264 | + | ||
| 265 | + afterEach context when test fails | ||
| 266 | + 1 (*ms) | ||
| 267 | + Error: test | ||
| 268 | + * | ||
| 269 | + * | ||
| 270 | + * | ||
| 271 | + * | ||
| 272 | + | ||
| 273 | + afterEach context when test fails (*ms) | ||
| 274 | + | ||
| 261 | 275 | afterEach throws and test fails | |
| 262 | 276 | 1 (*ms) | |
| 263 | 277 | Error: test | |
@@ -315,10 +329,10 @@ | |||
| 315 | 329 | before 2 called | |
| 316 | 330 | after 1 called | |
| 317 | 331 | after 2 called | |
| 318 | - tests 39 | ||
| 332 | + tests 43 | ||
| 319 | 333 | suites 9 | |
| 320 | - pass 14 | ||
| 321 | - fail 22 | ||
| 334 | + pass 16 | ||
| 335 | + fail 24 | ||
| 322 | 336 | cancelled 3 | |
| 323 | 337 | skipped 0 | |
| 324 | 338 | todo 0 | |
@@ -551,6 +565,14 @@ | |||
| 551 | 565 | * | |
| 552 | 566 | * | |
| 553 | 567 | ||
| 568 | + * | ||
| 569 | + 1 (*ms) | ||
| 570 | + Error: test | ||
| 571 | + * | ||
| 572 | + * | ||
| 573 | + * | ||
| 574 | + * | ||
| 575 | + | ||
| 554 | 576 | * | |
| 555 | 577 | 1 (*ms) | |
| 556 | 578 | Error: test | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -155,6 +155,7 @@ true !== false | |||
| 155 | 155 | <testcase name="+sync throw fail" time="*" classname="test" failure="thrown from subtest sync throw fail"> | |
| 156 | 156 | <failure type="testCodeFailure" message="thrown from subtest sync throw fail"> | |
| 157 | 157 | Error [ERR_TEST_FAILURE]: thrown from subtest sync throw fail | |
| 158 | + * | ||
| 158 | 159 | * { | |
| 159 | 160 | code: 'ERR_TEST_FAILURE', | |
| 160 | 161 | failureType: 'testCodeFailure', | |
@@ -338,6 +339,7 @@ Error [ERR_TEST_FAILURE]: thrown from callback async throw | |||
| 338 | 339 | <testcase name="sync throw fails at first" time="*" classname="test" failure="thrown from subtest sync throw fails at first"> | |
| 339 | 340 | <failure type="testCodeFailure" message="thrown from subtest sync throw fails at first"> | |
| 340 | 341 | Error [ERR_TEST_FAILURE]: thrown from subtest sync throw fails at first | |
| 342 | + * | ||
| 341 | 343 | * { | |
| 342 | 344 | code: 'ERR_TEST_FAILURE', | |
| 343 | 345 | failureType: 'testCodeFailure', | |
| Back | FazBrowse Home | New Git URL |
0 commit comments