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

Method onTestRunEnd

packages/vitest/src/node/reporters/blob.ts:42–98  ·  view source on GitHub ↗
(testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>)

Source from the content-addressed store, hash-verified

40 }
41
42 async onTestRunEnd(testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>): Promise<void> {
43 const executionTime = performance.now() - this.start
44
45 const files = testModules.map(testModule => testModule.task)
46 const errors = [...unhandledErrors]
47 const coverage = this.coverage
48
49 let outputFile
50 = this.options.outputFile ?? getOutputFile(this.ctx.config, 'blob')
51 if (!outputFile) {
52 const shard = this.ctx.config.shard
53 outputFile = shard
54 ? `.vitest-reports/blob-${shard.index}-${shard.count}.json`
55 : '.vitest-reports/blob.json'
56 }
57
58 const environmentModules: MergeReportEnvironmentModules = {}
59 this.ctx.projects.forEach((project) => {
60 const serializedProject: MergeReportEnvironmentModules[string] = {
61 environments: {},
62 external: [],
63 }
64 Object.entries(project.vite.environments).forEach(([environmentName, environment]) => {
65 serializedProject.environments[environmentName] = serializeEnvironmentModuleGraph(
66 environment,
67 )
68 })
69
70 if (project.browser?.vite.environments.client) {
71 serializedProject.browser = serializeEnvironmentModuleGraph(
72 project.browser.vite.environments.client,
73 )
74 }
75
76 for (const [id, value] of project._resolver.externalizeCache.entries()) {
77 if (typeof value === 'string') {
78 serializedProject.external.push([id, value])
79 }
80 }
81
82 environmentModules[project.name] = serializedProject
83 })
84
85 const report = [
86 this.ctx.version,
87 files,
88 errors,
89 coverage,
90 executionTime,
91 environmentModules,
92 ] satisfies MergeReport
93
94 const reportFile = resolve(this.ctx.config.root, outputFile)
95 await writeBlob(report, reportFile)
96
97 this.ctx.logger.log('blob report written to', reportFile)
98 }
99}

Callers

nothing calls this directly

Calls 6

getOutputFileFunction · 0.90
writeBlobFunction · 0.85
entriesMethod · 0.80
resolveFunction · 0.50
logMethod · 0.45

Tested by

no test coverage detected