Skip to content

Commit

Permalink
fix(testing): resolve full paths to vite configs for vitest (#17396)
Browse files Browse the repository at this point in the history
  • Loading branch information
barbados-clemens authored Jun 2, 2023
1 parent aa6b639 commit ca38a23
Showing 1 changed file with 13 additions and 4 deletions.
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

1 comment on commit ca38a23

@vercel
Copy link

@vercel vercel bot commented on ca38a23 Jun 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-five.vercel.app
nx.dev
nx-dev-nrwl.vercel.app
nx-dev-git-master-nrwl.vercel.app

Please sign in to comment.