From b3327a64c97fbe9b15455fead987ede6ac7c0630 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Perkki=C3=B6?= Date: Sat, 4 Nov 2023 15:28:18 +0200 Subject: [PATCH] fix(coverage): exclude files and directories starting with dot by default (#4428) --- docs/config/index.md | 1 + packages/vitest/src/defaults.ts | 1 + .../coverage-report-tests/generic.report.test.ts | 5 +++++ .../excluded-from-coverage.ts | 5 +++++ 4 files changed, 12 insertions(+) create mode 100644 test/coverage-test/src/.should-be-excluded-from-coverage/excluded-from-coverage.ts diff --git a/docs/config/index.md b/docs/config/index.md index 6ee0d0dd38ca..42170d2c8275 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -1066,6 +1066,7 @@ List of files included in coverage as glob patterns [ 'coverage/**', 'dist/**', + '**/[.]**', 'packages/*/test?(s)/**', '**/*.d.ts', '**/virtual:*', diff --git a/packages/vitest/src/defaults.ts b/packages/vitest/src/defaults.ts index 0d44c755e05f..4cfbfc8027e9 100644 --- a/packages/vitest/src/defaults.ts +++ b/packages/vitest/src/defaults.ts @@ -13,6 +13,7 @@ export const benchmarkConfigDefaults: Required { const files = fs.readdirSync(coveragePath) expect(files).toContain('untested-file.ts.html') + + // Directories starting with dot should be excluded + expect(files).not.toContain('.should-be-excluded-from-coverage/excluded-from-coverage.ts.html') + expect(files).not.toContain('.should-be-excluded-from-coverage') + expect(files).not.toContain('excluded-from-coverage.ts.html') }) test('files should not contain query parameters', () => { diff --git a/test/coverage-test/src/.should-be-excluded-from-coverage/excluded-from-coverage.ts b/test/coverage-test/src/.should-be-excluded-from-coverage/excluded-from-coverage.ts new file mode 100644 index 000000000000..64bda3a2b8cb --- /dev/null +++ b/test/coverage-test/src/.should-be-excluded-from-coverage/excluded-from-coverage.ts @@ -0,0 +1,5 @@ +// This file should be excluded from coverage report + +export function uncoveredFile() { + return 0 +}