mirror of https://github.com/nodejs/node.git
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: https://github.com/nodejs/node/pull/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>pull/55988/head
parent
b6fe731c55
commit
b09618e474
|
@ -2,7 +2,6 @@
|
|||
const {
|
||||
ArrayPrototypePush,
|
||||
ArrayPrototypePushApply,
|
||||
ArrayPrototypeReduce,
|
||||
ArrayPrototypeShift,
|
||||
ArrayPrototypeSlice,
|
||||
ArrayPrototypeSome,
|
||||
|
@ -846,13 +845,14 @@ class Test extends AsyncResource {
|
|||
async runHook(hook, args) {
|
||||
validateOneOf(hook, 'hook name', kHookNames);
|
||||
try {
|
||||
await ArrayPrototypeReduce(this.hooks[hook], async (prev, hook) => {
|
||||
await prev;
|
||||
const hooks = this.hooks[hook];
|
||||
for (let i = 0; i < hooks.length; ++i) {
|
||||
const hook = hooks[i];
|
||||
await hook.run(args);
|
||||
if (hook.error) {
|
||||
throw hook.error;
|
||||
}
|
||||
}, PromiseResolve());
|
||||
}
|
||||
} catch (err) {
|
||||
const error = new ERR_TEST_FAILURE(`failed running ${hook} hook`, kHookFailure);
|
||||
error.cause = isTestFailureError(err) ? err.cause : err;
|
||||
|
|
|
@ -101,7 +101,7 @@ not ok 2 - 2 after describe
|
|||
*
|
||||
*
|
||||
*
|
||||
async Promise.all (index 0)
|
||||
*
|
||||
...
|
||||
# Subtest: test 2
|
||||
not ok 2 - test 2
|
||||
|
@ -122,7 +122,7 @@ not ok 2 - 2 after describe
|
|||
*
|
||||
*
|
||||
*
|
||||
async Promise.all (index 0)
|
||||
*
|
||||
...
|
||||
1..2
|
||||
not ok 3 - 3 beforeEach describe
|
||||
|
|
|
@ -21,7 +21,6 @@ not ok 2 - /test/fixtures/test-runner/output/global_after_should_fail_the_test.j
|
|||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
...
|
||||
1..1
|
||||
# tests 1
|
||||
|
|
|
@ -77,7 +77,6 @@ not ok 3 - before throws
|
|||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
...
|
||||
# Subtest: before throws - no subtests
|
||||
not ok 4 - before throws - no subtests
|
||||
|
@ -97,7 +96,6 @@ not ok 4 - before throws - no subtests
|
|||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
...
|
||||
# Subtest: after throws
|
||||
# Subtest: 1
|
||||
|
@ -129,6 +127,7 @@ not ok 5 - after throws
|
|||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
...
|
||||
# Subtest: after throws - no subtests
|
||||
not ok 6 - after throws - no subtests
|
||||
|
@ -149,6 +148,7 @@ not ok 6 - after throws - no subtests
|
|||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
...
|
||||
# Subtest: beforeEach throws
|
||||
# Subtest: 1
|
||||
|
@ -167,9 +167,9 @@ not ok 6 - after throws - no subtests
|
|||
*
|
||||
*
|
||||
*
|
||||
async Promise.all (index 0)
|
||||
*
|
||||
*
|
||||
new Promise (<anonymous>)
|
||||
...
|
||||
# Subtest: 2
|
||||
not ok 2 - 2
|
||||
|
@ -188,6 +188,8 @@ not ok 6 - after throws - no subtests
|
|||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
async Promise.all (index 0)
|
||||
...
|
||||
1..2
|
||||
not ok 7 - beforeEach throws
|
||||
|
@ -482,7 +484,6 @@ not ok 15 - t.after throws
|
|||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
...
|
||||
# Subtest: t.after throws - no subtests
|
||||
not ok 16 - t.after throws - no subtests
|
||||
|
@ -502,7 +503,6 @@ not ok 16 - t.after throws - no subtests
|
|||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
...
|
||||
# Subtest: t.beforeEach throws
|
||||
# Subtest: 1
|
||||
|
@ -765,7 +765,6 @@ not ok 24 - run after when before throws
|
|||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
...
|
||||
# Subtest: test hooks - async
|
||||
# Subtest: 1
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
|
||||
before throws - no subtests (*ms)
|
||||
Error: before
|
||||
|
@ -38,7 +37,6 @@
|
|||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
|
||||
after throws
|
||||
1 (*ms)
|
||||
|
@ -55,6 +53,7 @@
|
|||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
|
||||
after throws - no subtests (*ms)
|
||||
Error: after
|
||||
|
@ -67,6 +66,7 @@
|
|||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
|
||||
beforeEach throws
|
||||
1 (*ms)
|
||||
|
@ -78,9 +78,9 @@
|
|||
*
|
||||
*
|
||||
*
|
||||
at async Promise.all (index 0)
|
||||
*
|
||||
*
|
||||
at new Promise (<anonymous>)
|
||||
|
||||
2 (*ms)
|
||||
Error: beforeEach
|
||||
|
@ -92,6 +92,8 @@
|
|||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
at async Promise.all (index 0)
|
||||
|
||||
beforeEach throws (*ms)
|
||||
afterEach throws
|
||||
|
@ -242,7 +244,6 @@
|
|||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
|
||||
t.after throws - no subtests (*ms)
|
||||
Error: after
|
||||
|
@ -255,7 +256,6 @@
|
|||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
|
||||
t.beforeEach throws
|
||||
1 (*ms)
|
||||
|
@ -390,7 +390,6 @@
|
|||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
|
||||
test hooks - async
|
||||
1 (*ms)
|
||||
|
@ -430,7 +429,6 @@
|
|||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
|
||||
*
|
||||
before throws - no subtests (*ms)
|
||||
|
@ -443,7 +441,6 @@
|
|||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
|
||||
*
|
||||
after throws (*ms)
|
||||
|
@ -457,6 +454,7 @@
|
|||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
|
||||
*
|
||||
after throws - no subtests (*ms)
|
||||
|
@ -470,6 +468,7 @@
|
|||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
|
||||
*
|
||||
1 (*ms)
|
||||
|
@ -481,9 +480,9 @@
|
|||
*
|
||||
*
|
||||
*
|
||||
at async Promise.all (index 0)
|
||||
*
|
||||
*
|
||||
at new Promise (<anonymous>)
|
||||
|
||||
*
|
||||
2 (*ms)
|
||||
|
@ -496,6 +495,8 @@
|
|||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
at async Promise.all (index 0)
|
||||
|
||||
*
|
||||
1 (*ms)
|
||||
|
@ -633,7 +634,6 @@
|
|||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
|
||||
*
|
||||
t.after throws - no subtests (*ms)
|
||||
|
@ -647,7 +647,6 @@
|
|||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
|
||||
*
|
||||
1 (*ms)
|
||||
|
@ -776,4 +775,3 @@
|
|||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue