Skip to content

Commit fc77d4f

Browse files
authored
fix: support Deno 2.8 (#794)
* fix: support Deno 2.8 * fix: pass down `[]` * chore: fix legacy
1 parent 7d56e9d commit fc77d4f

10 files changed

Lines changed: 184 additions & 116 deletions

File tree

packages/extension/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@
99
"picomatch": "catalog:latest",
1010
"vitest": "catalog:v3",
1111
"vitest-vscode-shared": "workspace:*"
12+
},
13+
"devDependencies": {
14+
"flatted": "^3.4.2"
1215
}
1316
}

packages/extension/src/spawn/rpc.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { ExtensionWorkerEvents, ExtensionWorkerTransport } from 'vitest-vscode-shared'
22
import v8 from 'node:v8'
33
import { createBirpc } from 'birpc'
4+
import { log } from '../log'
45

56
export type {
67
ExtensionWorkerEvents,
@@ -64,6 +65,8 @@ export function createRpcOptions() {
6465
export function createVitestRpc(options: {
6566
on: (listener: (message: any) => void) => void
6667
send: (message: any) => void
68+
serialize?: (v: any) => any
69+
deserialize?: (v: any) => any
6770
}) {
6871
const { events, handlers } = createRpcOptions()
6972

@@ -76,8 +79,11 @@ export function createVitestRpc(options: {
7679
post(message) {
7780
options.send(message)
7881
},
79-
serialize: v8.serialize,
80-
deserialize: (v) => v8.deserialize(Buffer.from(v) as any),
82+
serialize: options.serialize ?? v8.serialize,
83+
deserialize: options.deserialize ?? ((v) => v8.deserialize(Buffer.from(v) as any)),
84+
onGeneralError(error) {
85+
log.error('RPC Error', error)
86+
},
8187
})
8288

8389
return {

packages/extension/src/spawn/ws.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
import { log } from '../log'
1919
import { createVitestRpc } from './rpc'
2020
import { resolve } from 'pathe'
21+
import { parse, stringify } from 'flatted'
2122

2223
export type WsConnectionMetadata = Omit<ResolvedMeta, 'process'> & {
2324
ws: WebSocket
@@ -83,6 +84,21 @@ export function onWsConnection(
8384
const { api, handlers } = createVitestRpc({
8485
on: (listener) => ws.on('message', listener),
8586
send: (message) => ws.send(message),
87+
serialize:
88+
pkg.runtime !== 'node'
89+
? (e) =>
90+
stringify(e, (_, v) => {
91+
if (v instanceof Error) {
92+
return {
93+
name: v.name,
94+
message: v.message,
95+
stack: v.stack,
96+
}
97+
}
98+
return v
99+
})
100+
: undefined,
101+
deserialize: pkg.runtime !== 'node' ? parse : undefined,
86102
})
87103
ws.once('close', () => {
88104
log.verbose?.('[API]', 'Vitest WebSocket connection closed, cannot call RPC anymore.')
@@ -153,6 +169,7 @@ export function onWsConnection(
153169
env: getConfig(pkg.folder).env || undefined,
154170
configFile: pkg.configFile,
155171
cwd: pkg.cwd,
172+
runtime: pkg.runtime,
156173
arguments: pkg.arguments,
157174
workspaceFile: pkg.workspaceFile,
158175
id: pkg.id,

packages/extension/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function formatPkg(pkg: VitestPackage) {
1717
}
1818

1919
function _showVitestError(message: string, error?: any) {
20-
if (error) log.error(error)
20+
if (error) log.error(error.stack || error)
2121

2222
vscode.window
2323
.showErrorMessage(`${message}. Check the output for more details.`, 'See error')

packages/extension/src/watcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { VitestProcessAPI } from './apiProcess'
22
import type { TransformSchemaProvider } from './schemaProvider'
33
import type { TestTree } from './testTree'
44
import { relative } from 'node:path'
5-
import { normalize, resolve } from 'pathe'
5+
import { normalize } from 'pathe'
66
import * as vscode from 'vscode'
77
import { getConfig } from './config'
88
import { log } from './log'

packages/extension/src/worker/index.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { pathToFileURL } from 'node:url'
44
import v8 from 'node:v8'
55
import { createWorkerRPC, normalizeDriveLetter, WorkerWSEventEmitter } from 'vitest-vscode-shared'
66
import { WebSocket } from 'ws'
7+
import { parse, stringify } from 'flatted'
78

89
// this is the file that will be executed with "node <path>"
910

@@ -53,8 +54,22 @@ emitter.on('message', async function onMessage(message: any) {
5354
post(message) {
5455
emitter.send(message)
5556
},
56-
serialize: v8.serialize,
57-
deserialize: (v) => v8.deserialize(Buffer.from(v) as any),
57+
serialize:
58+
data.meta.runtime !== 'node'
59+
? (e) =>
60+
stringify(e, (_, v) => {
61+
if (v instanceof Error) {
62+
return {
63+
name: v.name,
64+
message: v.message,
65+
stack: v.stack,
66+
}
67+
}
68+
return v
69+
})
70+
: v8.serialize,
71+
deserialize:
72+
data.meta.runtime !== 'node' ? parse : (v) => v8.deserialize(Buffer.from(v) as any),
5873
})
5974
worker.initRpc(rpc)
6075
reporter.initRpc(rpc)

packages/shared/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export interface WorkerInitMetadata {
143143
id: string
144144
cwd: string
145145
arguments?: string
146+
runtime: 'node' | 'deno'
146147
configFile?: string
147148
workspaceFile?: string
148149
env: Record<string, any> | undefined

packages/worker-legacy/src/worker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,9 @@ export class ExtensionWorker implements ExtensionWorkerTransport {
188188

189189
private async globTestSpecifications(filters?: string[]): Promise<TestSpecification[]> {
190190
if ('globTestSpecifications' in this.vitest) {
191-
return this.vitest.globTestSpecifications(filters)
191+
return this.vitest.globTestSpecifications(filters || [])
192192
}
193-
return await (this.vitest as any).globTestFiles(filters)
193+
return await (this.vitest as any).globTestFiles(filters || [])
194194
}
195195

196196
private invalidateTree(mod: any, seen = new Set()) {

packages/worker/src/runner.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ export class ExtensionWorkerRunner {
7373
}
7474

7575
if (!filesOrDirectories || this.isOnlyDirectories(filesOrDirectories)) {
76-
const specifications = await this.vitest.getRelevantTestSpecifications(filesOrDirectories)
76+
const specifications = await this.vitest.getRelevantTestSpecifications(
77+
filesOrDirectories || [],
78+
)
7779
await this.vitest.rerunTestSpecifications(specifications, true)
7880
} else {
7981
const specifications = await this.resolveTestSpecifications(filesOrDirectories)

0 commit comments

Comments
 (0)