(specifications: TestSpecification[], errors: unknown[], coverage?: unknown)
| 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) { |
no test coverage detected