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

fix(browser): print correct transformed module graph #5833

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion packages/ui/client/components/FileDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function relativeToRoot(path?: string) {

<div flex flex-col flex-1 overflow="hidden">
<div v-if="hasGraphBeenDisplayed" :flex-1="viewMode === 'graph' && ''">
<ViewModuleGraph v-show="viewMode === 'graph'" :graph="graph" data-testid="graph" />
<ViewModuleGraph v-show="viewMode === 'graph'" :graph="graph" data-testid="graph" :project-name="current.file.projectName || ''" />
</div>
<ViewEditor v-if="viewMode === 'editor'" :key="current.filepath" :file="current" data-testid="editor" @draft="onDraft" />
<ViewConsoleOutput v-else-if="viewMode === 'console'" :file="current" data-testid="console" />
Expand Down
6 changes: 3 additions & 3 deletions packages/ui/client/components/ModuleTransformResultView.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script setup lang="ts">
import { client } from '~/composables/client'
import { client, browserState } from '~/composables/client'

const props = defineProps<{ id: string }>()
const props = defineProps<{ id: string; projectName: string }>()
const emit = defineEmits<{ (e: 'close'): void }>()

const result = asyncComputed(() => client.rpc.getTransformResult(props.id))
const result = asyncComputed(() => client.rpc.getTransformResult(props.projectName, props.id, !!browserState))
const ext = computed(() => props.id?.split(/\./g).pop() || 'js')

const source = computed(() => result.value?.source?.trim() || '')
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/client/components/views/ViewModuleGraph.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { ModuleGraph, ModuleGraphController, ModuleLink, ModuleNode, Module

const props = defineProps<{
graph: ModuleGraph
projectName: string
}>()

const { graph } = toRefs(props)
Expand Down Expand Up @@ -161,7 +162,7 @@ function bindOnClick(selection: Selection<SVGCircleElement, ModuleNode, SVGGElem
<Modal v-model="modalShow" direction="right">
<template v-if="selectedModule">
<Suspense>
<ModuleTransformResultView :id="selectedModule" @close="modalShow = false" />
<ModuleTransformResultView :id="selectedModule" :project-name="projectName" @close="modalShow = false" />
</Suspense>
</template>
</Modal>
Expand Down
8 changes: 6 additions & 2 deletions packages/vitest/src/api/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ export function setup(ctx: Vitest, _server?: ViteDevServer) {
getConfig() {
return ctx.config
},
async getTransformResult(id) {
const result: TransformResultWithSource | null | undefined = await ctx.vitenode.transformRequest(id)
async getTransformResult(projectName: string, id, browser = false) {
const project = ctx.getProjectByName(projectName)
const result: TransformResultWithSource | null | undefined
= browser
? await project.browser!.transformRequest(id)
: await project.vitenode.transformRequest(id)
if (result) {
try {
result.source = result.source || (await fs.readFile(id, 'utf-8'))
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface WebSocketHandlers {
getPaths: () => string[]
getConfig: () => ResolvedConfig
getModuleGraph: (projectName: string, id: string, browser?: boolean) => Promise<ModuleGraphData>
getTransformResult: (id: string) => Promise<TransformResultWithSource | undefined>
getTransformResult: (projectName: string, id: string, browser?: boolean) => Promise<TransformResultWithSource | undefined>
readTestFile: (id: string) => Promise<string | null>
saveTestFile: (id: string, content: string) => Promise<void>
rerun: (files: string[]) => Promise<void>
Expand Down
Loading