Skip to content

Commit

Permalink
fix(coverage): exclude browser mode iframe results (#6905)
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio authored Nov 18, 2024
1 parent 338d955 commit e04a136
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 deletions.
8 changes: 8 additions & 0 deletions packages/coverage-v8/src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,13 @@ function filterResult(coverage: ScriptCoverage['result'][number]): boolean {
return false
}

if (coverage.url === window.location.href) {
return false
}

if (coverage.url.includes('?browserv=') || coverage.url.includes('&browserv=')) {
return false
}

return true
}
2 changes: 1 addition & 1 deletion test/coverage-test/test/bundled-sources.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test('bundled code with source maps to originals', async () => {
expect(files.find(file => file.includes('bundle.ts'))).toBeFalsy()
expect(files.find(file => file.includes('bundle.d.ts'))).toBeFalsy()

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

coverageTest('run bundled sources', () => {
Expand Down
10 changes: 3 additions & 7 deletions test/coverage-test/test/include-exclude.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { expect } from 'vitest'
import { coverageConfigDefaults } from 'vitest/config'
import { coverageTest, normalizeURL, readCoverageMap, runVitest, test } from '../utils'
import { readCoverageMap, runVitest, test } from '../utils'

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

test('overriden exclude should not apply defaults', async () => {
await runVitest({
include: [normalizeURL(import.meta.url)],
include: ['fixtures/test/math.test.ts'],
coverage: {
all: true,
reporter: 'json',
Expand Down Expand Up @@ -63,7 +63,3 @@ test('test files are not automatically excluded from report when excludes is set
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)
})
2 changes: 1 addition & 1 deletion test/coverage-test/test/pre-transpiled-source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ test('pre-transpiled code with source maps to original (#5341)', async () => {
expect(files.find(file => file.includes('transpiled.ts'))).toBeFalsy()
expect(files.find(file => file.includes('transpiled.d.ts'))).toBeFalsy()

expect(JSON.stringify(coverageJson, null, 2)).toMatchFileSnapshot(`__snapshots__/pre-transpiled-${isV8Provider() ? 'v8' : 'istanbul'}.snapshot.json`)
await expect(JSON.stringify(coverageJson, null, 2)).toMatchFileSnapshot(`__snapshots__/pre-transpiled-${isV8Provider() ? 'v8' : 'istanbul'}.snapshot.json`)
})
2 changes: 1 addition & 1 deletion test/coverage-test/test/results-snapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ test('coverage results matches snapshot', async () => {

const coverageJson = await readCoverageJson()

expect(JSON.stringify(coverageJson, null, 2)).toMatchFileSnapshot(`__snapshots__/results-${isV8Provider() ? 'v8' : 'istanbul'}.snapshot.json`)
await expect(JSON.stringify(coverageJson, null, 2)).toMatchFileSnapshot(`__snapshots__/results-${isV8Provider() ? 'v8' : 'istanbul'}.snapshot.json`)
})
2 changes: 2 additions & 0 deletions test/coverage-test/vitest.workspace.custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default defineWorkspace([
BROWSER_TESTS,

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

// Other non-provider-specific tests that should be run on browser mode as well
'**/include-exclude.test.ts',
'**/allow-external.test.ts',
'**/ignore-hints.test.ts',
'**/import-attributes.test.ts',
Expand Down

0 comments on commit e04a136

Please sign in to comment.