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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(testing): bust require cache in jest plugin so configs reload #22893

Merged
merged 1 commit into from
Apr 19, 2024
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
20 changes: 19 additions & 1 deletion packages/jest/src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,36 @@ export const createNodes: CreateNodes<JestPluginOptions> = [
},
];

const jestValidatePath = dirname(
require.resolve('jest-validate/package.json', {
paths: [dirname(require.resolve('jest-config'))],
})
);

async function buildJestTargets(
configFilePath: string,
projectRoot: string,
options: JestPluginOptions,
context: CreateNodesContext
): Promise<Pick<ProjectConfiguration, 'targets' | 'metadata'>> {
const absConfigFilePath = resolve(context.workspaceRoot, configFilePath);

if (require.cache[absConfigFilePath]) {
for (const k of Object.keys(require.cache)) {
// Only delete the cache outside of jest-validate
// jest-validate has a Symbol which is important for jest config validation which breaks if the require cache is broken
if (relative(jestValidatePath, k).startsWith('../')) {
delete require.cache[k];
}
}
}

const config = await readConfig(
{
_: [],
$0: undefined,
},
resolve(context.workspaceRoot, configFilePath)
absConfigFilePath
);

const namedInputs = getNamedInputs(projectRoot, context);
Expand Down