fix(vite): add fix for vitest configuration (#14404)
This commit is contained in:
parent
2b69cd5b79
commit
351b4aabf2
@ -210,7 +210,8 @@ describe('Vite Plugin', () => {
|
|||||||
it('should collect coverage', () => {
|
it('should collect coverage', () => {
|
||||||
runCLI(`generate @nrwl/react:lib ${lib} --unitTestRunner=vitest`);
|
runCLI(`generate @nrwl/react:lib ${lib} --unitTestRunner=vitest`);
|
||||||
updateFile(`libs/${lib}/vite.config.ts`, () => {
|
updateFile(`libs/${lib}/vite.config.ts`, () => {
|
||||||
return `import { defineConfig } from 'vite';
|
return `/// <reference types="vitest" />
|
||||||
|
import { defineConfig } from 'vite';
|
||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
exports[`@nrwl/vite:configuration library mode should add config for building library 1`] = `
|
exports[`@nrwl/vite:configuration library mode should add config for building library 1`] = `
|
||||||
"
|
"
|
||||||
|
/// <reference types=\\"vitest\\" />
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||||
@ -58,6 +59,7 @@ import { join } from 'path';
|
|||||||
|
|
||||||
exports[`@nrwl/vite:configuration library mode should set up non buildable library correctly 1`] = `
|
exports[`@nrwl/vite:configuration library mode should set up non buildable library correctly 1`] = `
|
||||||
"
|
"
|
||||||
|
/// <reference types=\\"vitest\\" />
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||||
@ -373,6 +375,7 @@ exports[`@nrwl/vite:configuration transform React app to use Vite by providing c
|
|||||||
|
|
||||||
exports[`@nrwl/vite:configuration transform React app to use Vite should create vite.config file at the root of the app 1`] = `
|
exports[`@nrwl/vite:configuration transform React app to use Vite should create vite.config file at the root of the app 1`] = `
|
||||||
"
|
"
|
||||||
|
/// <reference types=\\"vitest\\" />
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||||
@ -536,6 +539,7 @@ exports[`@nrwl/vite:configuration transform React app to use Vite should transfo
|
|||||||
|
|
||||||
exports[`@nrwl/vite:configuration transform Web app to use Vite should create vite.config file at the root of the app 1`] = `
|
exports[`@nrwl/vite:configuration transform Web app to use Vite should create vite.config file at the root of the app 1`] = `
|
||||||
"
|
"
|
||||||
|
/// <reference types=\\"vitest\\" />
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
|
|
||||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||||
@ -688,6 +692,7 @@ exports[`@nrwl/vite:configuration transform Web app to use Vite should transform
|
|||||||
|
|
||||||
exports[`@nrwl/vite:configuration vitest should create a vitest configuration if "includeVitest" is true 1`] = `
|
exports[`@nrwl/vite:configuration vitest should create a vitest configuration if "includeVitest" is true 1`] = `
|
||||||
"
|
"
|
||||||
|
/// <reference types=\\"vitest\\" />
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
exports[`vitest generator insourceTests should add the insourceSource option in the vite config 1`] = `
|
exports[`vitest generator insourceTests should add the insourceSource option in the vite config 1`] = `
|
||||||
"
|
"
|
||||||
|
/// <reference types=\\"vitest\\" />
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||||
@ -46,6 +47,7 @@ exports[`vitest generator insourceTests should add the insourceSource option in
|
|||||||
|
|
||||||
exports[`vitest generator vite.config should create correct vite.config.ts file for apps 1`] = `
|
exports[`vitest generator vite.config should create correct vite.config.ts file for apps 1`] = `
|
||||||
"
|
"
|
||||||
|
/// <reference types=\\"vitest\\" />
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||||
@ -88,6 +90,7 @@ exports[`vitest generator vite.config should create correct vite.config.ts file
|
|||||||
|
|
||||||
exports[`vitest generator vite.config should create correct vite.config.ts file for non buildable libs 1`] = `
|
exports[`vitest generator vite.config should create correct vite.config.ts file for non buildable libs 1`] = `
|
||||||
"
|
"
|
||||||
|
/// <reference types=\\"vitest\\" />
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||||
|
|||||||
@ -4,6 +4,7 @@ exports[`ensureBuildOptionsInViteConfig should add build and test options if def
|
|||||||
"import dts from 'vite-plugin-dts';
|
"import dts from 'vite-plugin-dts';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
|
|
||||||
|
/// <reference types=\\"vitest\\" />
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||||
@ -203,6 +204,7 @@ import { defineConfig } from 'vite';
|
|||||||
|
|
||||||
exports[`ensureBuildOptionsInViteConfig should add build options if it is using conditional config - do nothing for test 1`] = `
|
exports[`ensureBuildOptionsInViteConfig should add build options if it is using conditional config - do nothing for test 1`] = `
|
||||||
"
|
"
|
||||||
|
/// <reference types=\\"vitest\\" />
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
export default defineConfig(({ command, mode, ssrBuild }) => {
|
export default defineConfig(({ command, mode, ssrBuild }) => {
|
||||||
if (command === 'serve') {
|
if (command === 'serve') {
|
||||||
@ -269,6 +271,7 @@ exports[`ensureBuildOptionsInViteConfig should not do anything if cannot underst
|
|||||||
|
|
||||||
exports[`ensureBuildOptionsInViteConfig should not do anything if project has everything setup already 1`] = `
|
exports[`ensureBuildOptionsInViteConfig should not do anything if project has everything setup already 1`] = `
|
||||||
"
|
"
|
||||||
|
/// <reference types=\\"vitest\\" />
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||||
|
|||||||
@ -567,6 +567,7 @@ export function createOrEditViteConfig(
|
|||||||
}
|
}
|
||||||
|
|
||||||
viteConfigContent = `
|
viteConfigContent = `
|
||||||
|
/// <reference types="vitest" />
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
${reactPluginImportLine}
|
${reactPluginImportLine}
|
||||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
export const noBuildOptions = `
|
export const noBuildOptions = `
|
||||||
|
/// <reference types="vitest" />
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||||
@ -24,6 +25,7 @@ export const noBuildOptions = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
export const someBuildOptions = `
|
export const someBuildOptions = `
|
||||||
|
/// <reference types="vitest" />
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||||
@ -53,6 +55,7 @@ export const someBuildOptions = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
export const noContentDefineConfig = `
|
export const noContentDefineConfig = `
|
||||||
|
/// <reference types="vitest" />
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||||
@ -61,6 +64,7 @@ export const noContentDefineConfig = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
export const conditionalConfig = `
|
export const conditionalConfig = `
|
||||||
|
/// <reference types="vitest" />
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
export default defineConfig(({ command, mode, ssrBuild }) => {
|
export default defineConfig(({ command, mode, ssrBuild }) => {
|
||||||
if (command === 'serve') {
|
if (command === 'serve') {
|
||||||
@ -78,6 +82,7 @@ export const conditionalConfig = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
export const configNoDefineConfig = `
|
export const configNoDefineConfig = `
|
||||||
|
/// <reference types="vitest" />
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||||
@ -93,6 +98,7 @@ export const configNoDefineConfig = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
export const noBuildOptionsHasTestOption = `
|
export const noBuildOptionsHasTestOption = `
|
||||||
|
/// <reference types="vitest" />
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||||
@ -118,6 +124,7 @@ export const noBuildOptionsHasTestOption = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
export const someBuildOptionsSomeTestOption = `
|
export const someBuildOptionsSomeTestOption = `
|
||||||
|
/// <reference types="vitest" />
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||||
@ -142,6 +149,7 @@ export const someBuildOptionsSomeTestOption = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
export const hasEverything = `
|
export const hasEverything = `
|
||||||
|
/// <reference types="vitest" />
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||||
|
|||||||
@ -90,7 +90,8 @@ export function mockViteReactAppGenerator(tree: Tree): Tree {
|
|||||||
|
|
||||||
tree.write(
|
tree.write(
|
||||||
`apps/${appName}/vite.config.ts`,
|
`apps/${appName}/vite.config.ts`,
|
||||||
`import { defineConfig } from 'vite';
|
` /// <reference types="vitest" />
|
||||||
|
import { defineConfig } from 'vite';
|
||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
import tsconfigPaths from 'vite-tsconfig-paths';
|
import tsconfigPaths from 'vite-tsconfig-paths';
|
||||||
|
|
||||||
@ -533,7 +534,8 @@ export function mockReactLibNonBuildableVitestRunnerGenerator(
|
|||||||
|
|
||||||
tree.write(
|
tree.write(
|
||||||
`libs/${libName}/vite.config.ts`,
|
`libs/${libName}/vite.config.ts`,
|
||||||
`import { defineConfig } from 'vite';
|
`/// <reference types="vitest" />
|
||||||
|
import { defineConfig } from 'vite';
|
||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user