From 2e2ee7ec7d9b9087f1e9469f1bec24d19627fb25 Mon Sep 17 00:00:00 2001 From: Katerina Skroumpelou Date: Fri, 10 Nov 2023 10:48:24 +0200 Subject: [PATCH] fix(vite): vitest should use v8 as default c8 is deprecated --- .../generated/packages/vite/generators/vitest.json | 2 +- e2e/vite/src/vite.test.ts | 2 +- packages/js/src/generators/library/library.ts | 2 +- .../src/generators/application/application.ts | 2 +- packages/react/src/generators/library/library.ts | 2 +- packages/vite/migrations.json | 14 ++++++++++++++ packages/vite/src/executors/test/vitest.impl.ts | 10 ++++++---- .../src/generators/configuration/configuration.ts | 2 +- packages/vite/src/generators/vitest/schema.d.ts | 2 +- packages/vite/src/generators/vitest/schema.json | 2 +- .../vite/src/generators/vitest/vitest-generator.ts | 5 ++--- packages/vite/src/generators/vitest/vitest.spec.ts | 2 +- packages/vite/src/utils/versions.ts | 1 - .../library/__snapshots__/library.spec.ts.snap | 2 +- .../vue/src/generators/library/lib/add-vite.ts | 2 +- .../web/src/generators/application/application.ts | 2 +- 16 files changed, 34 insertions(+), 20 deletions(-) diff --git a/docs/generated/packages/vite/generators/vitest.json b/docs/generated/packages/vite/generators/vitest.json index f9b72140e3a37..7a14929e696a7 100644 --- a/docs/generated/packages/vite/generators/vitest.json +++ b/docs/generated/packages/vite/generators/vitest.json @@ -32,7 +32,7 @@ }, "coverageProvider": { "type": "string", - "enum": ["v8", "c8", "istanbul"], + "enum": ["v8", "istanbul", "custom"], "default": "v8", "description": "Coverage provider to use." }, diff --git a/e2e/vite/src/vite.test.ts b/e2e/vite/src/vite.test.ts index ef4fd932563f0..daa6207d609dc 100644 --- a/e2e/vite/src/vite.test.ts +++ b/e2e/vite/src/vite.test.ts @@ -379,7 +379,7 @@ export default App; environment: 'jsdom', include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], coverage: { - provider: "c8", + provider: "v8", enabled: true, lines: 100, statements: 100, diff --git a/packages/js/src/generators/library/library.ts b/packages/js/src/generators/library/library.ts index 0d918f44ceffc..9b8bc833f4935 100644 --- a/packages/js/src/generators/library/library.ts +++ b/packages/js/src/generators/library/library.ts @@ -128,7 +128,7 @@ export async function libraryGeneratorInternal( const vitestTask = await vitestGenerator(tree, { project: options.name, uiFramework: 'none', - coverageProvider: 'c8', + coverageProvider: 'v8', skipFormat: true, testEnvironment: options.testEnvironment, }); diff --git a/packages/react/src/generators/application/application.ts b/packages/react/src/generators/application/application.ts index dedb732170782..f6377619755b2 100644 --- a/packages/react/src/generators/application/application.ts +++ b/packages/react/src/generators/application/application.ts @@ -192,7 +192,7 @@ export async function applicationGeneratorInternal( const vitestTask = await vitestGenerator(host, { uiFramework: 'react', - coverageProvider: 'c8', + coverageProvider: 'v8', project: options.projectName, inSourceTests: options.inSourceTests, skipFormat: true, diff --git a/packages/react/src/generators/library/library.ts b/packages/react/src/generators/library/library.ts index 762c267a33d4f..325ed29a3f3b8 100644 --- a/packages/react/src/generators/library/library.ts +++ b/packages/react/src/generators/library/library.ts @@ -147,7 +147,7 @@ export async function libraryGeneratorInternal(host: Tree, schema: Schema) { const vitestTask = await vitestGenerator(host, { uiFramework: 'react', project: options.name, - coverageProvider: 'c8', + coverageProvider: 'v8', inSourceTests: options.inSourceTests, skipFormat: true, testEnvironment: 'jsdom', diff --git a/packages/vite/migrations.json b/packages/vite/migrations.json index 1f3613f09a68f..699dd254ea4bc 100644 --- a/packages/vite/migrations.json +++ b/packages/vite/migrations.json @@ -43,6 +43,20 @@ } }, "packageJsonUpdates": { + "17.2.0": { + "@vitest/coverage-v8": { + "version": "~0.34.6", + "alwaysAddToPackageJson": false + }, + "@vitest/ui": { + "version": "~0.34.6", + "alwaysAddToPackageJson": false + }, + "@vitest/coverage-istanbul": { + "version": "~0.34.6", + "alwaysAddToPackageJson": false + } + }, "16.4.0-beta.7": { "version": "16.4.0-beta.7", "packages": { diff --git a/packages/vite/src/executors/test/vitest.impl.ts b/packages/vite/src/executors/test/vitest.impl.ts index 7dd83239d9f19..9761f8884ac8e 100644 --- a/packages/vite/src/executors/test/vitest.impl.ts +++ b/packages/vite/src/executors/test/vitest.impl.ts @@ -108,12 +108,14 @@ async function getSettings( const packageJson = existsSync(packageJsonPath) ? readJsonFile(packageJsonPath) : undefined; - let provider: 'v8' | 'c8' = 'v8'; + let provider: 'v8' | 'istanbul' | 'custom'; if ( - packageJson?.dependencies?.['@vitest/coverage-c8'] || - packageJson?.devDependencies?.['@vitest/coverage-c8'] + packageJson?.dependencies?.['@vitest/coverage-istanbul'] || + packageJson?.devDependencies?.['@vitest/coverage-istanbul'] ) { - provider = 'c8'; + provider = 'istanbul'; + } else { + provider = 'v8'; } const offset = relative(workspaceRoot, context.cwd); // if reportsDirectory is not provided vitest will remove all files in the project root diff --git a/packages/vite/src/generators/configuration/configuration.ts b/packages/vite/src/generators/configuration/configuration.ts index 1367f85546992..7c46ca9c20638 100644 --- a/packages/vite/src/generators/configuration/configuration.ts +++ b/packages/vite/src/generators/configuration/configuration.ts @@ -232,7 +232,7 @@ export async function viteConfigurationGenerator( project: schema.project, uiFramework: schema.uiFramework, inSourceTests: schema.inSourceTests, - coverageProvider: 'c8', + coverageProvider: 'v8', skipViteConfig: true, testTarget: testTargetName, skipFormat: true, diff --git a/packages/vite/src/generators/vitest/schema.d.ts b/packages/vite/src/generators/vitest/schema.d.ts index 5b5039be21855..4945d4f9e0b28 100644 --- a/packages/vite/src/generators/vitest/schema.d.ts +++ b/packages/vite/src/generators/vitest/schema.d.ts @@ -1,7 +1,7 @@ export interface VitestGeneratorSchema { project: string; uiFramework: 'react' | 'none'; - coverageProvider: 'v8' | 'c8' | 'istanbul'; + coverageProvider: 'v8' | 'istanbul' | 'custom'; inSourceTests?: boolean; skipViteConfig?: boolean; testTarget?: string; diff --git a/packages/vite/src/generators/vitest/schema.json b/packages/vite/src/generators/vitest/schema.json index 6f98e0f49bcb2..fe3eb795b622a 100644 --- a/packages/vite/src/generators/vitest/schema.json +++ b/packages/vite/src/generators/vitest/schema.json @@ -31,7 +31,7 @@ }, "coverageProvider": { "type": "string", - "enum": ["v8", "c8", "istanbul"], + "enum": ["v8", "istanbul", "custom"], "default": "v8", "description": "Coverage provider to use." }, diff --git a/packages/vite/src/generators/vitest/vitest-generator.ts b/packages/vite/src/generators/vitest/vitest-generator.ts index 67b2666ef2a69..dc3812858248a 100644 --- a/packages/vite/src/generators/vitest/vitest-generator.ts +++ b/packages/vite/src/generators/vitest/vitest-generator.ts @@ -19,7 +19,6 @@ import { VitestGeneratorSchema } from './schema'; import initGenerator from '../init/init'; import { - vitestCoverageC8Version, vitestCoverageIstanbulVersion, vitestCoverageV8Version, } from '../../utils/versions'; @@ -202,9 +201,9 @@ function getCoverageProviderDependency( coverageProvider: VitestGeneratorSchema['coverageProvider'] ) { switch (coverageProvider) { - case 'c8': + case 'v8': return { - '@vitest/coverage-c8': vitestCoverageC8Version, + '@vitest/coverage-v8': vitestCoverageV8Version, }; case 'istanbul': return { diff --git a/packages/vite/src/generators/vitest/vitest.spec.ts b/packages/vite/src/generators/vitest/vitest.spec.ts index a1ccf54230311..101b16d38553f 100644 --- a/packages/vite/src/generators/vitest/vitest.spec.ts +++ b/packages/vite/src/generators/vitest/vitest.spec.ts @@ -17,7 +17,7 @@ describe('vitest generator', () => { const options: VitestGeneratorSchema = { project: 'my-test-react-app', uiFramework: 'react', - coverageProvider: 'c8', + coverageProvider: 'v8', }; beforeEach(() => { diff --git a/packages/vite/src/utils/versions.ts b/packages/vite/src/utils/versions.ts index ab7f9a103e3d0..25d5d84822afc 100644 --- a/packages/vite/src/utils/versions.ts +++ b/packages/vite/src/utils/versions.ts @@ -10,6 +10,5 @@ export const happyDomVersion = '~9.20.3'; export const edgeRuntimeVmVersion = '~3.0.2'; // Coverage providers -export const vitestCoverageC8Version = '~0.32.0'; export const vitestCoverageV8Version = '~0.32.0'; export const vitestCoverageIstanbulVersion = '~0.32.0'; diff --git a/packages/vue/src/generators/library/__snapshots__/library.spec.ts.snap b/packages/vue/src/generators/library/__snapshots__/library.spec.ts.snap index 0a1fb80a1a794..1caa8648811ee 100644 --- a/packages/vue/src/generators/library/__snapshots__/library.spec.ts.snap +++ b/packages/vue/src/generators/library/__snapshots__/library.spec.ts.snap @@ -101,7 +101,7 @@ exports[`lib should add vue, vite and vitest to package.json 1`] = ` "@typescript-eslint/eslint-plugin": "^6.9.1", "@typescript-eslint/parser": "^6.9.1", "@vitejs/plugin-vue": "^4.3.1", - "@vitest/coverage-c8": "~0.32.0", + "@vitest/coverage-v8": "~0.32.0", "@vitest/ui": "~0.32.0", "@vue/eslint-config-prettier": "7.1.0", "@vue/eslint-config-typescript": "^11.0.3", diff --git a/packages/vue/src/generators/library/lib/add-vite.ts b/packages/vue/src/generators/library/lib/add-vite.ts index f0eea26c33205..3a5cba8e17966 100644 --- a/packages/vue/src/generators/library/lib/add-vite.ts +++ b/packages/vue/src/generators/library/lib/add-vite.ts @@ -53,7 +53,7 @@ export async function addVite( const vitestTask = await vitestGenerator(tree, { uiFramework: 'none', project: options.name, - coverageProvider: 'c8', + coverageProvider: 'v8', inSourceTests: options.inSourceTests, skipFormat: true, testEnvironment: 'jsdom', diff --git a/packages/web/src/generators/application/application.ts b/packages/web/src/generators/application/application.ts index df6840adb06df..811ae54dc9c07 100644 --- a/packages/web/src/generators/application/application.ts +++ b/packages/web/src/generators/application/application.ts @@ -238,7 +238,7 @@ export async function applicationGeneratorInternal(host: Tree, schema: Schema) { const vitestTask = await vitestGenerator(host, { uiFramework: 'none', project: options.projectName, - coverageProvider: 'c8', + coverageProvider: 'v8', inSourceTests: options.inSourceTests, skipFormat: true, });