| 103 | } |
| 104 | |
| 105 | async writeReport(report: string): Promise<void> { |
| 106 | const metaFile = resolve(this.reporterDir, 'html.meta.json.gz') |
| 107 | |
| 108 | const promiseGzip = promisify(gzip) |
| 109 | const data = await promiseGzip(report, { |
| 110 | level: zlibConstants.Z_BEST_COMPRESSION, |
| 111 | }) |
| 112 | await fs.writeFile(metaFile, data, 'base64') |
| 113 | const ui = resolve(distDir, 'client') |
| 114 | // copy ui |
| 115 | const files = globSync(['**/*'], { cwd: ui, expandDirectories: false }) |
| 116 | await Promise.all( |
| 117 | files.map(async (f) => { |
| 118 | if (f === 'index.html') { |
| 119 | const html = await fs.readFile(resolve(ui, f), 'utf-8') |
| 120 | const filePath = relative(this.reporterDir, metaFile) |
| 121 | await fs.writeFile( |
| 122 | this.htmlFilePath, |
| 123 | html.replace( |
| 124 | '<!-- !LOAD_METADATA! -->', |
| 125 | `<script>window.METADATA_PATH="${filePath}"</script>`, |
| 126 | ), |
| 127 | ) |
| 128 | } |
| 129 | else { |
| 130 | await fs.copyFile(resolve(ui, f), resolve(this.reporterDir, f)) |
| 131 | } |
| 132 | }), |
| 133 | ) |
| 134 | |
| 135 | // copy attachments |
| 136 | // TODO: unify attachmentsDir and html outputFile, so both live together without extra copy |
| 137 | if (existsSync(this.ctx.config.attachmentsDir)) { |
| 138 | const destAttachmentsDir = resolve(this.reporterDir, 'data') |
| 139 | await fs.rm(destAttachmentsDir, { recursive: true, force: true }) |
| 140 | await fs.mkdir(destAttachmentsDir, { recursive: true }) |
| 141 | await fs.cp(this.ctx.config.attachmentsDir, destAttachmentsDir, { recursive: true }) |
| 142 | } |
| 143 | |
| 144 | this.ctx.logger.log( |
| 145 | `${c.bold(c.inverse(c.magenta(' HTML ')))} ${c.magenta( |
| 146 | 'Report is generated', |
| 147 | )}`, |
| 148 | ) |
| 149 | this.ctx.logger.log( |
| 150 | `${c.dim(' You can run ')}${c.bold( |
| 151 | `npx vite preview --outDir ${relative(this.ctx.config.root, this.reporterDir)}`, |
| 152 | )}${c.dim(' to see the test results.')}`, |
| 153 | ) |
| 154 | } |
| 155 | |
| 156 | async onFinishedReportCoverage(): Promise<void> { |
| 157 | if (this.ctx.config.coverage.enabled && this.ctx.config.coverage.htmlDir) { |