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

Method end

packages/vitest/src/node/test-run.ts:105–144  ·  view source on GitHub ↗
(specifications: TestSpecification[], errors: unknown[], coverage?: unknown)

Source from the content-addressed store, hash-verified

103 }
104
105 async end(specifications: TestSpecification[], errors: unknown[], coverage?: unknown): Promise<void> {
106 if (coverage) {
107 await this.vitest.report('onCoverage', coverage)
108 }
109
110 // specification won't have the File task if they were filtered by the --shard command
111 const modules = specifications.map(spec => spec.testModule).filter(s => s != null)
112
113 const state: TestRunEndReason = this.vitest.isCancelling
114 ? 'interrupted'
115 // by this point, the run will be marked as failed if there are any errors,
116 // should it be done by testRun.end?
117 : this.hasFailed(modules)
118 ? 'failed'
119 : 'passed'
120
121 if (state !== 'passed') {
122 process.exitCode = 1
123 }
124
125 await this.vitest.report('onTestRunEnd', modules, [...errors] as SerializedError[], state)
126
127 for (const project in this.vitest.state.metadata) {
128 const meta = this.vitest.state.metadata[project]
129 if (!meta?.dumpDir) {
130 continue
131 }
132 const path = resolve(meta.dumpDir, 'vitest-metadata.json')
133 meta.outline = {
134 externalized: Object.keys(meta.externalized).length,
135 inlined: Object.keys(meta.tmps).length,
136 }
137 await writeFile(
138 path,
139 JSON.stringify(meta, null, 2),
140 'utf-8',
141 )
142 this.vitest.logger.log(`Metadata written to ${path}`)
143 }
144 }
145
146 private hasFailed(modules: TestModule[]) {
147 if (!modules.length) {

Callers 15

endSpanMethod · 0.80
tester.tsFile · 0.80
configureServerFunction · 0.80
resolveTesterFunction · 0.80
createTesterMiddlewareFunction · 0.80
handlerFunction · 0.80
recordInitSpanMethod · 0.80
#callActiveSpanMethod · 0.80
mergeReportsMethod · 0.80
startMethod · 0.80
runFilesMethod · 0.80

Calls 7

hasFailedMethod · 0.95
writeFileFunction · 0.85
reportMethod · 0.80
keysMethod · 0.80
filterMethod · 0.65
resolveFunction · 0.50
logMethod · 0.45

Tested by

no test coverage detected