-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
feat: implement istanbul
coverage support for browser testing
#3040
Merged
sheremet-va
merged 24 commits into
vitest-dev:main
from
sheremet-va:feat/browser-coverage-support
Mar 28, 2023
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
0ef4875
feat: implement coverage support for browser testing
sheremet-va 56e2176
chore: remove query when instrumenting coverage
sheremet-va c885538
fix: colec and run only a single test at a time
sheremet-va a5e33ba
chore: use /@id/ for importing
sheremet-va 485f875
chore: cleanup
sheremet-va 9341732
chre: don't run coverage in browser tests bu default
sheremet-va e251be9
chore: don't run no-op coverage apis on browser
AriPerkkio 740cc82
test: browser with coverage
AriPerkkio 730bf08
fix: browser to preserve coverage ignore hints comments
AriPerkkio 17caf00
fix: browser plugin to resolve ids without query params
AriPerkkio 1f981ac
fix: browser to use unique query parameter
AriPerkkio 5bd1498
fix: throw error if c8 is used with --browser
AriPerkkio 40975d4
fix: throw error if c8 is used with browser via poolMatchGlobs
AriPerkkio c66bef0
chore: lockfile
sheremet-va 5ab4065
chore: add workaround for .mjs extension
sheremet-va 4718952
test: browser watch mode
AriPerkkio 7c0a961
fix: browser watch mode
AriPerkkio adfaea2
fix: browser with --root
AriPerkkio 27ae18e
chore: allow test.aliases in browser mode
sheremet-va 23b83ce
test: add test.alias to browser tests
sheremet-va af95db3
test: remove browser from global typechecking
sheremet-va b743282
test(watch): promise instead of polling
AriPerkkio 59e22ee
chore: cleanup browser runner test
sheremet-va 4473b2b
test: skip browser watch on windows
AriPerkkio File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
export * from './takeCoverage' | ||
import * as coverage from './takeCoverage' | ||
|
||
export async function getProvider() { | ||
const { C8CoverageProvider } = await import('./provider') | ||
return new C8CoverageProvider() | ||
export default { | ||
...coverage, | ||
async getProvider() { | ||
// to not bundle the provider | ||
AriPerkkio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const name = './provider.js' | ||
const { C8CoverageProvider } = await import(name) as typeof import('./provider') | ||
return new C8CoverageProvider() | ||
}, | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { startTests } from '@vitest/runner' | ||
export { setupCommonEnv } from './runtime/setup.common' | ||
export { setupSnapshotEnvironment } from './integrations/snapshot/env' | ||
export { takeCoverageInsideWorker, stopCoverageInsideWorker, getCoverageProvider, startCoverageInsideWorker } from './integrations/coverage' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
import type { Plugin as VitePlugin } from 'vite' | ||
import { normalizeRequestId } from 'vite-node/utils' | ||
|
||
import type { Vitest } from '../core' | ||
|
||
export function CoverageTransform(ctx: Vitest): VitePlugin | null { | ||
return { | ||
name: 'vitest:coverage-transform', | ||
transform(srcCode, id) { | ||
return ctx.coverageProvider?.onFileTransform?.(srcCode, id, this) | ||
return ctx.coverageProvider?.onFileTransform?.(srcCode, normalizeRequestId(id), this) | ||
}, | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
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 removal of named export
getProvider
caused a breaking change. The@vitest/coverage-istanbul
is still exporting it as both named and default. Was this intentional @sheremet-va?There are some reports where users are using different versions of
vitest
and@vitest/coverage-c8
and the API breaks: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.
Yeah, not intentional. Should've either not remove it or update
peerDependencies
. The next version is locked to be 0.30.0 though, so we will have to wait for a fix, but PR is welcome.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.
As a fix we can just bump the
peerDependency
version for0.30.0
release and it will prevent the usage of mixed versions. I'll set PR soon.I'm also thinking about a feature that would include the versions of
vitest
and@vitest/*
packages in the logs of unhandled crashes, like seen here on #3118 and here on #3125. It would help users to see that they are not using the latest versions when they think they are.