@@ -1456,11 +1456,6 @@ run({ files: [path.resolve('./tests/test.js')] })
14561456added:
14571457 - v22.0.0
14581458 - v20.13.0
1459- changes:
1460- - version:
1461- - v24.0.0
1462- pr-url: https://github.com/nodejs/node/pull/56664
1463- description: This function no longer returns a `Promise`.
14641459-->
14651460
14661461* ` name ` {string} The name of the suite, which is displayed when reporting test
@@ -1471,6 +1466,7 @@ changes:
14711466* ` fn ` {Function|AsyncFunction} The suite function declaring nested tests and
14721467 suites. The first argument to this function is a [ ` SuiteContext ` ] [ ] object.
14731468 ** Default:** A no-op function.
1469+ * Returns: {Promise} Immediately fulfilled with ` undefined ` .
14741470
14751471The ` suite() ` function is imported from the ` node:test ` module.
14761472
@@ -1514,10 +1510,6 @@ added:
15141510 - v18.0.0
15151511 - v16.17.0
15161512changes:
1517- - version:
1518- - v24.0.0
1519- pr-url: https://github.com/nodejs/node/pull/56664
1520- description: This function no longer returns a `Promise`.
15211513 - version:
15221514 - v20.2.0
15231515 - v18.17.0
@@ -1567,6 +1559,8 @@ changes:
15671559 to this function is a [ ` TestContext ` ] [ ] object. If the test uses callbacks,
15681560 the callback function is passed as the second argument. ** Default:** A no-op
15691561 function.
1562+ * Returns: {Promise} Fulfilled with ` undefined ` once
1563+ the test completes, or immediately if the test runs within a suite.
15701564
15711565The ` test() ` function is the value imported from the ` test ` module. Each
15721566invocation of this function results in reporting the test to the {TestsStream}.
@@ -1575,6 +1569,26 @@ The `TestContext` object passed to the `fn` argument can be used to perform
15751569actions related to the current test. Examples include skipping the test, adding
15761570additional diagnostic information, or creating subtests.
15771571
1572+ ` test() ` returns a ` Promise ` that fulfills once the test completes.
1573+ if ` test() ` is called within a suite, it fulfills immediately.
1574+ The return value can usually be discarded for top level tests.
1575+ However, the return value from subtests should be used to prevent the parent
1576+ test from finishing first and cancelling the subtest
1577+ as shown in the following example.
1578+
1579+ ``` js
1580+ test (' top level test' , async (t ) => {
1581+ // The setTimeout() in the following subtest would cause it to outlive its
1582+ // parent test if 'await' is removed on the next line. Once the parent test
1583+ // completes, it will cancel any outstanding subtests.
1584+ await t .test (' longer running subtest' , async (t ) => {
1585+ return new Promise ((resolve , reject ) => {
1586+ setTimeout (resolve, 1000 );
1587+ });
1588+ });
1589+ });
1590+ ```
1591+
15781592The ` timeout ` option can be used to fail the test if it takes longer than
15791593` timeout ` milliseconds to complete. However, it is not a reliable mechanism for
15801594canceling tests because a running test might block the application thread and
0 commit comments