| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d61a505 commit d839640
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -140,8 +140,8 @@ function setup(root) { | |||
| 140 | 140 | const rejectionHandler = | |
| 141 | 141 | createProcessEventHandler('unhandledRejection', root); | |
| 142 | 142 | const coverage = configureCoverage(root, globalOptions); | |
| 143 | - const exitHandler = async () => { | ||
| 144 | - await root.run(new ERR_TEST_FAILURE( | ||
| 143 | + const exitHandler = () => { | ||
| 144 | + root.postRun(new ERR_TEST_FAILURE( | ||
| 145 | 145 | 'Promise resolution is still pending but the event loop has already resolved', | |
| 146 | 146 | kCancelledByParent)); | |
| 147 | 147 | ||
@@ -150,8 +150,8 @@ function setup(root) { | |||
| 150 | 150 | process.removeListener('uncaughtException', exceptionHandler); | |
| 151 | 151 | }; | |
| 152 | 152 | ||
| 153 | - const terminationHandler = async () => { | ||
| 154 | - await exitHandler(); | ||
| 153 | + const terminationHandler = () => { | ||
| 154 | + exitHandler(); | ||
| 155 | 155 | process.exit(); | |
| 156 | 156 | }; | |
| 157 | 157 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -574,7 +574,7 @@ class Test extends AsyncResource { | |||
| 574 | 574 | } | |
| 575 | 575 | } | |
| 576 | 576 | ||
| 577 | - async run(pendingSubtestsError) { | ||
| 577 | + async run() { | ||
| 578 | 578 | if (this.parent !== null) { | |
| 579 | 579 | this.parent.activeSubtests++; | |
| 580 | 580 | } | |
@@ -662,9 +662,16 @@ class Test extends AsyncResource { | |||
| 662 | 662 | } | |
| 663 | 663 | } | |
| 664 | 664 | ||
| 665 | - // Clean up the test. Then, try to report the results and execute any | ||
| 666 | - // tests that were pending due to available concurrency. | ||
| 667 | - this.postRun(pendingSubtestsError); | ||
| 665 | + if (this.parent !== null || typeof this.hookType === 'string') { | ||
| 666 | + // Clean up the test. Then, try to report the results and execute any | ||
| 667 | + // tests that were pending due to available concurrency. | ||
| 668 | + // | ||
| 669 | + // The root test is skipped here because it is a special case. Its | ||
| 670 | + // postRun() method is called when the process is getting ready to exit. | ||
| 671 | + // This helps catch any asynchronous activity that occurs after the tests | ||
| 672 | + // have finished executing. | ||
| 673 | + this.postRun(); | ||
| 674 | + } | ||
| 668 | 675 | } | |
| 669 | 676 | ||
| 670 | 677 | postRun(pendingSubtestsError) { | |
@@ -706,6 +713,18 @@ class Test extends AsyncResource { | |||
| 706 | 713 | this.parent.addReadySubtest(this); | |
| 707 | 714 | this.parent.processReadySubtestRange(false); | |
| 708 | 715 | this.parent.processPendingSubtests(); | |
| 716 | + | ||
| 717 | + if (this.parent === this.root && | ||
| 718 | + this.root.activeSubtests === 0 && | ||
| 719 | + this.root.pendingSubtests.length === 0 && | ||
| 720 | + this.root.readySubtests.size === 0 && | ||
| 721 | + this.root.hooks.after.length > 0) { | ||
| 722 | + // This is done so that any global after() hooks are run. At this point | ||
| 723 | + // all of the tests have finished running. However, there might be | ||
| 724 | + // ref'ed handles keeping the event loop alive. This gives the global | ||
| 725 | + // after() hook a chance to clean them up. | ||
| 726 | + this.root.run(); | ||
| 727 | + } | ||
| 709 | 728 | } else if (!this.reported) { | |
| 710 | 729 | const { | |
| 711 | 730 | diagnostics, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,13 @@ | |||
| 1 | + import * as common from '../../../common/index.mjs'; | ||
| 2 | + import { describe, test } from 'node:test'; | ||
| 3 | + import { setTimeout } from 'node:timers/promises'; | ||
| 4 | + | ||
| 5 | + test('test', common.mustCall()); | ||
| 6 | + describe('suite', common.mustCall(async () => { | ||
| 7 | + test('test', common.mustCall()); | ||
| 8 | + await setTimeout(10); | ||
| 9 | + test('scheduled async', common.mustCall()); | ||
| 10 | + })); | ||
| 11 | + | ||
| 12 | + await setTimeout(10); | ||
| 13 | + test('scheduled async', common.mustCall()); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,37 @@ | |||
| 1 | + TAP version 13 | ||
| 2 | + # Subtest: test | ||
| 3 | + ok 1 - test | ||
| 4 | + --- | ||
| 5 | + duration_ms: * | ||
| 6 | + ... | ||
| 7 | + # Subtest: suite | ||
| 8 | + # Subtest: test | ||
| 9 | + ok 1 - test | ||
| 10 | + --- | ||
| 11 | + duration_ms: * | ||
| 12 | + ... | ||
| 13 | + # Subtest: scheduled async | ||
| 14 | + ok 2 - scheduled async | ||
| 15 | + --- | ||
| 16 | + duration_ms: * | ||
| 17 | + ... | ||
| 18 | + 1..2 | ||
| 19 | + ok 2 - suite | ||
| 20 | + --- | ||
| 21 | + duration_ms: * | ||
| 22 | + type: 'suite' | ||
| 23 | + ... | ||
| 24 | + # Subtest: scheduled async | ||
| 25 | + ok 3 - scheduled async | ||
| 26 | + --- | ||
| 27 | + duration_ms: * | ||
| 28 | + ... | ||
| 29 | + 1..3 | ||
| 30 | + # tests 4 | ||
| 31 | + # suites 1 | ||
| 32 | + # pass 4 | ||
| 33 | + # fail 0 | ||
| 34 | + # cancelled 0 | ||
| 35 | + # skipped 0 | ||
| 36 | + # todo 0 | ||
| 37 | + # duration_ms * | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,7 +22,6 @@ not ok 2 - /test/fixtures/test-runner/output/global_after_should_fail_the_test.j | |||
| 22 | 22 | * | |
| 23 | 23 | * | |
| 24 | 24 | * | |
| 25 | - * | ||
| 26 | 25 | ... | |
| 27 | 26 | 1..1 | |
| 28 | 27 | # tests 1 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -74,6 +74,7 @@ const tests = [ | |||
| 74 | 74 | { name: 'test-runner/output/unresolved_promise.js' }, | |
| 75 | 75 | { name: 'test-runner/output/default_output.js', transform: specTransform, tty: true }, | |
| 76 | 76 | { name: 'test-runner/output/arbitrary-output.js' }, | |
| 77 | + { name: 'test-runner/output/async-test-scheduling.mjs' }, | ||
| 77 | 78 | !skipForceColors ? { | |
| 78 | 79 | name: 'test-runner/output/arbitrary-output-colored.js', | |
| 79 | 80 | transform: snapshot.transform(specTransform, replaceTestDuration), tty: true | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,26 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const { before, after, test } = require('node:test'); | ||
| 4 | + const { createServer } = require('node:http'); | ||
| 5 | + | ||
| 6 | + let server; | ||
| 7 | + | ||
| 8 | + before(common.mustCall(() => { | ||
| 9 | + server = createServer(); | ||
| 10 | + | ||
| 11 | + return new Promise(common.mustCall((resolve, reject) => { | ||
| 12 | + server.listen(0, common.mustCall((err) => { | ||
| 13 | + if (err) { | ||
| 14 | + reject(err); | ||
| 15 | + } else { | ||
| 16 | + resolve(); | ||
| 17 | + } | ||
| 18 | + })); | ||
| 19 | + })); | ||
| 20 | + })); | ||
| 21 | + | ||
| 22 | + after(common.mustCall(() => { | ||
| 23 | + server.close(common.mustCall()); | ||
| 24 | + })); | ||
| 25 | + | ||
| 26 | + test(); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments