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) {
const unregisterTsProject = registerTsProject(tsConfigPath);
try {
module = require(resolvedPath);
module = load(resolvedPath);
} finally {
unregisterTsProject();
}
} else {
module = require(resolvedPath);
module = load(resolvedPath);
}
} else {
module = require(resolvedPath);
module = load(resolvedPath);
}
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);
}