Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions packages/extension/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,13 @@ async function createVitestProcessAPI(
pkg: VitestPackage,
): Promise<DiscoveryResult> {
return withProcess(pkg, async (meta) => {
meta.projects.forEach((project) => {
meta.config.projects.forEach((project) => {
if (project.config) {
usedConfigs.add(project.config)
}
})
const files = await meta.rpc.getFiles()
const config = new VitestProjectConfig(pkg, meta.projects, meta.workspaceSource)
const config = new VitestProjectConfig(pkg, meta.config)
const api = new VitestProcessAPI(config)
return { api, files }
})
Expand Down
18 changes: 12 additions & 6 deletions packages/extension/src/apiProcess.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SerializedProject } from 'vitest-vscode-shared'
import type { ExtensionWorkerConfig, SerializedProject } from 'vitest-vscode-shared'
import type { VitestPackage } from './spawn/pkg'
import { usesJestTestNamePattern } from './spawn/pkg'
import type { ExtensionWorkerEvents, VitestExtensionRPC } from './spawn/rpc'
Expand All @@ -22,8 +22,7 @@ export class VitestProjectConfig {

constructor(
readonly pkg: VitestPackage,
readonly projects: SerializedProject[],
readonly workspaceSource: string | false,
readonly extensionConfig: ExtensionWorkerConfig,

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.

This doesn’t seem like the right name. Extension config is something that configures the extension

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Naming is hard. What I ended up is metadata: WorkerReadyMetadata. Now we have to live with meta.metadata in some places.

) {
this.id = normalize(pkg.id)
this.workspaceFolder = pkg.folder
Expand All @@ -42,6 +41,14 @@ export class VitestProjectConfig {
return this.projects.map((p) => p.config).filter((n) => n != null)
}

get projects(): SerializedProject[] {
return this.extensionConfig.projects
}

get workspaceSource() {
return this.extensionConfig.workspaceSource
}

get version() {
return this.pkg.version
}
Expand Down Expand Up @@ -111,7 +118,7 @@ export class VitestProcessAPI {
* a handle wrapping the existing process (without closing it).
*/
static forDebug(pkg: VitestPackage, meta: ResolvedMeta): VitestProcessAPI {
const config = new VitestProjectConfig(pkg, meta.projects, meta.workspaceSource)
const config = new VitestProjectConfig(pkg, meta.config)
const api = new VitestProcessAPI(config)
api.currentMeta = meta
return api
Expand Down Expand Up @@ -321,10 +328,9 @@ export interface RunHandlers {

export interface ResolvedMeta {
rpc: VitestExtensionRPC
config: ExtensionWorkerConfig
process: ExtensionWorkerProcess
workspaceSource: string | false
pkg: VitestPackage
projects: SerializedProject[]
handlers: {
onProcessLog: (listener: ExtensionWorkerEvents['onProcessLog']) => void
onConsoleLog: (listener: ExtensionWorkerEvents['onConsoleLog']) => void
Expand Down
3 changes: 1 addition & 2 deletions packages/extension/src/spawn/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,10 @@ export async function createVitestTerminalProcess(
const vitestProcess = new ExtensionTerminalProcess(terminal, server, meta.ws)
return {
rpc: meta.rpc,
config: meta.config,
handlers: meta.handlers,
pkg,
workspaceSource: meta.workspaceSource,
process: vitestProcess,
projects: meta.projects,
dispose: meta.dispose,
}
}
Expand Down
16 changes: 9 additions & 7 deletions packages/extension/src/spawn/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,16 @@ export function onWsConnection(
}
onStart({
rpc: api,
workspaceSource: message.workspaceSource,
config: {
...message.config,
projects: message.config.projects.map((p) => {
if (p.dir) {
p.dir = resolve(pkg.cwd, p.dir)
}
return p
}),
},
handlers,
projects: message.projects.map((p) => {
if (p.dir) {
p.dir = resolve(pkg.cwd, p.dir)
}
return p
}),
ws,
pkg,
async dispose() {
Expand Down
4 changes: 2 additions & 2 deletions packages/extension/src/worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ emitter.on('message', async function onMessage(message: any) {
const workerPath = pathToFileURL(join(__dirname, workerName))
const initModule = await import(workerPath.toString())

const { createWorker, reporter, projects, workspaceSource } = await initModule.initVitest(
const { config, createWorker, reporter } = await initModule.initVitest(
vitestModule,
data,
emitter,
Expand Down Expand Up @@ -73,7 +73,7 @@ emitter.on('message', async function onMessage(message: any) {
})
worker.initRpc(rpc)
reporter.initRpc(rpc)
emitter.ready(projects, workspaceSource, isLegacy, vitestModule.version)
emitter.ready(config, isLegacy, vitestModule.version)

await worker.vitest.report('onInit', worker.vitest)
} catch (err: any) {
Expand Down
11 changes: 3 additions & 8 deletions packages/shared/src/emitter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SerializedProject, WorkerEvent } from 'vitest-vscode-shared'
import type { ExtensionWorkerConfig, WorkerEvent } from 'vitest-vscode-shared'
import type WebSocket from 'ws'

abstract class WorkerEventEmitter {
Expand All @@ -8,13 +8,8 @@ abstract class WorkerEventEmitter {
abstract on(event: string, listener: (...args: any[]) => void): void
abstract off(event: string, listener: (...args: any[]) => void): void

ready(
projects: SerializedProject[],
workspaceSource: string | false,
legacy: boolean,
version: string | undefined,
) {
this.sendWorkerEvent({ type: 'ready', projects, workspaceSource, legacy, version })
ready(config: ExtensionWorkerConfig, legacy: boolean, version: string | undefined) {
this.sendWorkerEvent({ type: 'ready', config, legacy, version })
}

error(err: any) {
Expand Down
8 changes: 6 additions & 2 deletions packages/shared/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,14 @@ export interface SerializedProject {
}
}

export interface EventReady {
type: 'ready'
export interface ExtensionWorkerConfig {
projects: SerializedProject[]
workspaceSource: string | false
}

export interface EventReady {
type: 'ready'
config: ExtensionWorkerConfig
legacy: boolean
// the actual runtime version, unlike VitestPackage.version
// this is also defined when vitest is resolved via yarn pnp
Expand Down
5 changes: 3 additions & 2 deletions packages/worker-legacy/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
ExtensionWorkerConfig,
SerializedProject,
WorkerRunnerOptions,
WorkerWSEventEmitter,
Expand Down Expand Up @@ -202,11 +203,11 @@ export async function initVitest(
: vitest.config.workspace != null || vitest.config.projects != null
? vitest.server.config.configFile || false
: false
const config: ExtensionWorkerConfig = { projects, workspaceSource }
return {
vitest,
reporter,
workspaceSource,
projects,
config,
meta,
createWorker() {
return new ExtensionWorker(vitest, !!data.debug, emitter)
Expand Down
5 changes: 3 additions & 2 deletions packages/worker/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
ExtensionWorkerConfig,
SerializedProject,
WorkerRunnerOptions,
WorkerWSEventEmitter,
Expand Down Expand Up @@ -167,11 +168,11 @@ export async function initVitest(

const workspaceSource: string | false =
vitest.config.projects != null ? vitest.vite.config.configFile || false : false
const config: ExtensionWorkerConfig = { projects, workspaceSource }
return {
vitest,
reporter,
workspaceSource,
projects,
config,
meta,
createWorker() {
return new ExtensionWorker(vitest, !!data.debug, emitter)
Expand Down
Loading