GeezerVison is showing github.com — test_runner: simplify hook running logic · nodejs/node@bf3967f
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 +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 | const { | 3 | 3 | ArrayPrototypePush, | 4 | 4 | ArrayPrototypePushApply, | 5 | | - ArrayPrototypeReduce, | 6 | 5 | ArrayPrototypeShift, | 7 | 6 | ArrayPrototypeSlice, | 8 | 7 | ArrayPrototypeSome, | @@ -846,13 +845,14 @@ class Test extends AsyncResource { | 846 | 845 | async runHook(hook, args) { | 847 | 846 | validateOneOf(hook, 'hook name', kHookNames); | 848 | 847 | try { | 849 | | - await ArrayPrototypeReduce(this.hooks[hook], async (prev, hook) => { | 850 | | - await prev; | | 848 | + const hooks = this.hooks[hook]; | | 849 | + for (let i = 0; i < hooks.length; ++i) { | | 850 | + const hook = hooks[i]; | 851 | 851 | await hook.run(args); | 852 | 852 | if (hook.error) { | 853 | 853 | throw hook.error; | 854 | 854 | } | 855 | | - }, PromiseResolve()); | | 855 | + } | 856 | 856 | } catch (err) { | 857 | 857 | const error = new ERR_TEST_FAILURE(`failed running ${hook} hook`, kHookFailure); | 858 | 858 | error.cause = isTestFailureError(err) ? err.cause : err; | |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/test-runner/output/abort_hooks.snapshot +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -101,7 +101,7 @@ not ok 2 - 2 after describe | 101 | 101 | * | 102 | 102 | * | 103 | 103 | * | 104 | | - async Promise.all (index 0) | | 104 | + * | 105 | 105 | ... | 106 | 106 | # Subtest: test 2 | 107 | 107 | not ok 2 - test 2 | @@ -122,7 +122,7 @@ not ok 2 - 2 after describe | 122 | 122 | * | 123 | 123 | * | 124 | 124 | * | 125 | | - async Promise.all (index 0) | | 125 | + * | 126 | 126 | ... | 127 | 127 | 1..2 | 128 | 128 | not ok 3 - 3 beforeEach describe | |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/test-runner/output/global_after_should_fail_the_test.snapshot -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -21,7 +21,6 @@ not ok 2 - /test/fixtures/test-runner/output/global_after_should_fail_the_test.j | 21 | 21 | * | 22 | 22 | * | 23 | 23 | * | 24 | | - * | 25 | 24 | ... | 26 | 25 | 1..1 | 27 | 26 | # tests 1 | |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/test-runner/output/hooks.snapshot +5-6Lines changed: 5 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -77,7 +77,6 @@ not ok 3 - before throws | 77 | 77 | * | 78 | 78 | * | 79 | 79 | * | 80 | | - * | 81 | 80 | ... | 82 | 81 | # Subtest: before throws - no subtests | 83 | 82 | not ok 4 - before throws - no subtests | @@ -97,7 +96,6 @@ not ok 4 - before throws - no subtests | 97 | 96 | * | 98 | 97 | * | 99 | 98 | * | 100 | | - * | 101 | 99 | ... | 102 | 100 | # Subtest: after throws | 103 | 101 | # Subtest: 1 | @@ -129,6 +127,7 @@ not ok 5 - after throws | 129 | 127 | * | 130 | 128 | * | 131 | 129 | * | | 130 | + * | 132 | 131 | ... | 133 | 132 | # Subtest: after throws - no subtests | 134 | 133 | not ok 6 - after throws - no subtests | @@ -149,6 +148,7 @@ not ok 6 - after throws - no subtests | 149 | 148 | * | 150 | 149 | * | 151 | 150 | * | | 151 | + * | 152 | 152 | ... | 153 | 153 | # Subtest: beforeEach throws | 154 | 154 | # Subtest: 1 | @@ -167,9 +167,9 @@ not ok 6 - after throws - no subtests | 167 | 167 | * | 168 | 168 | * | 169 | 169 | * | 170 | | - async Promise.all (index 0) | 171 | 170 | * | 172 | 171 | * | | 172 | + new Promise (<anonymous>) | 173 | 173 | ... | 174 | 174 | # Subtest: 2 | 175 | 175 | not ok 2 - 2 | @@ -188,6 +188,8 @@ not ok 6 - after throws - no subtests | 188 | 188 | * | 189 | 189 | * | 190 | 190 | * | | 191 | + * | | 192 | + async Promise.all (index 0) | 191 | 193 | ... | 192 | 194 | 1..2 | 193 | 195 | not ok 7 - beforeEach throws | @@ -482,7 +484,6 @@ not ok 15 - t.after throws | 482 | 484 | * | 483 | 485 | * | 484 | 486 | * | 485 | | - * | 486 | 487 | ... | 487 | 488 | # Subtest: t.after throws - no subtests | 488 | 489 | not ok 16 - t.after throws - no subtests | @@ -502,7 +503,6 @@ not ok 16 - t.after throws - no subtests | 502 | 503 | * | 503 | 504 | * | 504 | 505 | * | 505 | | - * | 506 | 506 | ... | 507 | 507 | # Subtest: t.beforeEach throws | 508 | 508 | # Subtest: 1 | @@ -765,7 +765,6 @@ not ok 24 - run after when before throws | 765 | 765 | * | 766 | 766 | * | 767 | 767 | * | 768 | | - * | 769 | 768 | ... | 770 | 769 | # Subtest: test hooks - async | 771 | 770 | # Subtest: 1 | |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/test-runner/output/hooks_spec_reporter.snapshot +10-12Lines changed: 10 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 26 | 26 | * | 27 | 27 | * | 28 | 28 | * | 29 | | - * | 30 | 29 |
| 31 | 30 | before throws - no subtests (*ms) | 32 | 31 | Error: before | | 38 | 37 | * | 39 | 38 | * | 40 | 39 | * | 41 | | - * | 42 | 40 |
| 43 | 41 | after throws | 44 | 42 | 1 (*ms) | | 55 | 53 | * | 56 | 54 | * | 57 | 55 | * | | 56 | + * | 58 | 57 |
| 59 | 58 | after throws - no subtests (*ms) | 60 | 59 | Error: after | | 67 | 66 | * | 68 | 67 | * | 69 | 68 | * | | 69 | + * | 70 | 70 |
| 71 | 71 | beforeEach throws | 72 | 72 | 1 (*ms) | | 78 | 78 | * | 79 | 79 | * | 80 | 80 | * | 81 | | - at async Promise.all (index 0) | 82 | 81 | * | 83 | 82 | * | | 83 | + at new Promise (<anonymous>) | 84 | 84 |
| 85 | 85 | 2 (*ms) | 86 | 86 | Error: beforeEach | | 92 | 92 | * | 93 | 93 | * | 94 | 94 | * | | 95 | + * | | 96 | + at async Promise.all (index 0) | 95 | 97 |
| 96 | 98 | beforeEach throws (*ms) | 97 | 99 | afterEach throws | | 242 | 244 | * | 243 | 245 | * | 244 | 246 | * | 245 | | - * | 246 | 247 |
| 247 | 248 | t.after throws - no subtests (*ms) | 248 | 249 | Error: after | | 255 | 256 | * | 256 | 257 | * | 257 | 258 | * | 258 | | - * | 259 | 259 |
| 260 | 260 | t.beforeEach throws | 261 | 261 | 1 (*ms) | | 390 | 390 | * | 391 | 391 | * | 392 | 392 | * | 393 | | - * | 394 | 393 |
| 395 | 394 | test hooks - async | 396 | 395 | 1 (*ms) | | 430 | 429 | * | 431 | 430 | * | 432 | 431 | * | 433 | | - * | 434 | 432 |
| 435 | 433 | * | 436 | 434 | before throws - no subtests (*ms) | | 443 | 441 | * | 444 | 442 | * | 445 | 443 | * | 446 | | - * | 447 | 444 |
| 448 | 445 | * | 449 | 446 | after throws (*ms) | | 457 | 454 | * | 458 | 455 | * | 459 | 456 | * | | 457 | + * | 460 | 458 |
| 461 | 459 | * | 462 | 460 | after throws - no subtests (*ms) | | 470 | 468 | * | 471 | 469 | * | 472 | 470 | * | | 471 | + * | 473 | 472 |
| 474 | 473 | * | 475 | 474 | 1 (*ms) | | 481 | 480 | * | 482 | 481 | * | 483 | 482 | * | 484 | | - at async Promise.all (index 0) | 485 | 483 | * | 486 | 484 | * | | 485 | + at new Promise (<anonymous>) | 487 | 486 |
| 488 | 487 | * | 489 | 488 | 2 (*ms) | | 496 | 495 | * | 497 | 496 | * | 498 | 497 | * | | 498 | + * | | 499 | + at async Promise.all (index 0) | 499 | 500 |
| 500 | 501 | * | 501 | 502 | 1 (*ms) | | 633 | 634 | * | 634 | 635 | * | 635 | 636 | * | 636 | | - * | 637 | 637 |
| 638 | 638 | * | 639 | 639 | t.after throws - no subtests (*ms) | | 647 | 647 | * | 648 | 648 | * | 649 | 649 | * | 650 | | - * | 651 | 650 |
| 652 | 651 | * | 653 | 652 | 1 (*ms) | | 776 | 775 | * | 777 | 776 | * | 778 | 777 | * | 779 | | - * |
|