feat(vitest-pool-workers): add Istanbul coverage support#12590
Closed
TyposBro wants to merge 1 commit intocloudflare:mainfrom
Closed
feat(vitest-pool-workers): add Istanbul coverage support#12590TyposBro wants to merge 1 commit intocloudflare:mainfrom
TyposBro wants to merge 1 commit intocloudflare:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 9b91902 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
1d9eb45 to
8862a36
Compare
8862a36 to
ad2d307
Compare
When using @cloudflare/vitest-pool-workers with Istanbul coverage, coverage data is populated inside the workerd runtime but never bridges back to the Node.js process where Vitest's coverage provider reads it. This change adds: - Coverage data bridging from workerd to Node.js via the loopback service - Istanbul instrumentation for files loaded through the module fallback service (files not handled by Vite transforms) - Coverage data merging in the pool to handle parallel test execution The test runner collects globalThis.__VITEST_COVERAGE__ after tests complete and sends it to the pool's loopback handler, which merges it into the Node.js process. The module fallback service also instruments user source files with Istanbul when coverage is enabled, ensuring files loaded outside of Vite's transform pipeline are also covered. Closes #12589
ad2d307 to
9b91902
Compare
Author
|
Addressed latest review feedback in 9b91902:
Both fixes plus the earlier null-check and retry-prevention fixes are included in this commit. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds Istanbul code coverage support for
@cloudflare/vitest-pool-workers. Previously, running tests withcoverage.provider: 'istanbul'always reported 0% because coverage data populated inside the workerd runtime never bridged back to the Node.js process.Changes across 4 files (+163 lines):
src/pool/module-fallback.ts— Istanbul instrumentation for user source files loaded through the module fallback service (files not handled by Vite transforms). Uses dynamic import ofistanbul-lib-instrument(transitive dep of@vitest/coverage-istanbul).src/worker/lib/cloudflare/test-runner.ts— CollectsglobalThis.__VITEST_COVERAGE__after all test files complete and sends it to the pool via the loopback service.src/pool/loopback.ts— Handles/coveragePOST route. Merges incoming coverage data (statement, function, and branch counters) intoglobalThis.__VITEST_COVERAGE__on the Node.js side where Vitest's coverage provider reads it.src/pool/index.ts— Enables coverage instrumentation inexecuteMethod()whenctx.config.coverage.enabledis true.How it works
globalThis.__VITEST_COVERAGE__and POSTs it to the pool's loopback serviceTesting
Verified with a real project:
Test plan
Closes #12589