Web-based user interface for the Vitest testing framework with real-time test execution visualization and HTML reporting capabilities
—
The HTML Reporter generates comprehensive standalone HTML reports from Vitest test results, providing an interactive interface for viewing test outcomes, coverage data, and detailed error information.
import HTMLReporter from "@vitest/ui/reporter";Main class for generating HTML test reports.
declare class HTMLReporter implements Reporter {
constructor(options: HTMLOptions);
onInit(ctx: Vitest): Promise<void>;
onFinished(): Promise<void>;
processAttachment(attachment: TestAttachment): Promise<void>;
writeReport(report: string): Promise<void>;
}Constructor Parameters:
options: HTMLOptions - Configuration options for the HTML reporterMethods:
onInit(ctx: Vitest): Promise<void> - Initialize the reporter with Vitest contextonFinished(): Promise<void> - Generate the final HTML report after tests completeprocessAttachment(attachment: TestAttachment): Promise<void> - Process and store test attachmentswriteReport(report: string): Promise<void> - Write the HTML report to the file systemimport { defineConfig } from 'vitest/config';
import HTMLReporter from '@vitest/ui/reporter';
export default defineConfig({
test: {
reporters: [
new HTMLReporter({ outputFile: 'test-results/index.html' })
],
},
});import { defineConfig } from 'vitest/config';
import HTMLReporter from '@vitest/ui/reporter';
export default defineConfig({
test: {
reporters: [
'default', // Console reporter
new HTMLReporter({ outputFile: 'reports/test-results.html' }),
],
},
});export default defineConfig({
test: {
reporters: [
new HTMLReporter({
outputFile: 'dist/reports/vitest-report.html'
})
],
},
});The HTML reporter follows this workflow:
Generated reports include:
The reporter automatically processes test attachments:
// External URLs are preserved as-is
if (attachment.path.startsWith('http://') || attachment.path.startsWith('https://')) {
attachment.body = undefined;
return;
}
// Local files are copied to the report directory
const buffer = await readFile(attachment.path);
const hash = crypto.createHash('sha1').update(buffer).digest('hex');
const filename = hash + extname(attachment.path);
await writeFile(resolve(this.reporterDir, 'data', filename), buffer);// HTMLOptions is imported from 'vitest/node'
interface HTMLOptions {
outputFile?: string | Partial<Record<string, string>>;
}
interface HTMLReportData {
paths: string[];
files: RunnerTestFile[];
config: SerializedConfig;
projects: string[];
moduleGraph: Record<string, Record<string, ModuleGraphData>>;
unhandledErrors: unknown[];
sources: Record<string, string>;
}
interface TestAttachment {
path?: string;
body?: string | Buffer;
contentType?: string;
}Install with Tessl CLI
npx tessl i tessl/npm-vitest--ui