Skip to content

Commit

Permalink
fix(vite): vitest should use v8 as default
Browse files Browse the repository at this point in the history
c8 is deprecated
  • Loading branch information
mandarini committed Nov 10, 2023
1 parent 0af7ad4 commit 2e2ee7e
Show file tree
Hide file tree
Showing 16 changed files with 34 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docs/generated/packages/vite/generators/vitest.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"coverageProvider": {
"type": "string",
"enum": ["v8", "c8", "istanbul"],
"enum": ["v8", "istanbul", "custom"],
"default": "v8",
"description": "Coverage provider to use."
},
Expand Down
2 changes: 1 addition & 1 deletion e2e/vite/src/vite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/js/src/generators/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/generators/application/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/generators/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
14 changes: 14 additions & 0 deletions packages/vite/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
10 changes: 6 additions & 4 deletions packages/vite/src/executors/test/vitest.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/generators/vitest/schema.d.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/generators/vitest/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"coverageProvider": {
"type": "string",
"enum": ["v8", "c8", "istanbul"],
"enum": ["v8", "istanbul", "custom"],
"default": "v8",
"description": "Coverage provider to use."
},
Expand Down
5 changes: 2 additions & 3 deletions packages/vite/src/generators/vitest/vitest-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { VitestGeneratorSchema } from './schema';

import initGenerator from '../init/init';
import {
vitestCoverageC8Version,
vitestCoverageIstanbulVersion,
vitestCoverageV8Version,
} from '../../utils/versions';
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/generators/vitest/vitest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('vitest generator', () => {
const options: VitestGeneratorSchema = {
project: 'my-test-react-app',
uiFramework: 'react',
coverageProvider: 'c8',
coverageProvider: 'v8',
};

beforeEach(() => {
Expand Down
1 change: 0 additions & 1 deletion packages/vite/src/utils/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/src/generators/library/lib/add-vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/generators/application/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down

0 comments on commit 2e2ee7e

Please sign in to comment.