@@ -1472,11 +1472,6 @@ run({ files: [path.resolve('./tests/test.js')] })
14721472added:
14731473 - v22.0.0
14741474 - v20.13.0
1475- changes:
1476- - version:
1477- - v24.0.0
1478- pr-url: https://github.com/nodejs/node/pull/56664
1479- description: This function no longer returns a `Promise`.
14801475-->
14811476
14821477* ` name ` {string} The name of the suite, which is displayed when reporting test
@@ -1487,6 +1482,7 @@ changes:
14871482* ` fn ` {Function|AsyncFunction} The suite function declaring nested tests and
14881483 suites. The first argument to this function is a [ ` SuiteContext ` ] [ ] object.
14891484 ** Default:** A no-op function.
1485+ * Returns: {Promise} Immediately fulfilled with ` undefined ` .
14901486
14911487The ` suite() ` function is imported from the ` node:test ` module.
14921488
@@ -1530,10 +1526,6 @@ added:
15301526 - v18.0.0
15311527 - v16.17.0
15321528changes:
1533- - version:
1534- - v24.0.0
1535- pr-url: https://github.com/nodejs/node/pull/56664
1536- description: This function no longer returns a `Promise`.
15371529 - version:
15381530 - v20.2.0
15391531 - v18.17.0
@@ -1583,6 +1575,8 @@ changes:
15831575 to this function is a [ ` TestContext ` ] [ ] object. If the test uses callbacks,
15841576 the callback function is passed as the second argument. ** Default:** A no-op
15851577 function.
1578+ * Returns: {Promise} Fulfilled with ` undefined ` once
1579+ the test completes, or immediately if the test runs within a suite.
15861580
15871581The ` test() ` function is the value imported from the ` test ` module. Each
15881582invocation of this function results in reporting the test to the {TestsStream}.
@@ -1591,6 +1585,26 @@ The `TestContext` object passed to the `fn` argument can be used to perform
15911585actions related to the current test. Examples include skipping the test, adding
15921586additional diagnostic information, or creating subtests.
15931587
1588+ ` test() ` returns a ` Promise ` that fulfills once the test completes.
1589+ if ` test() ` is called within a suite, it fulfills immediately.
1590+ The return value can usually be discarded for top level tests.
1591+ However, the return value from subtests should be used to prevent the parent
1592+ test from finishing first and cancelling the subtest
1593+ as shown in the following example.
1594+
1595+ ``` js
1596+ test (' top level test' , async (t ) => {
1597+ // The setTimeout() in the following subtest would cause it to outlive its
1598+ // parent test if 'await' is removed on the next line. Once the parent test
1599+ // completes, it will cancel any outstanding subtests.
1600+ await t .test (' longer running subtest' , async (t ) => {
1601+ return new Promise ((resolve , reject ) => {
1602+ setTimeout (resolve, 1000 );
1603+ });
1604+ });
1605+ });
1606+ ```
1607+
15941608The ` timeout ` option can be used to fail the test if it takes longer than
15951609` timeout ` milliseconds to complete. However, it is not a reliable mechanism for
15961610canceling tests because a running test might block the application thread and
0 commit comments