Skip to content

Commit

Permalink
fix(vite): throw informative error if no vitest config exists (#19819)
Browse files Browse the repository at this point in the history
(cherry picked from commit f1f0f15)
  • Loading branch information
mandarini authored and FrozenPandaz committed Oct 25, 2023
1 parent 074f0a3 commit 0ab6d2f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
12 changes: 12 additions & 0 deletions packages/vite/src/executors/test/vitest.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ async function getSettings(
? options.config // config is expected to be from the workspace root
: findViteConfig(joinPathFragments(context.root, projectRoot));

if (!viteConfigPath) {
throw new Error(
stripIndents`
Unable to load test config from config file ${viteConfigPath}.
Please make sure that vitest is configured correctly,
or use the @nx/vite:vitest generator to configure it for you.
You can read more here: https://nx.dev/nx-api/vite/generators/vitest
`
);
}

const resolvedProjectRoot = resolve(workspaceRoot, projectRoot);
const resolvedViteConfigPath = resolve(
workspaceRoot,
Expand Down
7 changes: 6 additions & 1 deletion packages/vite/src/utils/options-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,13 @@ export function getViteBuildOptions(
const projectRoot =
context.projectsConfigurations.projects[context.projectName].root;

const outputPath = joinPathFragments(
'dist',
projectRoot != '.' ? projectRoot : context.projectName
);

return {
outDir: relative(projectRoot, options.outputPath),
outDir: relative(projectRoot, options.outputPath ?? outputPath),
emptyOutDir: options.emptyOutDir,
reportCompressedSize: true,
cssCodeSplit: options.cssCodeSplit,
Expand Down

0 comments on commit 0ab6d2f

Please sign in to comment.