fix(testing): resolve full paths to vite configs for vitest (#17396)

This commit is contained in:
Caleb Ukle 2023-06-02 16:32:32 -05:00 committed by GitHub
parent aa6b6394bb
commit ca38a2390b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -53,7 +53,7 @@ export async function* vitestExecutor(
) {
const projectRoot =
context.projectsConfigurations.projects[context.projectName].root;
registerTsConfigPaths(resolve(projectRoot, 'tsconfig.json'));
registerTsConfigPaths(resolve(workspaceRoot, projectRoot, 'tsconfig.json'));
const { startVitest } = await (Function(
'return import("vitest/node")'
@ -111,15 +111,23 @@ async function getSettings(
: ({} as CoverageOptions);
const viteConfigPath = options.config
? joinPathFragments(context.root, options.config)
? options.config // config is expected to be from the workspace root
: findViteConfig(joinPathFragments(context.root, projectRoot));
const resolvedProjectRoot = resolve(workspaceRoot, projectRoot);
const resolvedViteConfigPath = resolve(
workspaceRoot,
projectRoot,
relative(resolvedProjectRoot, viteConfigPath)
);
const resolved = await loadConfigFromFile(
{
mode: options.mode,
command: 'serve',
},
viteConfigPath
resolvedViteConfigPath,
resolvedProjectRoot
);
if (!viteConfigPath || !resolved?.config?.['test']) {
@ -138,7 +146,8 @@ You can manually set the config in the project, ${
// when running nx from the project root, the root will get appended to the cwd.
// creating an invalid path and no tests will be found.
// instead if we are not at the root, let the cwd be root.
root: offset === '' ? projectRoot : '',
root: offset === '' ? resolvedProjectRoot : workspaceRoot,
config: resolvedViteConfigPath,
reporters: [
...(options.reporters ?? []),
...((resolved?.config?.['test']?.reporters as string[]) ?? []),