-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(coverage): support overriding
exclude
(#5997)
- Loading branch information
1 parent
2898a52
commit 169bc1f
Showing
8 changed files
with
102 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
test/coverage-test/fixtures/src/test-that-looks-like-source-file.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { test, expect } from 'vitest' | ||
import { sum } from "./math" | ||
|
||
test("run tests on file that looks like source file", () => { | ||
expect(sum(1,2)).toBe(3) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { expect } from 'vitest' | ||
import { coverageConfigDefaults } from 'vitest/config' | ||
import { coverageTest, normalizeURL, readCoverageMap, runVitest, test } from '../utils' | ||
|
||
test('default exclude should ignore test files', async () => { | ||
await runVitest({ | ||
include: [normalizeURL(import.meta.url)], | ||
coverage: { | ||
all: true, | ||
reporter: 'json', | ||
include: ['fixtures/test/math.test.ts'], | ||
}, | ||
}) | ||
|
||
const coverageMap = await readCoverageMap() | ||
expect(coverageMap.files()).toMatchInlineSnapshot(`[]`) | ||
}) | ||
|
||
test('overriden exclude should not apply defaults', async () => { | ||
await runVitest({ | ||
include: [normalizeURL(import.meta.url)], | ||
coverage: { | ||
all: true, | ||
reporter: 'json', | ||
include: ['fixtures/test/math.test.ts'], | ||
exclude: ['dont-match-anything'], | ||
}, | ||
}) | ||
|
||
const coverageMap = await readCoverageMap() | ||
expect(coverageMap.files()).toMatchInlineSnapshot(` | ||
[ | ||
"<process-cwd>/fixtures/test/math.test.ts", | ||
] | ||
`) | ||
}) | ||
|
||
test('test file is excluded from report when excludes is not set', async () => { | ||
await runVitest({ | ||
include: ['fixtures/src/test-that-looks-like-source-file.ts'], | ||
coverage: { | ||
all: true, | ||
reporter: 'json', | ||
}, | ||
}) | ||
|
||
const coverageMap = await readCoverageMap() | ||
const files = coverageMap.files() | ||
expect(files.find(file => file.includes('test-that-looks-like-source-file'))).toBeFalsy() | ||
}) | ||
|
||
test('test files are not automatically excluded from report when excludes is set', async () => { | ||
await runVitest({ | ||
include: ['fixtures/src/test-that-looks-like-source-file.ts'], | ||
coverage: { | ||
all: true, | ||
reporter: 'json', | ||
exclude: [...coverageConfigDefaults.exclude, '**/something-else/**'], | ||
}, | ||
}) | ||
|
||
const coverageMap = await readCoverageMap() | ||
const files = coverageMap.files() | ||
expect(files).toContain('<process-cwd>/fixtures/src/test-that-looks-like-source-file.ts') | ||
}) | ||
|
||
coverageTest('dummy', () => { | ||
expect(1 + 1).toBe(2) | ||
}) |