Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions packages/vite/src/executors/test/vitest.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")'
Expand Down Expand Up @@ -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']) {
Expand All @@ -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[]) ?? []),
Expand Down