Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add resolved project names to the reporter API #7213

Merged
merged 5 commits into from
Jan 12, 2025
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
5 changes: 3 additions & 2 deletions packages/ui/client/composables/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,11 @@ watch(
ws.addEventListener('open', async () => {
status.value = 'OPEN'
client.state.filesMap.clear()
let [files, _config, errors] = await Promise.all([
let [files, _config, errors, projects] = await Promise.all([
client.rpc.getFiles(),
client.rpc.getConfig(),
client.rpc.getUnhandledErrors(),
client.rpc.getResolvedProjectNames(),
])
if (_config.standalone) {
const filenames = await client.rpc.getTestFiles()
Expand All @@ -166,7 +167,7 @@ watch(
return file
})
}
explorerTree.loadFiles(files)
explorerTree.loadFiles(files, projects)
client.state.collectFiles(files)
explorerTree.startRun()
unhandledErrors.value = (errors || []).map(parseError)
Expand Down
4 changes: 4 additions & 0 deletions packages/ui/client/composables/client/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface HTMLReportMetadata {
paths: string[]
files: File[]
config: SerializedConfig
projects: string[]
moduleGraph: Record<string, Record<string, ModuleGraphData>>
unhandledErrors: unknown[]
// filename -> source
Expand Down Expand Up @@ -47,6 +48,9 @@ export function createStaticClient(): VitestClient {
getConfig: () => {
return metadata.config
},
getResolvedProjectNames: () => {
return metadata.projects
},
getModuleGraph: async (projectName, id) => {
return metadata.moduleGraph[projectName]?.[id]
},
Expand Down
4 changes: 3 additions & 1 deletion packages/ui/client/composables/explorer/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class ExplorerTree {
private rafCollector: ReturnType<typeof useRafFn>
private resumeEndRunId: ReturnType<typeof setTimeout> | undefined
constructor(
public projects: string[] = [],
private onTaskUpdateCalled: boolean = false,
private resumeEndTimeout = 500,
public root = <RootTreeNode>{
Expand Down Expand Up @@ -53,7 +54,8 @@ export class ExplorerTree {
this.rafCollector = useRafFn(this.runCollect.bind(this), { fpsLimit: 10, immediate: false })
}

loadFiles(remoteFiles: File[]) {
loadFiles(remoteFiles: File[], projects: string[]) {
this.projects.splice(0, this.projects.length, ...projects)
Copy link
Member Author

Choose a reason for hiding this comment

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

this will require some changes when exposing the data for the filter selector, should be fixed in #7201 once merged

runLoadFiles(
remoteFiles,
true,
Expand Down
2 changes: 2 additions & 0 deletions packages/ui/node/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface HTMLReportData {
paths: string[]
files: File[]
config: SerializedConfig
projects: string[]
moduleGraph: Record<string, Record<string, ModuleGraphData>>
unhandledErrors: unknown[]
// filename -> source
Expand Down Expand Up @@ -65,6 +66,7 @@ export default class HTMLReporter implements Reporter {
files: this.ctx.state.getFiles(),
config: this.ctx.getRootProject().serializedConfig,
unhandledErrors: this.ctx.state.getUnhandledErrors(),
projects: this.ctx.getResolvedProjectNames(),
moduleGraph: {},
sources: {},
}
Expand Down
3 changes: 3 additions & 0 deletions packages/vitest/src/api/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ export function setup(ctx: Vitest, _server?: ViteDevServer) {
getConfig() {
return ctx.getRootProject().serializedConfig
},
getResolvedProjectNames(): string[] {
return ctx.getResolvedProjectNames()
},
async getTransformResult(projectName: string, id, browser = false) {
const project = ctx.getProjectByName(projectName)
const result: TransformResultWithSource | null | undefined = browser
Expand Down
1 change: 1 addition & 0 deletions packages/vitest/src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface WebSocketHandlers {
getTestFiles: () => Promise<SerializedTestSpecification[]>
getPaths: () => string[]
getConfig: () => SerializedConfig
getResolvedProjectNames: () => string[]
getModuleGraph: (
projectName: string,
id: string,
Expand Down
7 changes: 7 additions & 0 deletions packages/vitest/src/node/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,13 @@ export class Vitest {
return this.coreWorkspaceProject
}

/**
* Get project names.
*/
public getResolvedProjectNames(): string[] {
Copy link
Member

@sheremet-va sheremet-va Jan 12, 2025

Choose a reason for hiding this comment

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

I don't think this should be a public API. You can access resolvedProjects in the RPC, it's an internal property

Copy link
Member Author

Choose a reason for hiding this comment

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

oh thx

Copy link
Member Author

@userquin userquin Jan 12, 2025

Choose a reason for hiding this comment

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

I need to access it from packages/ui/node/reporter.ts, resolvedProjects is internal

Copy link
Member Author

@userquin userquin Jan 12, 2025

Choose a reason for hiding this comment

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

I'm going to provide a callback to resolve the project names.

Copy link
Member Author

Choose a reason for hiding this comment

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

argg, it is a reporter not a plugin, we'll need to expose it in the public API

Copy link
Member

Choose a reason for hiding this comment

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

internal fields should be visible in all internal packages, and ui is an internal package. the field is not private

return this.resolvedProjects.map(p => p.name)
}

/**
* @deprecated use Reported Task API instead
*/
Expand Down
Loading