Skip to content

Commit

Permalink
runtime already has the config
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Dec 4, 2020
1 parent 944f0cf commit 7ffb156
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 37 deletions.
10 changes: 2 additions & 8 deletions packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,15 @@ const jestAdapter = async (
});

for (const path of config.setupFilesAfterEnv) {
const esm = runtime.unstable_shouldLoadAsEsm(
path,
config.extensionsToTreatAsEsm,
);
const esm = runtime.unstable_shouldLoadAsEsm(path);

if (esm) {
await runtime.unstable_importModule(path);
} else {
runtime.requireModule(path);
}
}
const esm = runtime.unstable_shouldLoadAsEsm(
testPath,
config.extensionsToTreatAsEsm,
);
const esm = runtime.unstable_shouldLoadAsEsm(testPath);

if (esm) {
await runtime.unstable_importModule(testPath);
Expand Down
10 changes: 2 additions & 8 deletions packages/jest-jasmine2/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,7 @@ export default async function jasmine2(
});

for (const path of config.setupFilesAfterEnv) {
const esm = runtime.unstable_shouldLoadAsEsm(
path,
config.extensionsToTreatAsEsm,
);
const esm = runtime.unstable_shouldLoadAsEsm(path);

if (esm) {
await runtime.unstable_importModule(path);
Expand All @@ -165,10 +162,7 @@ export default async function jasmine2(
const testNameRegex = new RegExp(globalConfig.testNamePattern, 'i');
env.specFilter = (spec: Spec) => testNameRegex.test(spec.getFullName());
}
const esm = runtime.unstable_shouldLoadAsEsm(
testPath,
config.extensionsToTreatAsEsm,
);
const esm = runtime.unstable_shouldLoadAsEsm(testPath);

if (esm) {
await runtime.unstable_importModule(testPath);
Expand Down
10 changes: 2 additions & 8 deletions packages/jest-repl/src/cli/runtime-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,15 @@ export async function run(
);

for (const path of config.setupFiles) {
const esm = runtime.unstable_shouldLoadAsEsm(
path,
config.extensionsToTreatAsEsm,
);
const esm = runtime.unstable_shouldLoadAsEsm(path);

if (esm) {
await runtime.unstable_importModule(path);
} else {
runtime.requireModule(path);
}
}
const esm = runtime.unstable_shouldLoadAsEsm(
filePath,
config.extensionsToTreatAsEsm,
);
const esm = runtime.unstable_shouldLoadAsEsm(filePath);

if (esm) {
await runtime.unstable_importModule(filePath);
Expand Down
5 changes: 1 addition & 4 deletions packages/jest-runner/src/runTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,7 @@ async function runTestInternal(
const start = Date.now();

for (const path of config.setupFiles) {
const esm = runtime.unstable_shouldLoadAsEsm(
path,
config.extensionsToTreatAsEsm,
);
const esm = runtime.unstable_shouldLoadAsEsm(path);

if (esm) {
await runtime.unstable_importModule(path);
Expand Down
5 changes: 1 addition & 4 deletions packages/jest-runtime/src/__mocks__/createRuntime.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,7 @@ module.exports = async function createRuntime(filename, config) {
);

for (const path of config.setupFiles) {
const esm = runtime.unstable_shouldLoadAsEsm(
path,
config.extensionsToTreatAsEsm,
);
const esm = runtime.unstable_shouldLoadAsEsm(path);

if (esm) {
await runtime.unstable_importModule(path);
Expand Down
12 changes: 7 additions & 5 deletions packages/jest-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,12 @@ export default class Runtime {
}

// unstable as it should be replaced by https://github.com/nodejs/modules/issues/393, and we don't want people to use it
unstable_shouldLoadAsEsm = Resolver.unstable_shouldLoadAsEsm;
unstable_shouldLoadAsEsm(path: Config.Path): boolean {
return Resolver.unstable_shouldLoadAsEsm(
path,
this._config.extensionsToTreatAsEsm,
);
}

private async loadEsmModule(
modulePath: Config.Path,
Expand Down Expand Up @@ -499,10 +504,7 @@ export default class Runtime {

if (
this._resolver.isCoreModule(resolved) ||
this.unstable_shouldLoadAsEsm(
resolved,
this._config.extensionsToTreatAsEsm,
)
this.unstable_shouldLoadAsEsm(resolved)
) {
return this.loadEsmModule(resolved, query, isStaticImport);
}
Expand Down

0 comments on commit 7ffb156

Please sign in to comment.