Skip to content

Commit e04a136

Browse files
authored
fix(coverage): exclude browser mode iframe results (#6905)
1 parent 338d955 commit e04a136

6 files changed

+16
-10
lines changed

packages/coverage-v8/src/browser.ts

+8
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,13 @@ function filterResult(coverage: ScriptCoverage['result'][number]): boolean {
5959
return false
6060
}
6161

62+
if (coverage.url === window.location.href) {
63+
return false
64+
}
65+
66+
if (coverage.url.includes('?browserv=') || coverage.url.includes('&browserv=')) {
67+
return false
68+
}
69+
6270
return true
6371
}

test/coverage-test/test/bundled-sources.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ test('bundled code with source maps to originals', async () => {
2424
expect(files.find(file => file.includes('bundle.ts'))).toBeFalsy()
2525
expect(files.find(file => file.includes('bundle.d.ts'))).toBeFalsy()
2626

27-
expect(JSON.stringify(coverageJson, null, 2)).toMatchFileSnapshot(`__snapshots__/bundled-${isV8Provider() ? 'v8' : 'istanbul'}.snapshot.json`)
27+
await expect(JSON.stringify(coverageJson, null, 2)).toMatchFileSnapshot(`__snapshots__/bundled-${isV8Provider() ? 'v8' : 'istanbul'}.snapshot.json`)
2828
})
2929

3030
coverageTest('run bundled sources', () => {

test/coverage-test/test/include-exclude.test.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { expect } from 'vitest'
22
import { coverageConfigDefaults } from 'vitest/config'
3-
import { coverageTest, normalizeURL, readCoverageMap, runVitest, test } from '../utils'
3+
import { readCoverageMap, runVitest, test } from '../utils'
44

55
test('default exclude should ignore test files', async () => {
66
await runVitest({
7-
include: [normalizeURL(import.meta.url)],
7+
include: ['fixtures/test/math.test.ts'],
88
coverage: {
99
all: true,
1010
reporter: 'json',
@@ -18,7 +18,7 @@ test('default exclude should ignore test files', async () => {
1818

1919
test('overriden exclude should not apply defaults', async () => {
2020
await runVitest({
21-
include: [normalizeURL(import.meta.url)],
21+
include: ['fixtures/test/math.test.ts'],
2222
coverage: {
2323
all: true,
2424
reporter: 'json',
@@ -63,7 +63,3 @@ test('test files are not automatically excluded from report when excludes is set
6363
const files = coverageMap.files()
6464
expect(files).toContain('<process-cwd>/fixtures/src/test-that-looks-like-source-file.ts')
6565
})
66-
67-
coverageTest('dummy', () => {
68-
expect(1 + 1).toBe(2)
69-
})

test/coverage-test/test/pre-transpiled-source.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ test('pre-transpiled code with source maps to original (#5341)', async () => {
2222
expect(files.find(file => file.includes('transpiled.ts'))).toBeFalsy()
2323
expect(files.find(file => file.includes('transpiled.d.ts'))).toBeFalsy()
2424

25-
expect(JSON.stringify(coverageJson, null, 2)).toMatchFileSnapshot(`__snapshots__/pre-transpiled-${isV8Provider() ? 'v8' : 'istanbul'}.snapshot.json`)
25+
await expect(JSON.stringify(coverageJson, null, 2)).toMatchFileSnapshot(`__snapshots__/pre-transpiled-${isV8Provider() ? 'v8' : 'istanbul'}.snapshot.json`)
2626
})

test/coverage-test/test/results-snapshot.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ test('coverage results matches snapshot', async () => {
1616

1717
const coverageJson = await readCoverageJson()
1818

19-
expect(JSON.stringify(coverageJson, null, 2)).toMatchFileSnapshot(`__snapshots__/results-${isV8Provider() ? 'v8' : 'istanbul'}.snapshot.json`)
19+
await expect(JSON.stringify(coverageJson, null, 2)).toMatchFileSnapshot(`__snapshots__/results-${isV8Provider() ? 'v8' : 'istanbul'}.snapshot.json`)
2020
})

test/coverage-test/vitest.workspace.custom.ts

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export default defineWorkspace([
6666
BROWSER_TESTS,
6767

6868
// Other non-provider-specific tests that should be run on browser mode as well
69+
'**/include-exclude.test.ts',
6970
'**/allow-external.test.ts',
7071
'**/ignore-hints.test.ts',
7172
'**/import-attributes.test.ts',
@@ -89,6 +90,7 @@ export default defineWorkspace([
8990
BROWSER_TESTS,
9091

9192
// Other non-provider-specific tests that should be run on browser mode as well
93+
'**/include-exclude.test.ts',
9294
'**/allow-external.test.ts',
9395
'**/ignore-hints.test.ts',
9496
'**/import-attributes.test.ts',

0 commit comments

Comments
 (0)