From 14d305b51d98fe9727d5dd5d9838627d5f2ff081 Mon Sep 17 00:00:00 2001 From: Mikhail Date: Sun, 21 Jul 2024 11:03:37 +0300 Subject: [PATCH] fix: simplify promise finally action (#15199) --- packages/jest-circus/src/utils.ts | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/packages/jest-circus/src/utils.ts b/packages/jest-circus/src/utils.ts index c259aad3da03..389c8beddf50 100644 --- a/packages/jest-circus/src/utils.ts +++ b/packages/jest-circus/src/utils.ts @@ -301,20 +301,13 @@ export const callAsyncCircusFn = ( // Otherwise this test is synchronous, and if it didn't throw it means // it passed. resolve(); - }) - .then(() => { - completed = true; - // If timeout is not cleared/unrefed the node process won't exit until - // it's resolved. - timeoutID.unref?.(); - clearTimeout(timeoutID); - }) - .catch(error => { - completed = true; - timeoutID.unref?.(); - clearTimeout(timeoutID); - throw error; - }); + }).finally(() => { + completed = true; + // If timeout is not cleared/unrefed the node process won't exit until + // it's resolved. + timeoutID.unref?.(); + clearTimeout(timeoutID); + }); }; export const getTestDuration = (test: Circus.TestEntry): number | null => {