Skip to content

fix(vitest): strip non-serializable functions from inline diff config#10573

Merged
sheremet-va merged 2 commits into
vitest-dev:mainfrom
DucMinhNe:fix/serialize-diff-config-functions
Jun 12, 2026
Merged

fix(vitest): strip non-serializable functions from inline diff config#10573
sheremet-va merged 2 commits into
vitest-dev:mainfrom
DucMinhNe:fix/serialize-diff-config-functions

Conversation

@DucMinhNe

Copy link
Copy Markdown
Contributor

Description

Fixes #8663.

When test.diff is given as an inline object, it may contain color/compareKeys functions (the public DiffOptions type). serializeConfig forwarded that object to the worker pool verbatim:

// TODO: non serializable function?
diff: config.diff,

Because functions are not serializable across the worker boundary, every run with an inline diff object that includes a function crashed the worker before any test ran:

  • threads / vmThreadsDataCloneError on postMessage structured clone
  • forks / vmForks(s) => s could not be cloned on child_process IPC

The string (file-path) form was unaffected because only a string is serialized and the worker imports the module locally in loadDiffConfig.

Fix

Strip the object down to the serializable fields already declared by SerializedDiffOptions before sending it to workers. This honors the existing contract — SerializedDiffOptions deliberately omits every *Color/compareKeys function field — and loadDiffConfig already accepts an object diff and uses it as-is. The function-based options continue to work via the file-path form, which the worker imports locally.

Tests

Added a regression test in test/e2e/test/reporters/custom-diff-config.test.ts that runs with an inline diff object containing both serializable annotations and a color function, across the forks and threads pools. It asserts the run no longer crashes with could not be cloned and that the serializable annotations are still applied.

Verified the test fails without the fix (both pools throw could not be cloned) and passes with it.

An inline `test.diff` object can carry color/compareKeys functions
(`DiffOptions`). `serializeConfig` forwarded the raw object to the worker
pool, so the config failed to cross the worker boundary: the `threads`
pool threw `DataCloneError` on structured clone and the `forks` pool threw
on `child_process` IPC serialization. Every run with an inline diff object
that included a color function crashed the worker.

Forward only the serializable fields declared by `SerializedDiffOptions`,
matching the existing contract (the file-path form still imports the
function-based options locally in the worker).

Fixes vitest-dev#8663
The previous commit returned every SerializedDiffOptions field, so unset
options became explicit `undefined` values that clobbered the diff defaults
when the worker merged the options — breaking inline options like
`{ expand: true }` and `{ printBasicPrototype: true }` (caught by
test/diff.test.ts in CI). Copy only the keys that are actually set.
@netlify

netlify Bot commented Jun 12, 2026

Copy link
Copy Markdown

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 534e99b
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6a2bdaa58b3ffd0008cd30bb
😎 Deploy Preview https://deploy-preview-10573--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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

@DucMinhNe

Copy link
Copy Markdown
Contributor Author

CI status after 534e99b: all Build&Test and Cache&Test jobs are green — the earlier test/diff.test.ts snapshot failures are fixed (the first commit forwarded unset diff options as explicit undefined, clobbering defaults on merge; now only set keys are forwarded).

The remaining red jobs are the timing-sensitive hooks-timeout.test.ts browser suite and test/watch/reporter-failed.test.ts, which don't touch the diff-config path and are also failing intermittently on main (e.g. runs on 4087802, 13b78d9).

@sheremet-va
sheremet-va merged commit 5b81a63 into vitest-dev:main Jun 12, 2026
15 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

config test.diff don't work correctly with raw config

2 participants