From f1f0f15f0a239b678685d9aff312c5c20ff641d4 Mon Sep 17 00:00:00 2001 From: Katerina Skroumpelou Date: Tue, 24 Oct 2023 16:07:39 +0300 Subject: [PATCH] fix(vite): throw informative error if no vitest config exists (#19819) --- packages/vite/src/executors/test/vitest.impl.ts | 12 ++++++++++++ packages/vite/src/utils/options-utils.ts | 7 ++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/executors/test/vitest.impl.ts b/packages/vite/src/executors/test/vitest.impl.ts index 1bb83afd94..7dd83239d9 100644 --- a/packages/vite/src/executors/test/vitest.impl.ts +++ b/packages/vite/src/executors/test/vitest.impl.ts @@ -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, diff --git a/packages/vite/src/utils/options-utils.ts b/packages/vite/src/utils/options-utils.ts index 498153900b..05b849f78a 100644 --- a/packages/vite/src/utils/options-utils.ts +++ b/packages/vite/src/utils/options-utils.ts @@ -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,