Skip to content

Commit

Permalink
fix(testing): bust require cache in jest plugin so configs reload (#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz authored Apr 19, 2024
1 parent e2cee00 commit 595ea21
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 595ea21

Please sign in to comment.