Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/advanced/metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Vitest uses different methods to communicate with the Node.js process.

- If Vitest runs tests inside worker threads, it will send data via [message port](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort)
- If Vitest uses child process, the data will be send as a serialized Buffer via [`process.send`](https://nodejs.org/api/process.html#processsendmessage-sendhandle-options-callback) API
- If Vitest runs tests in the browser, the data will be stringified using [flatted](https://www.npmjs.com/package/flatted) package
- If Vitest runs tests in the browser, the data will be stringified using [@ungap/structured-clone](https://www.npmjs.com/package/@ungap/structured-clone) package

This property is also present on every test in the `json` reporter, so make sure that data can be serialized into JSON.

Expand Down
2 changes: 1 addition & 1 deletion docs/advanced/pool.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ To communicate between different processes, you can create methods object using

```ts
import { createBirpc } from 'birpc'
import { parse, stringify } from 'flatted'
import { parse, stringify } from '@ungap/structured-clone/json'
import { createMethodsRPC, TestProject } from 'vitest/node'

function createRpc(project: TestProject, wss: WebSocketServer) {
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@
"@testing-library/user-event": "^14.6.1",
"@types/pngjs": "^6.0.5",
"@types/ws": "catalog:",
"@ungap/structured-clone": "catalog:",
"@vitest/runner": "workspace:*",
"birpc": "catalog:",
"flatted": "catalog:",
"ivya": "^1.7.0",
"mime": "^4.1.0",
"pathe": "catalog:",
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import type { BirpcReturn } from 'birpc'
import type { WebSocketBrowserEvents, WebSocketBrowserHandlers } from '../types'
import type { IframeOrchestrator } from './orchestrator'
import { parse, stringify } from '@ungap/structured-clone/json'

Check failure on line 6 in packages/browser/src/client/client.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Could not find a declaration file for module '@ungap/structured-clone/json'. '/home/runner/work/vitest/vitest/node_modules/.pnpm/@ungap+structured-clone@1.3.0/node_modules/@ungap/structured-clone/esm/json.js' implicitly has an 'any' type.
import { createBirpc } from 'birpc'
import { parse, stringify } from 'flatted'
import { getBrowserState } from './utils'

const PAGE_TYPE = getBrowserState().type
Expand Down Expand Up @@ -110,7 +110,7 @@
post: msg => ctx.ws.send(msg),
on: fn => (onMessage = fn),
serialize: e =>
stringify(e, (_, v) => {

Check failure on line 113 in packages/browser/src/client/client.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Parameter 'v' implicitly has an 'any' type.

Check failure on line 113 in packages/browser/src/client/client.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Parameter '_' implicitly has an 'any' type.
if (v instanceof Error) {
return {
name: v.name,
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/client/tester/tester.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { BrowserRPC, IframeChannelEvent } from '@vitest/browser/client'
import { parse } from '@ungap/structured-clone/json'

Check failure on line 2 in packages/browser/src/client/tester/tester.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Could not find a declaration file for module '@ungap/structured-clone/json'. '/home/runner/work/vitest/vitest/node_modules/.pnpm/@ungap+structured-clone@1.3.0/node_modules/@ungap/structured-clone/esm/json.js' implicitly has an 'any' type.
import { channel, client, onCancel } from '@vitest/browser/client'
import { parse } from 'flatted'
import { page, server, userEvent } from 'vitest/browser'
import {
collectTests,
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/node/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import type { ParentBrowserProject } from './projectParent'
import type { BrowserServerState } from './state'
import { existsSync, promises as fs } from 'node:fs'
import { parse, stringify } from '@ungap/structured-clone/json'

Check failure on line 10 in packages/browser/src/node/rpc.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Could not find a declaration file for module '@ungap/structured-clone/json'. '/home/runner/work/vitest/vitest/node_modules/.pnpm/@ungap+structured-clone@1.3.0/node_modules/@ungap/structured-clone/esm/json.js' implicitly has an 'any' type.
import { AutomockedModule, AutospiedModule, ManualMockedModule, RedirectedModule } from '@vitest/mocker'
import { ServerMockResolver } from '@vitest/mocker/node'
import { createBirpc } from 'birpc'
import { parse, stringify } from 'flatted'
import { dirname, join } from 'pathe'
import { createDebugger, isFileServingAllowed, isValidApiRequest } from 'vitest/node'
import { WebSocketServer } from 'ws'
Expand Down Expand Up @@ -369,7 +369,7 @@

/**
* Replacer function for serialization methods such as JS.stringify() or
* flatted.stringify().
* flatted.stringify(). // here
Comment on lines 371 to +372
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure how to write that comment correctly because the name of dep is more complicated now

*/
export function stringifyReplace(key: string, value: any): any {
if (value instanceof Error) {
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/node/serverOrchestrator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { IncomingMessage, ServerResponse } from 'node:http'
import type { ProjectBrowser } from './project'
import type { ParentBrowserProject } from './projectParent'
import { stringify } from 'flatted'
import { stringify } from '@ungap/structured-clone/json'

Check failure on line 4 in packages/browser/src/node/serverOrchestrator.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Could not find a declaration file for module '@ungap/structured-clone/json'. '/home/runner/work/vitest/vitest/node_modules/.pnpm/@ungap+structured-clone@1.3.0/node_modules/@ungap/structured-clone/esm/json.js' implicitly has an 'any' type.
import { replacer } from './utils'

export async function resolveOrchestrator(
Expand Down
6 changes: 1 addition & 5 deletions packages/ui/client/components/FileDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import type { RunnerTask, RunnerTestCase } from 'vitest'
import type { ModuleGraph } from '~/composables/module-graph'
import type { Params } from '~/composables/params'
import { toJSON } from 'flatted'
import {
browserState,
client,
Expand Down Expand Up @@ -107,10 +106,7 @@ async function loadModuleGraph(force = false) {
if (hideNodeModules.value) {
// when using static html reporter, we've the meta as global, we need to clone it
if (isReport) {
moduleGraph
= typeof window.structuredClone !== 'undefined'
? window.structuredClone(moduleGraph)
: toJSON(moduleGraph)
Comment on lines -110 to -113
Copy link
Contributor Author

@7rulnik 7rulnik Oct 13, 2025

Choose a reason for hiding this comment

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

As I understood toJSON was used as polyfiil. Should we keep it?

structuredClone available in all major browsers for 3 years already https://caniuse.com/wf-structured-clone

moduleGraph = window.structuredClone(moduleGraph)
}
moduleGraph.inlined = moduleGraph.inlined.filter(
n => !nodeModuleRegex.test(n),
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/client/composables/client/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
WebSocketEvents,
WebSocketHandlers,
} from 'vitest'
import { parse } from '@ungap/structured-clone/json'

Check failure on line 10 in packages/ui/client/composables/client/static.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Could not find a declaration file for module '@ungap/structured-clone/json'. '/home/runner/work/vitest/vitest/node_modules/.pnpm/@ungap+structured-clone@1.3.0/node_modules/@ungap/structured-clone/esm/json.js' implicitly has an 'any' type.
import { decompressSync, strFromU8 } from 'fflate'
import { parse } from 'flatted'
import { StateManager } from '../../../../ws-client/src/state'

interface HTMLReportMetadata {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/node/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { fileURLToPath } from 'node:url'
import { promisify } from 'node:util'
import { gzip, constants as zlibConstants } from 'node:zlib'
import { stringify } from 'flatted'
import { stringify } from '@ungap/structured-clone/json'

Check failure on line 11 in packages/ui/node/reporter.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Could not find a declaration file for module '@ungap/structured-clone/json'. '/home/runner/work/vitest/vitest/node_modules/.pnpm/@ungap+structured-clone@1.3.0/node_modules/@ungap/structured-clone/esm/json.js' implicitly has an 'any' type.
import mime from 'mime/lite'
import { dirname, extname, relative, resolve } from 'pathe'
import { globSync } from 'tinyglobby'
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
"vitest": "workspace:*"
},
"dependencies": {
"@ungap/structured-clone": "catalog:",
"@vitest/utils": "workspace:*",
"fflate": "^0.8.2",
"flatted": "catalog:",
"pathe": "catalog:",
"sirv": "catalog:",
"tinyglobby": "catalog:",
Expand Down
46 changes: 23 additions & 23 deletions packages/vitest/LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,29 @@ Repository: git+https://github.com/sinonjs/fake-timers.git

---------------------------------------

## @ungap/structured-clone
License: ISC
By: Andrea Giammarchi
Repository: git+https://github.com/ungap/structured-clone.git

> ISC License
>
> Copyright (c) 2021, Andrea Giammarchi, @WebReflection
>
> Permission to use, copy, modify, and/or distribute this software for any
> purpose with or without fee is hereby granted, provided that the above
> copyright notice and this permission notice appear in all copies.
>
> THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
> REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
> AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
> INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
> LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
> OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
> PERFORMANCE OF THIS SOFTWARE.

---------------------------------------

## acorn-walk
License: MIT
By: Marijn Haverbeke, Ingvar Stepanyan, Adrian Heine
Expand Down Expand Up @@ -297,29 +320,6 @@ Repository: lukeed/empathic

---------------------------------------

## flatted
License: ISC
By: Andrea Giammarchi
Repository: git+https://github.com/WebReflection/flatted.git

> ISC License
>
> Copyright (c) 2018-2020, Andrea Giammarchi, @WebReflection
>
> Permission to use, copy, modify, and/or distribute this software for any
> purpose with or without fee is hereby granted, provided that the above
> copyright notice and this permission notice appear in all copies.
>
> THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
> REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
> AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
> INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
> LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
> OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
> PERFORMANCE OF THIS SOFTWARE.

---------------------------------------

## js-tokens
License: MIT
By: Simon Lydell
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,11 @@
"@types/picomatch": "^4.0.2",
"@types/prompts": "^2.4.9",
"@types/sinonjs__fake-timers": "^8.1.5",
"@ungap/structured-clone": "catalog:",
"acorn-walk": "catalog:",
"birpc": "catalog:",
"cac": "catalog:",
"empathic": "^2.0.0",
"flatted": "catalog:",
"happy-dom": "^20.0.0",
"jsdom": "^26.1.0",
"local-pkg": "^1.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/api/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
WebSocketRPC,
} from './types'
import { existsSync, promises as fs } from 'node:fs'
import { parse, stringify } from '@ungap/structured-clone/json'

Check failure on line 18 in packages/vitest/src/api/setup.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Could not find a declaration file for module '@ungap/structured-clone/json'. '/home/runner/work/vitest/vitest/node_modules/.pnpm/@ungap+structured-clone@1.3.0/node_modules/@ungap/structured-clone/esm/json.js' implicitly has an 'any' type.
import { noop } from '@vitest/utils/helpers'
import { createBirpc } from 'birpc'
import { parse, stringify } from 'flatted'
import { WebSocketServer } from 'ws'
import { API_PATH } from '../constants'
import { getModuleGraph } from '../utils/graph'
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/pools/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import type { BrowserProvider } from '../types/browser'
import crypto from 'node:crypto'
import * as nodeos from 'node:os'
import { stringify } from '@ungap/structured-clone/json'

Check failure on line 9 in packages/vitest/src/node/pools/browser.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Could not find a declaration file for module '@ungap/structured-clone/json'. '/home/runner/work/vitest/vitest/node_modules/.pnpm/@ungap+structured-clone@1.3.0/node_modules/@ungap/structured-clone/esm/json.js' implicitly has an 'any' type.
import { createDefer } from '@vitest/utils/helpers'
import { stringify } from 'flatted'
import { createDebugger } from '../../utils/debugger'

const debug = createDebugger('vitest:browser:pool')
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/reporters/blob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { Reporter } from '../types/reporter'
import type { TestModule } from './reported-tasks'
import { existsSync } from 'node:fs'
import { mkdir, readdir, readFile, stat, writeFile } from 'node:fs/promises'
import { parse, stringify } from 'flatted'
import { parse, stringify } from '@ungap/structured-clone/json'
import { dirname, resolve } from 'pathe'
import { getOutputFile } from '../../utils/config-helpers'

Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/utils/serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function cloneByOwnProperties(value: any) {

/**
* Replacer function for serialization methods such as JS.stringify() or
* flatted.stringify().
* flatted.stringify(). //here
Comment on lines 16 to +17
Copy link
Contributor Author

Choose a reason for hiding this comment

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

*/
export function stringifyReplace(key: string, value: any): any {
if (value instanceof Error) {
Expand Down
2 changes: 1 addition & 1 deletion packages/ws-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@ungap/structured-clone": "catalog:",
"birpc": "catalog:",
"flatted": "catalog:",
"ws": "catalog:"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/ws-client/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { BirpcOptions, BirpcReturn } from 'birpc'
// eslint-disable-next-line no-restricted-imports
import type { WebSocketEvents, WebSocketHandlers } from 'vitest'
import { createBirpc } from 'birpc'
import { parse, stringify } from '@ungap/structured-clone/json'

import { parse, stringify } from 'flatted'
import { createBirpc } from 'birpc'
import { StateManager } from './state'

export * from '@vitest/runner/utils'
Expand Down
36 changes: 18 additions & 18 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ catalog:
'@types/istanbul-reports': ^3.0.4
'@types/test-exclude': ^6.0.2
'@types/ws': ^8.18.1
'@ungap/structured-clone': ^1.3.0
'@unocss/reset': ^66.5.1
'@vitejs/plugin-vue': ^6.0.1
'@vueuse/core': ^12.8.2
Expand All @@ -27,7 +28,6 @@ catalog:
cac: ^6.7.14
chai: ^6.0.1
debug: ^4.4.3
flatted: ^3.3.3
istanbul-lib-coverage: ^3.2.2
istanbul-lib-report: ^3.0.1
istanbul-lib-source-maps: ^5.0.6
Expand Down
2 changes: 1 addition & 1 deletion test/reporters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"test": "vitest"
},
"devDependencies": {
"@ungap/structured-clone": "^1.3.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should it be?

Suggested change
"@ungap/structured-clone": "^1.3.0",
"@ungap/structured-clone": "catalog:",

Copy link
Member

Choose a reason for hiding this comment

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

Yes, let's have it in the catalog file since it's used everywhere

"@vitest/runner": "workspace:*",
"flatted": "^3.3.3",
"pkg-reporter": "./reportPkg/",
"vitest": "workspace:*",
"vitest-sonar-reporter": "0.5.0"
Expand Down
Loading
Loading