From aa84de339449a0ec210556ac960c17bea736f3a8 Mon Sep 17 00:00:00 2001 From: Aris Ripandi Date: Wed, 4 Sep 2024 20:51:59 +0700 Subject: [PATCH] fix: Vitest coverage configuration --- package.json | 2 +- pnpm-lock.yaml | 33 ++++++++++++++++++++------------- tests/setup-test.ts | 3 ++- vite.config.ts | 10 +++++++++- 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index e72063b..c6b751b 100644 --- a/package.json +++ b/package.json @@ -87,7 +87,7 @@ "@types/node": "^22.5.3", "@types/react-dom": "^18.3.0", "@types/react": "^18.3.5", - "@vitest/coverage-v8": "^2.0.5", + "@vitest/coverage-istanbul": "^2.0.5", "@vitest/ui": "^2.0.5", "autoprefixer": "^10.4.20", "dotenv-cli": "^7.4.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index aba6264..7a3d26c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -111,7 +111,7 @@ importers: '@types/react-dom': specifier: ^18.3.0 version: 18.3.0 - '@vitest/coverage-v8': + '@vitest/coverage-istanbul': specifier: ^2.0.5 version: 2.0.5(vitest@2.0.5(@types/node@22.5.3)(@vitest/ui@2.0.5)(happy-dom@15.7.3)) '@vitest/ui': @@ -811,9 +811,6 @@ packages: '@base2/pretty-print-object@1.0.1': resolution: {integrity: sha512-4iri8i1AqYHJE2DstZYkyEprg6Pq6sKx3xn5FpySk9sNhH7qN2LLlHJCfDTZRILNwQNPD7mATWM0TBui7uC1pA==} - '@bcoe/v8-coverage@0.2.3': - resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==} - '@biomejs/biome@1.8.3': resolution: {integrity: sha512-/uUV3MV+vyAczO+vKrPdOW0Iaet7UnJMU4bNMinggGJTAnBPjCoLEYcyYtYHNnUNYlv4xZMH6hVIQCAozq8d5w==} engines: {node: '>=14.21.3'} @@ -1845,8 +1842,8 @@ packages: '@vanilla-extract/private@1.0.6': resolution: {integrity: sha512-ytsG/JLweEjw7DBuZ/0JCN4WAQgM9erfSTdS1NQY778hFQSZ6cfCDEZZ0sgVm4k54uNz6ImKB33AYvSR//fjxw==} - '@vitest/coverage-v8@2.0.5': - resolution: {integrity: sha512-qeFcySCg5FLO2bHHSa0tAZAOnAUbp4L6/A5JDuj9+bt53JREl8hpLjLHEWF0e/gWc8INVpJaqA7+Ene2rclpZg==} + '@vitest/coverage-istanbul@2.0.5': + resolution: {integrity: sha512-BvjWKtp7fiMAeYUD0mO5cuADzn1gmjTm54jm5qUEnh/O08riczun8rI4EtQlg3bWoRo2lT3FO8DmjPDX9ZthPw==} peerDependencies: vitest: 2.0.5 @@ -3014,6 +3011,10 @@ packages: resolution: {integrity: sha512-O8dpsF+r0WV/8MNRKfnmrtCWhuKjxrq2w+jpzBL5UZKTi2LeVWnWOmWRxFlesJONmc+wLAGvKQZEOanko0LFTg==} engines: {node: '>=8'} + istanbul-lib-instrument@6.0.3: + resolution: {integrity: sha512-Vtgk7L/R2JHyyGW07spoFlB8/lpjiOLTjMdms6AFMraYt3BaJauod/NGrfnVG/y4Ix1JEuMRPDPEj2ua+zz1/Q==} + engines: {node: '>=10'} + istanbul-lib-report@3.0.1: resolution: {integrity: sha512-GCfE1mtsHGOELCU8e/Z7YWzpmybrx/+dSTfLrvY8qRmaY6zXTKWn6WQIjaAFw069icm6GVMNkgu0NzI4iPZUNw==} engines: {node: '>=10'} @@ -5681,8 +5682,6 @@ snapshots: '@base2/pretty-print-object@1.0.1': {} - '@bcoe/v8-coverage@0.2.3': {} - '@biomejs/biome@1.8.3': optionalDependencies: '@biomejs/cli-darwin-arm64': 1.8.3 @@ -6833,18 +6832,16 @@ snapshots: '@vanilla-extract/private@1.0.6': {} - '@vitest/coverage-v8@2.0.5(vitest@2.0.5(@types/node@22.5.3)(@vitest/ui@2.0.5)(happy-dom@15.7.3))': + '@vitest/coverage-istanbul@2.0.5(vitest@2.0.5(@types/node@22.5.3)(@vitest/ui@2.0.5)(happy-dom@15.7.3))': dependencies: - '@ampproject/remapping': 2.3.0 - '@bcoe/v8-coverage': 0.2.3 + '@istanbuljs/schema': 0.1.3 debug: 4.3.6 istanbul-lib-coverage: 3.2.2 + istanbul-lib-instrument: 6.0.3 istanbul-lib-report: 3.0.1 istanbul-lib-source-maps: 5.0.6 istanbul-reports: 3.1.7 - magic-string: 0.30.11 magicast: 0.3.5 - std-env: 3.7.0 test-exclude: 7.0.1 tinyrainbow: 1.2.0 vitest: 2.0.5(@types/node@22.5.3)(@vitest/ui@2.0.5)(happy-dom@15.7.3) @@ -8067,6 +8064,16 @@ snapshots: istanbul-lib-coverage@3.2.2: {} + istanbul-lib-instrument@6.0.3: + dependencies: + '@babel/core': 7.25.2 + '@babel/parser': 7.25.6 + '@istanbuljs/schema': 0.1.3 + istanbul-lib-coverage: 3.2.2 + semver: 7.6.3 + transitivePeerDependencies: + - supports-color + istanbul-lib-report@3.0.1: dependencies: istanbul-lib-coverage: 3.2.2 diff --git a/tests/setup-test.ts b/tests/setup-test.ts index d76facb..562b457 100644 --- a/tests/setup-test.ts +++ b/tests/setup-test.ts @@ -1,4 +1,5 @@ -// @reference: https://dev.to/codeparrot/test-your-react-apps-with-vitest-2llb +// @ref: https://dev.to/codeparrot/test-your-react-apps-with-vitest-2llb +// @ref: https://www.machinet.net/tutorial-eng/vitest-coverage-comprehensive-guide import { installGlobals } from '@remix-run/node' import '@testing-library/jest-dom/vitest' diff --git a/vite.config.ts b/vite.config.ts index 30d9f7d..aedf5d9 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -46,12 +46,20 @@ export default defineConfig({ html: './tests-results/index.html', }, coverage: { - provider: 'v8', + provider: 'istanbul', reporter: process.env.CI ? ['json'] : ['html-spa'], reportsDirectory: './tests-results/coverage', include: ['app/**/*.{js,jsx,ts,tsx}'], cleanOnRerun: true, clean: true, + thresholds: { + global: { + statements: 80, + branches: 70, + functions: 75, + lines: 80, + }, + }, }, dir: './tests', globals: true,