Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bf3967f

Browse filesBrowse files
cjihrigruyadorno
authored andcommitted
test_runner: simplify hook running logic
This commit removes some asynchronous logic from the runHook() method and replaces ArrayPrototypeReduce() with a for loop. PR-URL: #55963 Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 1a78bde commit bf3967f
Copy full SHA for bf3967f

File tree

Expand file treeCollapse file tree

5 files changed

+21
-25
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

5 files changed

+21
-25
lines changed
Open diff view settings
Collapse file

‎lib/internal/test_runner/test.js‎

Copy file name to clipboardExpand all lines: lib/internal/test_runner/test.js
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
const {
33
ArrayPrototypePush,
44
ArrayPrototypePushApply,
5-
ArrayPrototypeReduce,
65
ArrayPrototypeShift,
76
ArrayPrototypeSlice,
87
ArrayPrototypeSome,
@@ -846,13 +845,14 @@ class Test extends AsyncResource {
846845
async runHook(hook, args) {
847846
validateOneOf(hook, 'hook name', kHookNames);
848847
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];
851851
await hook.run(args);
852852
if (hook.error) {
853853
throw hook.error;
854854
}
855-
}, PromiseResolve());
855+
}
856856
} catch (err) {
857857
const error = new ERR_TEST_FAILURE(`failed running ${hook} hook`, kHookFailure);
858858
error.cause = isTestFailureError(err) ? err.cause : err;
Collapse file

‎test/fixtures/test-runner/output/abort_hooks.snapshot‎

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 numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ not ok 2 - 2 after describe
101101
*
102102
*
103103
*
104-
async Promise.all (index 0)
104+
*
105105
...
106106
# Subtest: test 2
107107
not ok 2 - test 2
@@ -122,7 +122,7 @@ not ok 2 - 2 after describe
122122
*
123123
*
124124
*
125-
async Promise.all (index 0)
125+
*
126126
...
127127
1..2
128128
not ok 3 - 3 beforeEach describe
Collapse file

‎test/fixtures/test-runner/output/global_after_should_fail_the_test.snapshot‎

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 numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ not ok 2 - /test/fixtures/test-runner/output/global_after_should_fail_the_test.j
2121
*
2222
*
2323
*
24-
*
2524
...
2625
1..1
2726
# tests 1
Collapse file

‎test/fixtures/test-runner/output/hooks.snapshot‎

Copy file name to clipboardExpand all lines: test/fixtures/test-runner/output/hooks.snapshot
+5-6Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ not ok 3 - before throws
7777
*
7878
*
7979
*
80-
*
8180
...
8281
# Subtest: before throws - no subtests
8382
not ok 4 - before throws - no subtests
@@ -97,7 +96,6 @@ not ok 4 - before throws - no subtests
9796
*
9897
*
9998
*
100-
*
10199
...
102100
# Subtest: after throws
103101
# Subtest: 1
@@ -129,6 +127,7 @@ not ok 5 - after throws
129127
*
130128
*
131129
*
130+
*
132131
...
133132
# Subtest: after throws - no subtests
134133
not ok 6 - after throws - no subtests
@@ -149,6 +148,7 @@ not ok 6 - after throws - no subtests
149148
*
150149
*
151150
*
151+
*
152152
...
153153
# Subtest: beforeEach throws
154154
# Subtest: 1
@@ -167,9 +167,9 @@ not ok 6 - after throws - no subtests
167167
*
168168
*
169169
*
170-
async Promise.all (index 0)
171170
*
172171
*
172+
new Promise (<anonymous>)
173173
...
174174
# Subtest: 2
175175
not ok 2 - 2
@@ -188,6 +188,8 @@ not ok 6 - after throws - no subtests
188188
*
189189
*
190190
*
191+
*
192+
async Promise.all (index 0)
191193
...
192194
1..2
193195
not ok 7 - beforeEach throws
@@ -482,7 +484,6 @@ not ok 15 - t.after throws
482484
*
483485
*
484486
*
485-
*
486487
...
487488
# Subtest: t.after throws - no subtests
488489
not ok 16 - t.after throws - no subtests
@@ -502,7 +503,6 @@ not ok 16 - t.after throws - no subtests
502503
*
503504
*
504505
*
505-
*
506506
...
507507
# Subtest: t.beforeEach throws
508508
# Subtest: 1
@@ -765,7 +765,6 @@ not ok 24 - run after when before throws
765765
*
766766
*
767767
*
768-
*
769768
...
770769
# Subtest: test hooks - async
771770
# Subtest: 1
Collapse file

‎test/fixtures/test-runner/output/hooks_spec_reporter.snapshot‎

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 numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
*
2727
*
2828
*
29-
*
3029

3130
before throws - no subtests (*ms)
3231
Error: before
@@ -38,7 +37,6 @@
3837
*
3938
*
4039
*
41-
*
4240

4341
after throws
4442
1 (*ms)
@@ -55,6 +53,7 @@
5553
*
5654
*
5755
*
56+
*
5857

5958
after throws - no subtests (*ms)
6059
Error: after
@@ -67,6 +66,7 @@
6766
*
6867
*
6968
*
69+
*
7070

7171
beforeEach throws
7272
1 (*ms)
@@ -78,9 +78,9 @@
7878
*
7979
*
8080
*
81-
at async Promise.all (index 0)
8281
*
8382
*
83+
at new Promise (<anonymous>)
8484

8585
2 (*ms)
8686
Error: beforeEach
@@ -92,6 +92,8 @@
9292
*
9393
*
9494
*
95+
*
96+
at async Promise.all (index 0)
9597

9698
beforeEach throws (*ms)
9799
afterEach throws
@@ -242,7 +244,6 @@
242244
*
243245
*
244246
*
245-
*
246247

247248
t.after throws - no subtests (*ms)
248249
Error: after
@@ -255,7 +256,6 @@
255256
*
256257
*
257258
*
258-
*
259259

260260
t.beforeEach throws
261261
1 (*ms)
@@ -390,7 +390,6 @@
390390
*
391391
*
392392
*
393-
*
394393

395394
test hooks - async
396395
1 (*ms)
@@ -430,7 +429,6 @@
430429
*
431430
*
432431
*
433-
*
434432

435433
*
436434
before throws - no subtests (*ms)
@@ -443,7 +441,6 @@
443441
*
444442
*
445443
*
446-
*
447444

448445
*
449446
after throws (*ms)
@@ -457,6 +454,7 @@
457454
*
458455
*
459456
*
457+
*
460458

461459
*
462460
after throws - no subtests (*ms)
@@ -470,6 +468,7 @@
470468
*
471469
*
472470
*
471+
*
473472

474473
*
475474
1 (*ms)
@@ -481,9 +480,9 @@
481480
*
482481
*
483482
*
484-
at async Promise.all (index 0)
485483
*
486484
*
485+
at new Promise (<anonymous>)
487486

488487
*
489488
2 (*ms)
@@ -496,6 +495,8 @@
496495
*
497496
*
498497
*
498+
*
499+
at async Promise.all (index 0)
499500

500501
*
501502
1 (*ms)
@@ -633,7 +634,6 @@
633634
*
634635
*
635636
*
636-
*
637637

638638
*
639639
t.after throws - no subtests (*ms)
@@ -647,7 +647,6 @@
647647
*
648648
*
649649
*
650-
*
651650

652651
*
653652
1 (*ms)
@@ -776,4 +775,3 @@
776775
*
777776
*
778777
*
779-
*

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.