| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8b0c5ed commit dce1995
11 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -105,11 +105,11 @@ top level test with two subtests. | |||
| 105 | 105 | ||
| 106 | 106 | ```js | |
| 107 | 107 | test('top level test', async (t) => { | |
| 108 | - t.test('subtest 1', (t) => { | ||
| 108 | + await t.test('subtest 1', (t) => { | ||
| 109 | 109 | assert.strictEqual(1, 1); | |
| 110 | 110 | }); | |
| 111 | 111 | ||
| 112 | - t.test('subtest 2', (t) => { | ||
| 112 | + await t.test('subtest 2', (t) => { | ||
| 113 | 113 | assert.strictEqual(2, 2); | |
| 114 | 114 | }); | |
| 115 | 115 | }); | |
@@ -118,7 +118,12 @@ test('top level test', async (t) => { | |||
| 118 | 118 | > **Note:** `beforeEach` and `afterEach` hooks are triggered | |
| 119 | 119 | > between each subtest execution. | |
| 120 | 120 | ||
| 121 | - Any subtest failures cause the parent test to fail. | ||
| 121 | + In this example, `await` is used to ensure that both subtests have completed. | ||
| 122 | + This is necessary because tests do not wait for their subtests to | ||
| 123 | + complete, unlike tests created within suites. | ||
| 124 | + Any subtests that are still outstanding when their parent finishes | ||
| 125 | + are cancelled and treated as failures. Any subtest failures cause the parent | ||
| 126 | + test to fail. | ||
| 122 | 127 | ||
| 123 | 128 | ## Skipping tests | |
| 124 | 129 | ||
@@ -236,20 +241,20 @@ that are not executed are omitted from the test runner output. | |||
| 236 | 241 | // The suite's 'only' option is set, so these tests are run. | |
| 237 | 242 | test('this test is run', { only: true }, async (t) => { | |
| 238 | 243 | // Within this test, all subtests are run by default. | |
| 239 | - t.test('running subtest'); | ||
| 244 | + await t.test('running subtest'); | ||
| 240 | 245 | ||
| 241 | 246 | // The test context can be updated to run subtests with the 'only' option. | |
| 242 | 247 | t.runOnly(true); | |
| 243 | - t.test('this subtest is now skipped'); | ||
| 244 | - t.test('this subtest is run', { only: true }); | ||
| 248 | + await t.test('this subtest is now skipped'); | ||
| 249 | + await t.test('this subtest is run', { only: true }); | ||
| 245 | 250 | ||
| 246 | 251 | // Switch the context back to execute all tests. | |
| 247 | 252 | t.runOnly(false); | |
| 248 | - t.test('this subtest is now run'); | ||
| 253 | + await t.test('this subtest is now run'); | ||
| 249 | 254 | ||
| 250 | 255 | // Explicitly do not run these tests. | |
| 251 | - t.test('skipped subtest 3', { only: false }); | ||
| 252 | - t.test('skipped subtest 4', { skip: true }); | ||
| 256 | + await t.test('skipped subtest 3', { only: false }); | ||
| 257 | + await t.test('skipped subtest 4', { skip: true }); | ||
| 253 | 258 | }); | |
| 254 | 259 | ||
| 255 | 260 | // The 'only' option is not set, so this test is skipped. | |
@@ -304,13 +309,13 @@ multiple times (e.g. `--test-name-pattern="test 1"`, | |||
| 304 | 309 | ||
| 305 | 310 | ```js | |
| 306 | 311 | test('test 1', async (t) => { | |
| 307 | - t.test('test 2'); | ||
| 308 | - t.test('test 3'); | ||
| 312 | + await t.test('test 2'); | ||
| 313 | + await t.test('test 3'); | ||
| 309 | 314 | }); | |
| 310 | 315 | ||
| 311 | 316 | test('Test 4', async (t) => { | |
| 312 | - t.test('Test 5'); | ||
| 313 | - t.test('test 6'); | ||
| 317 | + await t.test('Test 5'); | ||
| 318 | + await t.test('test 6'); | ||
| 314 | 319 | }); | |
| 315 | 320 | ``` | |
| 316 | 321 | ||
@@ -3388,9 +3393,12 @@ before each subtest of the current test. | |||
| 3388 | 3393 | ```js | |
| 3389 | 3394 | test('top level test', async (t) => { | |
| 3390 | 3395 | t.beforeEach((t) => t.diagnostic(`about to run ${t.name}`)); | |
| 3391 | - t.test('This is a subtest', (t) => { | ||
| 3392 | - assert.ok('some relevant assertion here'); | ||
| 3393 | - }); | ||
| 3396 | + await t.test( | ||
| 3397 | + 'This is a subtest', | ||
| 3398 | + (t) => { | ||
| 3399 | + assert.ok('some relevant assertion here'); | ||
| 3400 | + }, | ||
| 3401 | + ); | ||
| 3394 | 3402 | }); | |
| 3395 | 3403 | ``` | |
| 3396 | 3404 | ||
@@ -3448,9 +3456,12 @@ after each subtest of the current test. | |||
| 3448 | 3456 | ```js | |
| 3449 | 3457 | test('top level test', async (t) => { | |
| 3450 | 3458 | t.afterEach((t) => t.diagnostic(`finished running ${t.name}`)); | |
| 3451 | - t.test('This is a subtest', (t) => { | ||
| 3452 | - assert.ok('some relevant assertion here'); | ||
| 3453 | - }); | ||
| 3459 | + await t.test( | ||
| 3460 | + 'This is a subtest', | ||
| 3461 | + (t) => { | ||
| 3462 | + assert.ok('some relevant assertion here'); | ||
| 3463 | + }, | ||
| 3464 | + ); | ||
| 3454 | 3465 | }); | |
| 3455 | 3466 | ``` | |
| 3456 | 3467 | ||
@@ -3702,8 +3713,10 @@ no-op. | |||
| 3702 | 3713 | test('top level test', (t) => { | |
| 3703 | 3714 | // The test context can be set to run subtests with the 'only' option. | |
| 3704 | 3715 | t.runOnly(true); | |
| 3705 | - t.test('this subtest is now skipped'); | ||
| 3706 | - t.test('this subtest is run', { only: true }); | ||
| 3716 | + return Promise.all([ | ||
| 3717 | + t.test('this subtest is now skipped'), | ||
| 3718 | + t.test('this subtest is run', { only: true }), | ||
| 3719 | + ]); | ||
| 3707 | 3720 | }); | |
| 3708 | 3721 | ``` | |
| 3709 | 3722 | ||
@@ -3775,10 +3788,6 @@ added: | |||
| 3775 | 3788 | - v18.0.0 | |
| 3776 | 3789 | - v16.17.0 | |
| 3777 | 3790 | changes: | |
| 3778 | - - version: | ||
| 3779 | - - v24.0.0 | ||
| 3780 | - pr-url: https://github.com/nodejs/node/pull/56664 | ||
| 3781 | - description: This function no longer returns a `Promise`. | ||
| 3782 | 3791 | - version: | |
| 3783 | 3792 | - v18.8.0 | |
| 3784 | 3793 | - v16.18.0 | |
@@ -3823,13 +3832,14 @@ changes: | |||
| 3823 | 3832 | to this function is a [`TestContext`][] object. If the test uses callbacks, | |
| 3824 | 3833 | the callback function is passed as the second argument. **Default:** A no-op | |
| 3825 | 3834 | function. | |
| 3835 | + * Returns: {Promise} Fulfilled with `undefined` once the test completes. | ||
| 3826 | 3836 | ||
| 3827 | 3837 | This function is used to create subtests under the current test. This function | |
| 3828 | 3838 | behaves in the same fashion as the top level [`test()`][] function. | |
| 3829 | 3839 | ||
| 3830 | 3840 | ```js | |
| 3831 | 3841 | test('top level test', async (t) => { | |
| 3832 | - t.test( | ||
| 3842 | + await t.test( | ||
| 3833 | 3843 | 'This is a subtest', | |
| 3834 | 3844 | { only: false, skip: false, concurrency: 1, todo: false, plan: 1 }, | |
| 3835 | 3845 | (t) => { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -370,7 +370,7 @@ class TestContext { | |||
| 370 | 370 | Test, name, options, fn, overrides, | |
| 371 | 371 | ); | |
| 372 | 372 | ||
| 373 | - subtest.start(); | ||
| 373 | + return subtest.start(); | ||
| 374 | 374 | } | |
| 375 | 375 | ||
| 376 | 376 | before(fn, options) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -158,6 +158,8 @@ Failed tests: | |||
| 158 | 158 | * | |
| 159 | 159 | * | |
| 160 | 160 | * | |
| 161 | + * | ||
| 162 | + * | ||
| 161 | 163 | ✖ subtest sync throw fails (*ms) | |
| 162 | 164 | '2 subtests failed' | |
| 163 | 165 | ✖ timed out async test (*ms) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -576,6 +576,7 @@ not ok 16 - t.after throws - no subtests | |||
| 576 | 576 | * | |
| 577 | 577 | * | |
| 578 | 578 | * | |
| 579 | + * | ||
| 579 | 580 | ... | |
| 580 | 581 | 1..2 | |
| 581 | 582 | not ok 17 - t.beforeEach throws | |
@@ -606,6 +607,8 @@ not ok 17 - t.beforeEach throws | |||
| 606 | 607 | * | |
| 607 | 608 | * | |
| 608 | 609 | * | |
| 610 | + * | ||
| 611 | + * | ||
| 609 | 612 | ... | |
| 610 | 613 | # Subtest: 2 | |
| 611 | 614 | not ok 2 - 2 | |
@@ -626,6 +629,7 @@ not ok 17 - t.beforeEach throws | |||
| 626 | 629 | * | |
| 627 | 630 | * | |
| 628 | 631 | * | |
| 632 | + * | ||
| 629 | 633 | ... | |
| 630 | 634 | 1..2 | |
| 631 | 635 | not ok 18 - t.afterEach throws | |
@@ -753,6 +757,7 @@ not ok 21 - afterEach context when test fails | |||
| 753 | 757 | * | |
| 754 | 758 | * | |
| 755 | 759 | * | |
| 760 | + * | ||
| 756 | 761 | ... | |
| 757 | 762 | 1..2 | |
| 758 | 763 | not ok 22 - afterEach throws and test fails | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -363,6 +363,7 @@ | |||
| 363 | 363 | * | |
| 364 | 364 | * | |
| 365 | 365 | * | |
| 366 | + * | ||
| 366 | 367 | ||
| 367 | 368 | * | |
| 368 | 369 | 1 (*ms) | |
@@ -375,6 +376,8 @@ | |||
| 375 | 376 | * | |
| 376 | 377 | * | |
| 377 | 378 | * | |
| 379 | + * | ||
| 380 | + * | ||
| 378 | 381 | ||
| 379 | 382 | * | |
| 380 | 383 | 2 (*ms) | |
@@ -388,6 +391,7 @@ | |||
| 388 | 391 | * | |
| 389 | 392 | * | |
| 390 | 393 | * | |
| 394 | + * | ||
| 391 | 395 | ||
| 392 | 396 | * | |
| 393 | 397 | 1 (*ms) | |
@@ -435,6 +439,7 @@ | |||
| 435 | 439 | * | |
| 436 | 440 | * | |
| 437 | 441 | * | |
| 442 | + * | ||
| 438 | 443 | ||
| 439 | 444 | * | |
| 440 | 445 | t.after() is called if test body throws (*ms) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -355,7 +355,8 @@ Error [ERR_TEST_FAILURE]: thrown from subtest sync throw fails at first | |||
| 355 | 355 | </testcase> | |
| 356 | 356 | <testcase name="sync throw fails at second" time="*" classname="test" failure="thrown from subtest sync throw fails at second"> | |
| 357 | 357 | <failure type="testCodeFailure" message="thrown from subtest sync throw fails at second"> | |
| 358 | - [Error [ERR_TEST_FAILURE]: thrown from subtest sync throw fails at second] { | ||
| 358 | + Error [ERR_TEST_FAILURE]: thrown from subtest sync throw fails at second | ||
| 359 | + * { | ||
| 359 | 360 | code: 'ERR_TEST_FAILURE', | |
| 360 | 361 | failureType: 'testCodeFailure', | |
| 361 | 362 | cause: Error: thrown from subtest sync throw fails at second | |
@@ -365,6 +366,8 @@ Error [ERR_TEST_FAILURE]: thrown from subtest sync throw fails at first | |||
| 365 | 366 | * | |
| 366 | 367 | * | |
| 367 | 368 | * | |
| 369 | + * | ||
| 370 | + * | ||
| 368 | 371 | } | |
| 369 | 372 | </failure> | |
| 370 | 373 | </testcase> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -606,6 +606,8 @@ not ok 51 - custom inspect symbol that throws fail | |||
| 606 | 606 | * | |
| 607 | 607 | * | |
| 608 | 608 | * | |
| 609 | + * | ||
| 610 | + * | ||
| 609 | 611 | ... | |
| 610 | 612 | 1..2 | |
| 611 | 613 | not ok 52 - subtest sync throw fails | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -614,6 +614,8 @@ not ok 51 - custom inspect symbol that throws fail | |||
| 614 | 614 | * | |
| 615 | 615 | * | |
| 616 | 616 | * | |
| 617 | + * | ||
| 618 | + * | ||
| 617 | 619 | ... | |
| 618 | 620 | 1..2 | |
| 619 | 621 | not ok 52 - subtest sync throw fails | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -289,6 +289,8 @@ | |||
| 289 | 289 | * | |
| 290 | 290 | * | |
| 291 | 291 | * | |
| 292 | + * | ||
| 293 | + * | ||
| 292 | 294 | ||
| 293 | 295 | * | |
| 294 | 296 | timed out async test (*ms) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -292,6 +292,8 @@ | |||
| 292 | 292 | * | |
| 293 | 293 | * | |
| 294 | 294 | * | |
| 295 | + * | ||
| 296 | + * | ||
| 295 | 297 | ||
| 296 | 298 | * | |
| 297 | 299 | timed out async test (*ms) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments