( coverageDataDir: string, cwd: string, testFiles: Set<string>, )
| 188 | } |
| 189 | |
| 190 | export async function collectServerCoverageMap( |
| 191 | coverageDataDir: string, |
| 192 | cwd: string, |
| 193 | testFiles: Set<string>, |
| 194 | ): Promise<CoverageMap | null> { |
| 195 | let { createCoverageMap } = getIstanbul() |
| 196 | let coverageMap = createCoverageMap({}) |
| 197 | let converted = 0 |
| 198 | |
| 199 | let files: string[] |
| 200 | try { |
| 201 | files = (await fsp.readdir(coverageDataDir)).filter( |
| 202 | (f) => f.startsWith('coverage-') && f.endsWith('.json'), |
| 203 | ) |
| 204 | } catch { |
| 205 | return null |
| 206 | } |
| 207 | |
| 208 | for (let file of files) { |
| 209 | let data = JSON.parse(await fsp.readFile(path.join(coverageDataDir, file), 'utf-8')) |
| 210 | let scriptCoverages: Array<{ url: string; functions: any[] }> = data.result ?? [] |
| 211 | |
| 212 | for (let entry of scriptCoverages) { |
| 213 | if (!entry.url.startsWith('file://')) continue |
| 214 | |
| 215 | let filePath: string |
| 216 | try { |
| 217 | filePath = fileURLToPath(entry.url) |
| 218 | } catch { |
| 219 | continue |
| 220 | } |
| 221 | |
| 222 | if ( |
| 223 | !filePath || |
| 224 | !['.ts', '.tsx'].includes(path.extname(filePath)) || |
| 225 | shouldExcludeFromCoverage(filePath, cwd, testFiles) |
| 226 | ) { |
| 227 | continue |
| 228 | } |
| 229 | |
| 230 | try { |
| 231 | // For server unit tests, we transform the TS with a module loader and V8 tracks |
| 232 | // coverage using byte offsets from the transformed JS. Re-transform with the |
| 233 | // same `esbuild` call here so offsets align, then pass the result with its |
| 234 | // inline source map to v8-to-istanbul. |
| 235 | let tsSource = await fsp.readFile(filePath, 'utf-8') |
| 236 | let { code } = await transformTypeScript(tsSource, filePath) |
| 237 | let success = await addV8EntryToCoverageMap(coverageMap, filePath, entry.functions, code) |
| 238 | if (success) converted++ |
| 239 | } catch { |
| 240 | // Skip files that can't be converted |
| 241 | } |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | // Clean up raw V8 coverage JSON files now that we've processed them |
| 246 | //await Promise.all(files.map((f) => fsp.rm(path.join(coverageDataDir, f), { force: true }))) |
| 247 |
no test coverage detected
searching dependent graphs…