Skip to content

Commit a758157

Browse files
authored
fix(browser): print correct transformed module graph (#5833)
1 parent 70a277b commit a758157

File tree

5 files changed

+13
-8
lines changed

5 files changed

+13
-8
lines changed

packages/ui/client/components/FileDetails.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ function relativeToRoot(path?: string) {
113113

114114
<div flex flex-col flex-1 overflow="hidden">
115115
<div v-if="hasGraphBeenDisplayed" :flex-1="viewMode === 'graph' && ''">
116-
<ViewModuleGraph v-show="viewMode === 'graph'" :graph="graph" data-testid="graph" />
116+
<ViewModuleGraph v-show="viewMode === 'graph'" :graph="graph" data-testid="graph" :project-name="current.file.projectName || ''" />
117117
</div>
118118
<ViewEditor v-if="viewMode === 'editor'" :key="current.filepath" :file="current" data-testid="editor" @draft="onDraft" />
119119
<ViewConsoleOutput v-else-if="viewMode === 'console'" :file="current" data-testid="console" />

packages/ui/client/components/ModuleTransformResultView.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<script setup lang="ts">
2-
import { client } from '~/composables/client'
2+
import { client, browserState } from '~/composables/client'
33
4-
const props = defineProps<{ id: string }>()
4+
const props = defineProps<{ id: string; projectName: string }>()
55
const emit = defineEmits<{ (e: 'close'): void }>()
66
7-
const result = asyncComputed(() => client.rpc.getTransformResult(props.id))
7+
const result = asyncComputed(() => client.rpc.getTransformResult(props.projectName, props.id, !!browserState))
88
const ext = computed(() => props.id?.split(/\./g).pop() || 'js')
99
1010
const source = computed(() => result.value?.source?.trim() || '')

packages/ui/client/components/views/ViewModuleGraph.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { ModuleGraph, ModuleGraphController, ModuleLink, ModuleNode, Module
77
88
const props = defineProps<{
99
graph: ModuleGraph
10+
projectName: string
1011
}>()
1112
1213
const { graph } = toRefs(props)
@@ -161,7 +162,7 @@ function bindOnClick(selection: Selection<SVGCircleElement, ModuleNode, SVGGElem
161162
<Modal v-model="modalShow" direction="right">
162163
<template v-if="selectedModule">
163164
<Suspense>
164-
<ModuleTransformResultView :id="selectedModule" @close="modalShow = false" />
165+
<ModuleTransformResultView :id="selectedModule" :project-name="projectName" @close="modalShow = false" />
165166
</Suspense>
166167
</template>
167168
</Modal>

packages/vitest/src/api/setup.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,12 @@ export function setup(ctx: Vitest, _server?: ViteDevServer) {
6767
getConfig() {
6868
return ctx.config
6969
},
70-
async getTransformResult(id) {
71-
const result: TransformResultWithSource | null | undefined = await ctx.vitenode.transformRequest(id)
70+
async getTransformResult(projectName: string, id, browser = false) {
71+
const project = ctx.getProjectByName(projectName)
72+
const result: TransformResultWithSource | null | undefined
73+
= browser
74+
? await project.browser!.transformRequest(id)
75+
: await project.vitenode.transformRequest(id)
7276
if (result) {
7377
try {
7478
result.source = result.source || (await fs.readFile(id, 'utf-8'))

packages/vitest/src/api/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface WebSocketHandlers {
1616
getPaths: () => string[]
1717
getConfig: () => ResolvedConfig
1818
getModuleGraph: (projectName: string, id: string, browser?: boolean) => Promise<ModuleGraphData>
19-
getTransformResult: (id: string) => Promise<TransformResultWithSource | undefined>
19+
getTransformResult: (projectName: string, id: string, browser?: boolean) => Promise<TransformResultWithSource | undefined>
2020
readTestFile: (id: string) => Promise<string | null>
2121
saveTestFile: (id: string, content: string) => Promise<void>
2222
rerun: (files: string[]) => Promise<void>

0 commit comments

Comments
 (0)