Skip to content

Commit 9175836

Browse files
authored
feat: add resolved project names to the reporter API (#7213)
1 parent b307055 commit 9175836

File tree

7 files changed

+22
-3
lines changed

7 files changed

+22
-3
lines changed

packages/ui/client/composables/client/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,11 @@ watch(
153153
ws.addEventListener('open', async () => {
154154
status.value = 'OPEN'
155155
client.state.filesMap.clear()
156-
let [files, _config, errors] = await Promise.all([
156+
let [files, _config, errors, projects] = await Promise.all([
157157
client.rpc.getFiles(),
158158
client.rpc.getConfig(),
159159
client.rpc.getUnhandledErrors(),
160+
client.rpc.getResolvedProjectNames(),
160161
])
161162
if (_config.standalone) {
162163
const filenames = await client.rpc.getTestFiles()
@@ -166,7 +167,7 @@ watch(
166167
return file
167168
})
168169
}
169-
explorerTree.loadFiles(files)
170+
explorerTree.loadFiles(files, projects)
170171
client.state.collectFiles(files)
171172
explorerTree.startRun()
172173
unhandledErrors.value = (errors || []).map(parseError)

packages/ui/client/composables/client/static.ts

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ interface HTMLReportMetadata {
1515
paths: string[]
1616
files: File[]
1717
config: SerializedConfig
18+
projects: string[]
1819
moduleGraph: Record<string, Record<string, ModuleGraphData>>
1920
unhandledErrors: unknown[]
2021
// filename -> source
@@ -47,6 +48,9 @@ export function createStaticClient(): VitestClient {
4748
getConfig: () => {
4849
return metadata.config
4950
},
51+
getResolvedProjectNames: () => {
52+
return metadata.projects
53+
},
5054
getModuleGraph: async (projectName, id) => {
5155
return metadata.moduleGraph[projectName]?.[id]
5256
},

packages/ui/client/composables/explorer/tree.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export class ExplorerTree {
1818
private rafCollector: ReturnType<typeof useRafFn>
1919
private resumeEndRunId: ReturnType<typeof setTimeout> | undefined
2020
constructor(
21+
public projects: string[] = [],
2122
private onTaskUpdateCalled: boolean = false,
2223
private resumeEndTimeout = 500,
2324
public root = <RootTreeNode>{
@@ -53,7 +54,8 @@ export class ExplorerTree {
5354
this.rafCollector = useRafFn(this.runCollect.bind(this), { fpsLimit: 10, immediate: false })
5455
}
5556

56-
loadFiles(remoteFiles: File[]) {
57+
loadFiles(remoteFiles: File[], projects: string[]) {
58+
this.projects.splice(0, this.projects.length, ...projects)
5759
runLoadFiles(
5860
remoteFiles,
5961
true,

packages/ui/node/reporter.ts

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ interface HTMLReportData {
3535
paths: string[]
3636
files: RunnerTestFile[]
3737
config: SerializedConfig
38+
projects: string[]
3839
moduleGraph: Record<string, Record<string, ModuleGraphData>>
3940
unhandledErrors: unknown[]
4041
// filename -> source
@@ -64,6 +65,7 @@ export default class HTMLReporter implements Reporter {
6465
files: this.ctx.state.getFiles(),
6566
config: this.ctx.getRootProject().serializedConfig,
6667
unhandledErrors: this.ctx.state.getUnhandledErrors(),
68+
projects: this.ctx.resolvedProjects.map(p => p.name),
6769
moduleGraph: {},
6870
sources: {},
6971
}

packages/vitest/src/api/setup.ts

+3
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ export function setup(ctx: Vitest, _server?: ViteDevServer) {
8181
getConfig() {
8282
return ctx.getRootProject().serializedConfig
8383
},
84+
getResolvedProjectNames(): string[] {
85+
return ctx.resolvedProjects.map(p => p.name)
86+
},
8487
async getTransformResult(projectName: string, id, browser = false) {
8588
const project = ctx.getProjectByName(projectName)
8689
const result: TransformResultWithSource | null | undefined = browser

packages/vitest/src/api/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export interface WebSocketHandlers {
3232
getTestFiles: () => Promise<SerializedTestSpecification[]>
3333
getPaths: () => string[]
3434
getConfig: () => SerializedConfig
35+
getResolvedProjectNames: () => string[]
3536
getModuleGraph: (
3637
projectName: string,
3738
id: string,

test/reporters/tests/__snapshots__/html.test.ts.snap

+6
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ exports[`html reporter > resolves to "failing" status for test file "json-fail"
9898
"paths": [
9999
"<rootDir>/test/reporters/fixtures/json-fail.test.ts",
100100
],
101+
"projects": [
102+
"",
103+
],
101104
"sources": {
102105
"<rootDir>/test/reporters/fixtures/json-fail.test.ts": "import { expect, test } from 'vitest'
103106
@@ -195,6 +198,9 @@ exports[`html reporter > resolves to "passing" status for test file "all-passing
195198
"paths": [
196199
"<rootDir>/test/reporters/fixtures/all-passing-or-skipped.test.ts",
197200
],
201+
"projects": [
202+
"",
203+
],
198204
"sources": {
199205
"<rootDir>/test/reporters/fixtures/all-passing-or-skipped.test.ts": "import { expect, test } from 'vitest'
200206

0 commit comments

Comments
 (0)