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

Class HTMLReporter

packages/ui/node/reporter.ts:41–171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39const distDir = resolve(fileURLToPath(import.meta.url), '../../dist')
40
41export default class HTMLReporter implements Reporter {
42 start = 0
43 ctx!: Vitest
44 options: HTMLOptions
45
46 private reporterDir!: string
47 private htmlFilePath!: string
48
49 constructor(options: HTMLOptions) {
50 this.options = options
51 }
52
53 async onInit(ctx: Vitest): Promise<void> {
54 this.ctx = ctx
55 this.start = Date.now()
56 const htmlFile
57 = this.options.outputFile
58 || getOutputFile(this.ctx.config)
59 || 'html/index.html'
60 const htmlFilePath = resolve(this.ctx.config.root, htmlFile)
61 this.reporterDir = dirname(htmlFilePath)
62 this.htmlFilePath = htmlFilePath
63
64 await fs.mkdir(resolve(this.reporterDir, 'assets'), { recursive: true })
65 }
66
67 async onTestRunEnd(): Promise<void> {
68 const result: HTMLReportData = {
69 paths: this.ctx.state.getPaths(),
70 files: this.ctx.state.getFiles(),
71 config: this.ctx.serializedRootConfig,
72 unhandledErrors: this.ctx.state.getUnhandledErrors(),
73 moduleGraph: {},
74 sources: {},
75 }
76 const promises: Promise<void>[] = []
77
78 promises.push(...result.files.map(async (file) => {
79 const projectName = file.projectName || ''
80 const resolvedConfig = this.ctx.getProjectByName(projectName).config
81 const browser = resolvedConfig.browser.enabled
82 result.moduleGraph[projectName] ??= {}
83 result.moduleGraph[projectName][file.filepath] = await getModuleGraph(
84 this.ctx,
85 projectName,
86 file.filepath,
87 browser,
88 )
89 if (!result.sources[file.filepath]) {
90 try {
91 result.sources[file.filepath] = await fs.readFile(file.filepath, {
92 encoding: 'utf-8',
93 })
94 }
95 catch {
96 // just ignore
97 }
98 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…