Skip to content

Commit

Permalink
leave require.resolve.paths alone [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Sep 19, 2023
1 parent 8830c30 commit dd70576
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
13 changes: 8 additions & 5 deletions packages/jest-config/src/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ export type AllOptions = Config.ProjectConfig & Config.GlobalConfig;
const createConfigError = (message: string) =>
new ValidationError(ERROR, message, DOCUMENTATION_NOTE);

// we wanna avoid webpack trying to be clever
const requireResolve = (module: string) => require.resolve(module);

function verifyDirectoryExists(path: string, key: string) {
try {
const rootStat = statSync(path);
Expand Down Expand Up @@ -525,7 +528,7 @@ export default async function normalize(
}

options.testEnvironment = resolveTestEnvironment({
requireResolveFunction: require.resolve,
requireResolveFunction: requireResolve,
rootDir: options.rootDir,
testEnvironment:
options.testEnvironment ||
Expand Down Expand Up @@ -667,7 +670,7 @@ export default async function normalize(
option &&
resolveRunner(newOptions.resolver, {
filePath: option,
requireResolveFunction: require.resolve,
requireResolveFunction: requireResolve,
rootDir: options.rootDir,
});
}
Expand Down Expand Up @@ -951,7 +954,7 @@ export default async function normalize(
config: {},
path: resolveWatchPlugin(newOptions.resolver, {
filePath: watchPlugin,
requireResolveFunction: require.resolve,
requireResolveFunction: requireResolve,
rootDir: options.rootDir,
}),
};
Expand All @@ -960,7 +963,7 @@ export default async function normalize(
config: watchPlugin[1] || {},
path: resolveWatchPlugin(newOptions.resolver, {
filePath: watchPlugin[0],
requireResolveFunction: require.resolve,
requireResolveFunction: requireResolve,
rootDir: options.rootDir,
}),
};
Expand Down Expand Up @@ -995,7 +998,7 @@ export default async function normalize(
newOptions.testSequencer = resolveSequencer(newOptions.resolver, {
filePath:
options.testSequencer || require.resolve(DEFAULT_CONFIG.testSequencer),
requireResolveFunction: require.resolve,
requireResolveFunction: requireResolve,
rootDir: options.rootDir,
});

Expand Down
3 changes: 2 additions & 1 deletion packages/jest-runner/src/runTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ async function runTestInternal(
}
testEnvironment = resolveTestEnvironment({
...projectConfig,
requireResolveFunction: require.resolve,
// we wanna avoid webpack trying to be clever
requireResolveFunction: module => require.resolve(module),
testEnvironment: customEnvironment,
});
}
Expand Down
3 changes: 3 additions & 0 deletions scripts/buildUtils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ class IgnoreDynamicRequire {
parser.hooks.call
.for('require.resolve')
.tap('IgnoreDynamicRequire', () => true);
parser.hooks.call
.for('require.resolve.paths')
.tap('IgnoreDynamicRequire', () => true);
});
});
}
Expand Down

0 comments on commit dd70576

Please sign in to comment.