Skip to content

Commit

Permalink
fix(testing): bust require cache in jest plugin so configs reload
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Apr 18, 2024
1 parent 4d6cd36 commit 8ffc372
Showing 1 changed file with 19 additions and 1 deletion.
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

0 comments on commit 8ffc372

Please sign in to comment.