fix(testing): recalculate cypress targets when cypress config changes (#20593)

This commit is contained in:
Jason Jean 2023-12-06 15:53:27 -05:00 committed by GitHub
parent bda1c7d153
commit 0618ba4ee4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -263,15 +263,15 @@ function getCypressConfig(
if (tsConfigPath) { if (tsConfigPath) {
const unregisterTsProject = registerTsProject(tsConfigPath); const unregisterTsProject = registerTsProject(tsConfigPath);
try { try {
module = require(resolvedPath); module = load(resolvedPath);
} finally { } finally {
unregisterTsProject(); unregisterTsProject();
} }
} else { } else {
module = require(resolvedPath); module = load(resolvedPath);
} }
} else { } else {
module = require(resolvedPath); module = load(resolvedPath);
} }
return module.default ?? module; return module.default ?? module;
} }
@ -297,3 +297,18 @@ function getInputs(
}, },
]; ];
} }
/**
* Load the module after ensuring that the require cache is cleared.
*/
function load(path: string): any {
// Clear cache if the path is in the cache
if (require.cache[path]) {
for (const k of Object.keys(require.cache)) {
delete require.cache[k];
}
}
// Then require
return require(path);
}