From 0ad5b7195b0102a438b04e775b2c9e8e8334a8b9 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 28 May 2021 13:43:39 +0200 Subject: [PATCH] fix unhandled rejection if transform fails --- .../jest-transform/src/ScriptTransformer.ts | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/jest-transform/src/ScriptTransformer.ts b/packages/jest-transform/src/ScriptTransformer.ts index 8fb433899e59..081ca1d8b272 100644 --- a/packages/jest-transform/src/ScriptTransformer.ts +++ b/packages/jest-transform/src/ScriptTransformer.ts @@ -773,18 +773,18 @@ class ScriptTransformer { }, }, ); - const module: ModuleType = await requireOrImportModule( - moduleName, - applyInteropRequireDefault, - ); + try { + const module: ModuleType = await requireOrImportModule( + moduleName, + applyInteropRequireDefault, + ); - if (!callback) { - revertHook(); + if (!callback) { + revertHook(); - return module; - } + return module; + } - try { const cbResult = callback(module); if (isPromise(cbResult)) { @@ -792,11 +792,11 @@ class ScriptTransformer { () => module, ); } + + return module; } finally { revertHook(); } - - return module; } shouldTransform(filename: Config.Path): boolean {