Skip to content

Commit

Permalink
chore: add invariant on ESM support in dynamic import (#11164)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Mar 6, 2021
1 parent 26b2237 commit 417650e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/jest-runtime/src/index.ts
Expand Up @@ -403,6 +403,10 @@ export default class Runtime {
specifier: string,
referencingModule: VMModule,
) => {
invariant(
runtimeSupportsVmModules,
'You need to run with a version of node that supports ES Modules in the VM API. See https://jestjs.io/docs/en/ecmascript-modules',
);
const module = await this.resolveModule(
specifier,
referencingModule.identifier,
Expand Down Expand Up @@ -495,7 +499,7 @@ export default class Runtime {
): Promise<void> {
invariant(
runtimeSupportsVmModules,
'You need to run with a version of node that supports ES Modules in the VM API.',
'You need to run with a version of node that supports ES Modules in the VM API. See https://jestjs.io/docs/en/ecmascript-modules',
);

const [path, query] = (moduleName ?? '').split('?');
Expand Down Expand Up @@ -1209,6 +1213,11 @@ export default class Runtime {
filename: scriptFilename,
// @ts-expect-error: Experimental ESM API
importModuleDynamically: async (specifier: string) => {
invariant(
runtimeSupportsVmModules,
'You need to run with a version of node that supports ES Modules in the VM API. See https://jestjs.io/docs/en/ecmascript-modules',
);

const context = this._environment.getVmContext?.();

invariant(context, 'Test environment has been torn down');
Expand Down

0 comments on commit 417650e

Please sign in to comment.