-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix: extraneous coverage for --project (fix #6331) #7885
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
Merged
AriPerkkio
merged 17 commits into
vitest-dev:main
from
energyworldnet:fix/project-filter-coverage
Jun 26, 2025
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
5716d0f
fix: extraneous coverage for --project (fix #6331)
gtbuchanan a02bd30
Filter out covered files
gtbuchanan f79d78f
Inline createTestExcludes function
gtbuchanan b6c42ff
Add workspace tests
gtbuchanan a1fc457
Revert "fix: extraneous coverage for --project (fix #6331)"
gtbuchanan f032d1f
Merge branch 'main' into fix/project-filter-coverage
gtbuchanan a12ca30
Migrate workspace test config to new style
gtbuchanan 38b255d
Fix workspace coverage include
gtbuchanan 098a9a4
Reapply fix
gtbuchanan 377a643
Localize project roots definition
gtbuchanan 0073c2d
Rename workspace test file
gtbuchanan 13cb63a
Add test case for shared ref
gtbuchanan ecb7978
Fix included external covered files
gtbuchanan bb4f9fb
Add clarifying comment about roots
gtbuchanan b6458af
Improve readability of included condition
gtbuchanan aad1474
Dedup project roots
gtbuchanan 11107dc
Merge branch 'main' into fix/project-filter-coverage
gtbuchanan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
26 changes: 26 additions & 0 deletions
26
test/coverage-test/fixtures/configs/vitest.config.workspace.ts
This file contains hidden or 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,26 @@ | ||
import { defineConfig } from "vitest/config"; | ||
|
||
export default defineConfig({ | ||
test: { | ||
projects: [ | ||
{ | ||
test: { | ||
name: "project1", | ||
root: "fixtures/workspaces/project/project1", | ||
}, | ||
}, | ||
{ | ||
test: { | ||
name: "project2", | ||
root: "fixtures/workspaces/project/project2", | ||
}, | ||
}, | ||
{ | ||
test: { | ||
name: 'project-shared', | ||
root: 'fixtures/workspaces/project/shared', | ||
} | ||
} | ||
] | ||
} | ||
}); |
4 changes: 4 additions & 0 deletions
4
test/coverage-test/fixtures/workspaces/project/project1/src/id.ts
This file contains hidden or 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,4 @@ | ||
import { raise } from "../../shared/src/utils" | ||
|
||
export const id = <T>(value: T) => | ||
value ?? raise("Value cannot be undefined") |
3 changes: 3 additions & 0 deletions
3
test/coverage-test/fixtures/workspaces/project/project1/src/untested.ts
This file contains hidden or 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,3 @@ | ||
export function untested() { | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
test/coverage-test/fixtures/workspaces/project/project1/test/id.test.ts
This file contains hidden or 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 { expect, test } from 'vitest'; | ||
import { id } from '../src/id'; | ||
|
||
test('returns identity value', () => { | ||
expect(id(1)).toBe(1); | ||
}) |
6 changes: 6 additions & 0 deletions
6
test/coverage-test/fixtures/workspaces/project/project2/src/konst.ts
This file contains hidden or 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 { raise } from "../../shared/src/utils" | ||
|
||
export const konst = <T>(value: T) => { | ||
value ??= raise("Value cannot be undefined") | ||
return () => value | ||
} |
3 changes: 3 additions & 0 deletions
3
test/coverage-test/fixtures/workspaces/project/project2/src/untested.ts
This file contains hidden or 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,3 @@ | ||
export function untested() { | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
test/coverage-test/fixtures/workspaces/project/project2/test/konst.test.ts
This file contains hidden or 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,8 @@ | ||
import { expect, test } from 'vitest' | ||
import { konst } from '../src/konst' | ||
|
||
test('returns function that returns constant value', () => { | ||
const fn = konst(1) | ||
|
||
expect(fn()).toBe(1); | ||
}) |
11 changes: 11 additions & 0 deletions
11
test/coverage-test/fixtures/workspaces/project/shared/src/utils.ts
This file contains hidden or 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,11 @@ | ||
function raise(error: string): never | ||
function raise(error: Error): never | ||
function raise(error: Error | string): never { | ||
if (typeof error === 'string') { | ||
throw new Error(error) | ||
} else { | ||
throw error | ||
} | ||
} | ||
|
||
export { raise } |
7 changes: 7 additions & 0 deletions
7
test/coverage-test/fixtures/workspaces/project/shared/test/utils.test.ts
This file contains hidden or 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,7 @@ | ||
import { expect, test } from 'vitest' | ||
import { raise } from '../src/utils' | ||
|
||
test('raise throws error', () => { | ||
const message = 'Value cannot be undefined' | ||
expect(() => raise(message)).toThrowError(message) | ||
}) |
This file contains hidden or 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,49 @@ | ||
import { expect } from 'vitest' | ||
import { readCoverageMap, runVitest, test } from '../utils' | ||
|
||
test('coverage files include all projects', async () => { | ||
await runVitest({ | ||
config: '../../configs/vitest.config.workspace.ts', | ||
coverage: { | ||
reporter: ['json', 'html'], | ||
include: ['**/src/**'], | ||
}, | ||
root: 'fixtures/workspaces/project', | ||
}) | ||
|
||
const coverageMap = await readCoverageMap('fixtures/workspaces/project/coverage/coverage-final.json') | ||
const files = coverageMap.files() | ||
|
||
// All files from workspace should be picked | ||
expect(files).toMatchInlineSnapshot(` | ||
[ | ||
"<process-cwd>/fixtures/workspaces/project/project1/src/id.ts", | ||
"<process-cwd>/fixtures/workspaces/project/project1/src/untested.ts", | ||
"<process-cwd>/fixtures/workspaces/project/project2/src/konst.ts", | ||
"<process-cwd>/fixtures/workspaces/project/project2/src/untested.ts", | ||
"<process-cwd>/fixtures/workspaces/project/shared/src/utils.ts", | ||
] | ||
`) | ||
}) | ||
|
||
test('coverage files limited to specified project', async () => { | ||
await runVitest({ | ||
config: '../../configs/vitest.config.workspace.ts', | ||
coverage: { | ||
reporter: ['json', 'html'], | ||
include: ['**/src/**'], | ||
}, | ||
project: 'project2', | ||
root: 'fixtures/workspaces/project', | ||
}) | ||
|
||
const coverageMap = await readCoverageMap('fixtures/workspaces/project/coverage/coverage-final.json') | ||
const files = coverageMap.files() | ||
|
||
expect(files).toMatchInlineSnapshot(` | ||
[ | ||
"<process-cwd>/fixtures/workspaces/project/project2/src/konst.ts", | ||
"<process-cwd>/fixtures/workspaces/project/project2/src/untested.ts", | ||
] | ||
`) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.