From 3bfcb07d39133f26d9f83f2adefd896d12377417 Mon Sep 17 00:00:00 2001 From: mrazauskas <72159681+mrazauskas@users.noreply.github.com> Date: Sat, 6 Nov 2021 08:38:25 +0200 Subject: [PATCH] refactor: use `invariant` --- packages/jest-runtime/src/index.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index 6cf2bb9dbf90..a3356062eb0c 100644 --- a/packages/jest-runtime/src/index.ts +++ b/packages/jest-runtime/src/index.ts @@ -648,14 +648,16 @@ export default class Runtime { const isSourceTextModule = (module: unknown): module is SourceTextModule => module instanceof SourceTextModule; - if ( + invariant( isSourceTextModule(evaluatedModule) && - evaluatedModule.namespace.default !== undefined - ) { - return {default: evaluatedModule.namespace.default}; - } + evaluatedModule.namespace.default !== undefined, + `"${path.relative( + '', + evaluatedModule.identifier, + )}" must be a node module with default export.`, + ); - throw new Error(`Module ${from} must have default export.`); + return {default: evaluatedModule.namespace.default}; } private loadCjsAsEsm(