-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix(coverage): browser + v8 in source tests missing #7946
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,9 +71,5 @@ function filterResult(coverage: ScriptCoverage['result'][number]): boolean { | |
| return false | ||
| } | ||
|
|
||
| if (coverage.url.includes('?browserv=') || coverage.url.includes('&browserv=')) { | ||
| return false | ||
| } | ||
|
|
||
|
Comment on lines
-74
to
-77
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to check with Storybook folks to see that this doesn't break coverage reports there. This was used to exclude
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Storybook can now exclude story files inside the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, that works! Using this in fresh Storybook project fixes the issue: {
name: "exclude-stories",
configureVitest(context) {
if (context.vitest.config.coverage.enabled) {
context.vitest.config.coverage.exclude.push("**/*.stories.**");
}
},Related tests in #8009 |
||
| return true | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| /// <reference types="vitest/importMeta" /> | ||
|
|
||
| export function add(a: number, b: number) { | ||
| if(a === 5 && b === 7) { | ||
| return 12; | ||
| } | ||
|
|
||
| return a + b | ||
| } | ||
|
|
||
| if (import.meta.vitest) { | ||
| const { test, expect } = import.meta.vitest | ||
|
|
||
| test('in source test running add function', () => { | ||
| expect(add(10, 19)).toBe(29) | ||
| }) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { expect } from 'vitest' | ||
| import { isV8Provider, readCoverageMap, runVitest, test } from '../utils' | ||
|
|
||
| test('in-source tests work', async () => { | ||
| const { stdout } = await runVitest({ | ||
| include: [], | ||
| includeSource: ['fixtures/src/in-source.ts'], | ||
| coverage: { all: false, reporter: 'json' }, | ||
| }) | ||
|
|
||
| expect(stdout).toContain('in source test running add function') | ||
|
|
||
| const coverageMap = await readCoverageMap() | ||
| const files = coverageMap.files() | ||
|
|
||
| expect(files).toMatchInlineSnapshot(` | ||
| [ | ||
| "<process-cwd>/fixtures/src/in-source.ts", | ||
| ] | ||
| `) | ||
|
|
||
| const fileCoverage = coverageMap.fileCoverageFor('<process-cwd>/fixtures/src/in-source.ts') | ||
|
|
||
| // If-branch is not taken - makes sure source maps are correct in in-source testing too | ||
| expect(fileCoverage.getUncoveredLines()).toContain('5') | ||
|
|
||
| if (isV8Provider()) { | ||
| expect(fileCoverage).toMatchInlineSnapshot(` | ||
| { | ||
| "branches": "2/4 (50%)", | ||
| "functions": "1/1 (100%)", | ||
| "lines": "10/12 (83.33%)", | ||
| "statements": "10/12 (83.33%)", | ||
| } | ||
| `) | ||
| } | ||
| else { | ||
| expect(fileCoverage).toMatchInlineSnapshot(` | ||
| { | ||
| "branches": "3/6 (50%)", | ||
| "functions": "2/2 (100%)", | ||
| "lines": "6/7 (85.71%)", | ||
| "statements": "6/7 (85.71%)", | ||
| } | ||
| `) | ||
| } | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is needed so that
/Users/x/vitest/test/coverage-test/fixtures/src/in-source.ts?import&browserv=1747838764408is recognized as cached test file.