From e92fd06937be0aea00ac55301db518de5aa780fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Perkki=C3=B6?= Date: Mon, 22 Jul 2024 10:00:08 +0300 Subject: [PATCH] fix(coverage): ignore `*.cts` files --- docs/config/index.md | 2 +- docs/guide/cli-table.md | 2 +- packages/vitest/src/defaults.ts | 1 - packages/vitest/src/node/cli/cli-config.ts | 2 +- .../fixtures/src/should-be-excluded-by-default.cts | 7 +++++++ 5 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 test/coverage-test/fixtures/src/should-be-excluded-by-default.cts diff --git a/docs/config/index.md b/docs/config/index.md index a8c596c2f135..6f768ab4cf62 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -1103,7 +1103,7 @@ List of files included in coverage as glob patterns #### coverage.extension - **Type:** `string | string[]` -- **Default:** `['.js', '.cjs', '.mjs', '.ts', '.mts', '.cts', '.tsx', '.jsx', '.vue', '.svelte', '.marko']` +- **Default:** `['.js', '.cjs', '.mjs', '.ts', '.mts', '.tsx', '.jsx', '.vue', '.svelte', '.marko']` - **Available for providers:** `'v8' | 'istanbul'` - **CLI:** `--coverage.extension=`, `--coverage.extension= --coverage.extension=` diff --git a/docs/guide/cli-table.md b/docs/guide/cli-table.md index c343c3bb6250..1ffef7e1f322 100644 --- a/docs/guide/cli-table.md +++ b/docs/guide/cli-table.md @@ -20,7 +20,7 @@ | `--coverage.enabled` | Enables coverage collection. Can be overridden using the `--coverage` CLI option (default: `false`) | | `--coverage.include ` | Files included in coverage as glob patterns. May be specified more than once when using multiple patterns (default: `**`) | | `--coverage.exclude ` | Files to be excluded in coverage. May be specified more than once when using multiple extensions (default: Visit [`coverage.exclude`](https://vitest.dev/config/#coverage-exclude)) | -| `--coverage.extension ` | Extension to be included in coverage. May be specified more than once when using multiple extensions (default: `[".js", ".cjs", ".mjs", ".ts", ".mts", ".cts", ".tsx", ".jsx", ".vue", ".svelte"]`) | +| `--coverage.extension ` | Extension to be included in coverage. May be specified more than once when using multiple extensions (default: `[".js", ".cjs", ".mjs", ".ts", ".mts", ".tsx", ".jsx", ".vue", ".svelte"]`) | | `--coverage.clean` | Clean coverage results before running tests (default: true) | | `--coverage.cleanOnRerun` | Clean coverage report on watch rerun (default: true) | | `--coverage.reportsDirectory ` | Directory to write coverage report to (default: ./coverage) | diff --git a/packages/vitest/src/defaults.ts b/packages/vitest/src/defaults.ts index 4b1ade73230b..cd412103235e 100644 --- a/packages/vitest/src/defaults.ts +++ b/packages/vitest/src/defaults.ts @@ -68,7 +68,6 @@ export const coverageConfigDefaults: ResolvedCoverageOptions = { '.mjs', '.ts', '.mts', - '.cts', '.tsx', '.jsx', '.vue', diff --git a/packages/vitest/src/node/cli/cli-config.ts b/packages/vitest/src/node/cli/cli-config.ts index 02d3755ea40a..055a05387a15 100644 --- a/packages/vitest/src/node/cli/cli-config.ts +++ b/packages/vitest/src/node/cli/cli-config.ts @@ -203,7 +203,7 @@ export const cliOptionsConfig: VitestCLIOptions = { }, extension: { description: - 'Extension to be included in coverage. May be specified more than once when using multiple extensions (default: `[".js", ".cjs", ".mjs", ".ts", ".mts", ".cts", ".tsx", ".jsx", ".vue", ".svelte"]`)', + 'Extension to be included in coverage. May be specified more than once when using multiple extensions (default: `[".js", ".cjs", ".mjs", ".ts", ".mts", ".tsx", ".jsx", ".vue", ".svelte"]`)', argument: '', array: true, }, diff --git a/test/coverage-test/fixtures/src/should-be-excluded-by-default.cts b/test/coverage-test/fixtures/src/should-be-excluded-by-default.cts new file mode 100644 index 000000000000..8047d5ad4ce7 --- /dev/null +++ b/test/coverage-test/fixtures/src/should-be-excluded-by-default.cts @@ -0,0 +1,7 @@ +/* + * Vite does not transform `*.cts` files. + * If this file is picked by Istanbul provider, it will make Babel crash on TS syntax. + */ +interface Props { + name: string; +}