Skip to content

feat(coverage): v8 to track node:child_process and node:worker_threads contexts#9976

Open
AriPerkkio wants to merge 3 commits intovitest-dev:mainfrom
AriPerkkio:feat/coverage-process-thread-context
Open

feat(coverage): v8 to track node:child_process and node:worker_threads contexts#9976
AriPerkkio wants to merge 3 commits intovitest-dev:mainfrom
AriPerkkio:feat/coverage-process-thread-context

Conversation

@AriPerkkio
Copy link
Copy Markdown
Member

@AriPerkkio AriPerkkio commented Mar 26, 2026

Description

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Comment thread packages/coverage-v8/src/intercept-new-run-context.ts Outdated
@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 26, 2026

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 2e65953
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/69e85e5c22bd0c0008417486
😎 Deploy Preview https://deploy-preview-9976--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@AriPerkkio AriPerkkio force-pushed the feat/coverage-process-thread-context branch from 88a5c08 to fa35cd5 Compare March 26, 2026 13:49
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Mar 26, 2026

@vitest/browser

npm i https://pkg.pr.new/@vitest/browser@9976

@vitest/browser-playwright

npm i https://pkg.pr.new/@vitest/browser-playwright@9976

@vitest/browser-preview

npm i https://pkg.pr.new/@vitest/browser-preview@9976

@vitest/browser-webdriverio

npm i https://pkg.pr.new/@vitest/browser-webdriverio@9976

@vitest/coverage-istanbul

npm i https://pkg.pr.new/@vitest/coverage-istanbul@9976

@vitest/coverage-v8

npm i https://pkg.pr.new/@vitest/coverage-v8@9976

@vitest/expect

npm i https://pkg.pr.new/@vitest/expect@9976

@vitest/mocker

npm i https://pkg.pr.new/@vitest/mocker@9976

@vitest/pretty-format

npm i https://pkg.pr.new/@vitest/pretty-format@9976

@vitest/runner

npm i https://pkg.pr.new/@vitest/runner@9976

@vitest/snapshot

npm i https://pkg.pr.new/@vitest/snapshot@9976

@vitest/spy

npm i https://pkg.pr.new/@vitest/spy@9976

@vitest/ui

npm i https://pkg.pr.new/@vitest/ui@9976

@vitest/utils

npm i https://pkg.pr.new/@vitest/utils@9976

vitest

npm i https://pkg.pr.new/vitest@9976

@vitest/web-worker

npm i https://pkg.pr.new/@vitest/web-worker@9976

@vitest/ws-client

npm i https://pkg.pr.new/@vitest/ws-client@9976

commit: 2e65953

@AriPerkkio AriPerkkio force-pushed the feat/coverage-process-thread-context branch 3 times, most recently from fef5aec to 188a95f Compare March 31, 2026 18:35
@AriPerkkio AriPerkkio force-pushed the feat/coverage-process-thread-context branch 2 times, most recently from 70f7641 to 3d1dce2 Compare April 6, 2026 14:03
Comment thread test/coverage-test/test/extended-run-context.v8.test.ts Outdated
@AriPerkkio AriPerkkio force-pushed the feat/coverage-process-thread-context branch 3 times, most recently from ed25468 to 66e52a1 Compare April 6, 2026 19:31
Comment thread packages/coverage-v8/src/index.ts Outdated
@AriPerkkio AriPerkkio force-pushed the feat/coverage-process-thread-context branch 3 times, most recently from fb7116a to c0a7985 Compare April 12, 2026 09:55
Comment thread packages/coverage-v8/src/index.ts Outdated
import { loadProvider } from './load-provider'

const session = new inspector.Session()
let session: inspector.Session | null = null
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This used to create unused new Session() on main thread too, oops.

@AriPerkkio AriPerkkio force-pushed the feat/coverage-process-thread-context branch 3 times, most recently from b97e821 to 63acca7 Compare April 13, 2026 09:31
@AriPerkkio AriPerkkio marked this pull request as ready for review April 13, 2026 10:52
@AriPerkkio AriPerkkio force-pushed the feat/coverage-process-thread-context branch from 63acca7 to 92ab430 Compare April 13, 2026 10:55
Comment thread docs/config/coverage.md Outdated

Collect coverage only for files changed since a specified commit or branch. When set to `true`, it uses staged and unstaged changes.

## coverage.trackProcessAndWorker
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming this option is difficult. Right now it only covers node:child_process and node:worker_threads, but in future it's likely going to be used for web workers and similar on browser. @hi-ogawa & @sheremet-va - please propose better name here. 🙏

Internally this feature also uses term extendedContextCoverage. 🙃

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think worker really fits in here, both child process and a worker thread is a worker in my opinion, at least that's how we defined it for pools, maybe trackProcessAndThreads is more accurate.

I would vote for something like includeSubprocesses/instrumentSubprocesses - subprocess can refer to anything, not just a fork/thread/service worker

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In debugging world there is also --follow-forks mode (in C), in vscode it's autoAttachChildProcesses (although it also follows workers)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about autoAttachChildContext? Or autoAttachWorkers and imply Worker is processes too. 🤔

@AriPerkkio AriPerkkio requested review from hi-ogawa and sheremet-va and removed request for sheremet-va April 13, 2026 10:57
@AriPerkkio AriPerkkio requested a review from sheremet-va April 13, 2026 10:57
@AriPerkkio AriPerkkio force-pushed the feat/coverage-process-thread-context branch from 92ab430 to c1073e1 Compare April 20, 2026 10:05
@AriPerkkio AriPerkkio force-pushed the feat/coverage-process-thread-context branch from c1073e1 to 2eb5e8d Compare April 21, 2026 05:47
Comment thread docs/config/coverage.md Outdated
}

if (this.extendedContextCoverageDir) {
const filenames = await readdir(this.extendedContextCoverageDir)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This directory doesn't exist when there are no children spawned and this happens:

$ pnpm -C examples/basic test --coverage --coverage.autoAttachWorkers

> @vitest/example-test@ test /home/hiroshi/code/others/vitest-wt1/examples/basic
> vitest --coverage --coverage.autoAttachWorkers


 DEV  v4.1.4 /home/hiroshi/code/others/vitest-wt1/examples/basic
      Coverage enabled with v8

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Errors ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

Vitest caught 2 unhandled errors during the test run.
This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Test Run Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Error: ENOENT: no such file or directory, scandir '/home/hiroshi/code/others/vitest-wt1/examples/basic/coverage/tmp/af48afe8-e4b0-4810-b7b2-e6dbea470389'
 ❯ readdir node:internal/fs/promises:956:18
 ❯ Object.takeCoverage ../../packages/coverage-v8/dist/index.js:50:22
 ❯ TestRunner.testRunner.onAfterRunFiles ../../packages/vitest/dist/chunks/index.DtMvdosS.js:173:20
 ❯ startTests ../../packages/runner/dist/chunk-artifact.js:3281:3
 ❯ ../../packages/vitest/dist/chunks/base.DuCI8aBZ.js:90:5
 ❯ run ../../packages/vitest/dist/chunks/base.DuCI8aBZ.js:81:2
 ❯ runBaseTests ../../packages/vitest/dist/chunks/base.DuCI8aBZ.js:200:2
 ❯ executeTests ../../packages/vitest/dist/chunks/init-forks.UV3ZQGQH.js:29:4
 ❯ execute ../../packages/vitest/dist/chunks/init.D98-gwRW.js:158:3
 ❯ process.onMessage ../../packages/vitest/dist/chunks/init.D98-gwRW.js:287:14

}

if (this.extendedContextCoverageDir) {
const filenames = await readdir(this.extendedContextCoverageDir)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also does this ensure the coverage json emitted by children to be collected only once? Looks like multiple takeCoverage calls (maybe isolate false) can read the same json and sent as coverage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

coverage not collected from sub-propcesses result from child_process APIs

3 participants