Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add invariant on ESM support in dynamic import #11164

Merged
merged 1 commit into from Mar 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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