GeezerVison is showing github.com — test_runner: fix async callback in describe not awaited · nodejs/node@6b186d4
File treeExpand file treeCollapse file tree Open diff view settings test/fixtures/test-runner/output
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/test_runner/test.js +14-7Lines changed: 14 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -13,6 +13,7 @@ const { | 13 | 13 | ObjectSeal, | 14 | 14 | PromisePrototypeThen, | 15 | 15 | PromiseResolve, | | 16 | + SafePromisePrototypeFinally, | 16 | 17 | ReflectApply, | 17 | 18 | RegExpPrototypeExec, | 18 | 19 | SafeMap, | @@ -789,17 +790,23 @@ class Suite extends Test { | 789 | 790 | const { ctx, args } = this.getRunArgs(); | 790 | 791 | const runArgs = [this.fn, ctx]; | 791 | 792 | ArrayPrototypePushApply(runArgs, args); | 792 | | - this.buildSuite = PromisePrototypeThen( | 793 | | - PromiseResolve(ReflectApply(this.runInAsyncScope, this, runArgs)), | 794 | | - undefined, | 795 | | - (err) => { | 796 | | - this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure)); | 797 | | - }); | | 793 | + this.buildSuite = SafePromisePrototypeFinally( | | 794 | + PromisePrototypeThen( | | 795 | + PromiseResolve(ReflectApply(this.runInAsyncScope, this, runArgs)), | | 796 | + undefined, | | 797 | + (err) => { | | 798 | + this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure)); | | 799 | + }), | | 800 | + () => { | | 801 | + this.buildPhaseFinished = true; | | 802 | + }, | | 803 | + ); | 798 | 804 | } catch (err) { | 799 | 805 | this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure)); | | 806 | + | | 807 | + this.buildPhaseFinished = true; | 800 | 808 | } | 801 | 809 | this.fn = () => {}; | 802 | | - this.buildPhaseFinished = true; | 803 | 810 | } | 804 | 811 |
| 805 | 812 | getRunArgs() { | |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/test-runner/output/describe_it.js +19Lines changed: 19 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -375,3 +375,22 @@ describe('rejected thenable', () => { | 375 | 375 | }, | 376 | 376 | }; | 377 | 377 | }); | | 378 | + | | 379 | +describe("async describe function", async () => { | | 380 | + await null; | | 381 | + | | 382 | + await it("it inside describe 1", async () => { | | 383 | + await null | | 384 | + }); | | 385 | + await it("it inside describe 2", async () => { | | 386 | + await null; | | 387 | + }); | | 388 | + | | 389 | + describe("inner describe", async () => { | | 390 | + await null; | | 391 | + | | 392 | + it("it inside inner describe", async () => { | | 393 | + await null; | | 394 | + }); | | 395 | + }); | | 396 | +}); |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/test-runner/output/describe_it.snapshot +34-5Lines changed: 34 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -635,8 +635,37 @@ not ok 59 - rejected thenable | 635 | 635 | stack: |- | 636 | 636 | * | 637 | 637 | ... | | 638 | +# Subtest: async describe function | | 639 | + # Subtest: it inside describe 1 | | 640 | + ok 1 - it inside describe 1 | | 641 | + --- | | 642 | + duration_ms: * | | 643 | + ... | | 644 | + # Subtest: it inside describe 2 | | 645 | + ok 2 - it inside describe 2 | | 646 | + --- | | 647 | + duration_ms: * | | 648 | + ... | | 649 | + # Subtest: inner describe | | 650 | + # Subtest: it inside inner describe | | 651 | + ok 1 - it inside inner describe | | 652 | + --- | | 653 | + duration_ms: * | | 654 | + ... | | 655 | + 1..1 | | 656 | + ok 3 - inner describe | | 657 | + --- | | 658 | + duration_ms: * | | 659 | + type: 'suite' | | 660 | + ... | | 661 | + 1..3 | | 662 | +ok 60 - async describe function | | 663 | + --- | | 664 | + duration_ms: * | | 665 | + type: 'suite' | | 666 | + ... | 638 | 667 | # Subtest: invalid subtest fail | 639 | | -not ok 60 - invalid subtest fail | | 668 | +not ok 61 - invalid subtest fail | 640 | 669 | --- | 641 | 670 | duration_ms: * | 642 | 671 | failureType: 'parentAlreadyFinished' | @@ -645,16 +674,16 @@ not ok 60 - invalid subtest fail | 645 | 674 | stack: |- | 646 | 675 | * | 647 | 676 | ... | 648 | | -1..60 | | 677 | +1..61 | 649 | 678 | # Warning: Test "unhandled rejection - passes but warns" generated asynchronous activity after the test ended. This activity created the error "Error: rejected from unhandled rejection fail" and would have caused the test to fail, but instead triggered an unhandledRejection event. | 650 | 679 | # Warning: Test "async unhandled rejection - passes but warns" generated asynchronous activity after the test ended. This activity created the error "Error: rejected from async unhandled rejection fail" and would have caused the test to fail, but instead triggered an unhandledRejection event. | 651 | 680 | # Warning: Test "immediate throw - passes but warns" generated asynchronous activity after the test ended. This activity created the error "Error: thrown from immediate throw fail" and would have caused the test to fail, but instead triggered an uncaughtException event. | 652 | 681 | # Warning: Test "immediate reject - passes but warns" generated asynchronous activity after the test ended. This activity created the error "Error: rejected from immediate reject fail" and would have caused the test to fail, but instead triggered an unhandledRejection event. | 653 | 682 | # Warning: Test "callback called twice in different ticks" generated asynchronous activity after the test ended. This activity created the error "Error [ERR_TEST_FAILURE]: callback invoked multiple times" and would have caused the test to fail, but instead triggered an uncaughtException event. | 654 | 683 | # Warning: Test "callback async throw after done" generated asynchronous activity after the test ended. This activity created the error "Error: thrown from callback async throw after done" and would have caused the test to fail, but instead triggered an uncaughtException event. | 655 | | -# tests 67 | 656 | | -# suites 9 | 657 | | -# pass 29 | | 684 | +# tests 70 | | 685 | +# suites 11 | | 686 | +# pass 32 | 658 | 687 | # fail 19 | 659 | 688 | # cancelled 4 | 660 | 689 | # skipped 10 | |
|