MCPcopy
hub / github.com/vitest-dev/vitest / getTransformResult

Function getTransformResult

packages/vitest/src/api/setup.ts:125–157  ·  view source on GitHub ↗
(projectName: string, moduleId, testFileTaskId, browser = false)

Source from the content-addressed store, hash-verified

123 return result
124 },
125 async getTransformResult(projectName: string, moduleId, testFileTaskId, browser = false) {
126 const project = ctx.getProjectByName(projectName)
127 const testModule = ctx.state.getReportedEntityById(testFileTaskId) as TestModule | undefined
128 if (!testModule || !isFileServingAllowed(project.vite.config, moduleId)) {
129 return
130 }
131
132 const environment = getTestFileEnvironment(project, testModule.moduleId, browser)
133
134 const moduleNode = environment?.moduleGraph.getModuleById(moduleId)
135 if (!environment || !moduleNode?.transformResult) {
136 return
137 }
138
139 const result: TransformResultWithSource = moduleNode.transformResult
140 try {
141 result.source = result.source || (moduleNode.file ? await fs.readFile(moduleNode.file, 'utf-8') : undefined)
142 }
143 catch {}
144
145 // TODO: store this in HTML reporter separately
146 const transformDuration = ctx.state.metadata[projectName]?.duration[moduleNode.url]?.[0]
147 if (transformDuration != null) {
148 result.transformTime = transformDuration
149 }
150 try {
151 const diagnostic = await ctx.experimental_getSourceModuleDiagnostic(moduleId, testModule)
152 result.modules = diagnostic.modules
153 result.untrackedModules = diagnostic.untrackedModules
154 }
155 catch {}
156 return result
157 },
158 async getModuleGraph(project, id, browser): Promise<ModuleGraphData> {
159 return getModuleGraph(ctx, project, id, browser)
160 },

Callers

nothing calls this directly

Calls 6

isFileServingAllowedFunction · 0.90
getTestFileEnvironmentFunction · 0.90
getProjectByNameMethod · 0.80
getReportedEntityByIdMethod · 0.80
readFileMethod · 0.80

Tested by

no test coverage detected