Web-based user interface for the Vitest testing framework with real-time test execution visualization and HTML reporting capabilities
—
The @vitest/ui Vite plugin provides a development-time web interface for Vitest, serving the UI application and handling WebSocket connections for real-time test monitoring.
import vitestUI from "@vitest/ui";Creates a Vite plugin that integrates the Vitest UI into your development server.
declare function vitestUI(ctx: Vitest): Plugin;Parameters:
ctx: Vitest - The Vitest instance context containing configuration and stateReturns:
Plugin - A Vite plugin object with server middleware configurationimport { defineConfig } from 'vite';
import vitestUI from '@vitest/ui';
export default defineConfig({
plugins: [
vitestUI(vitestContext), // Pass your Vitest instance
],
});import { defineConfig } from 'vitest/config';
export default defineConfig({
plugins: [
// Vitest will automatically configure the UI plugin when ui: true
],
test: {
ui: true,
uiBase: '/vitest-ui', // Custom base path
},
});The plugin performs several key functions:
The plugin configures several middleware handlers:
/__vitest_attachment__ endpointThe plugin includes validation to prevent configuration conflicts:
// Example error case
if (coveragePath && base === coveragePath) {
throw new Error(
`The ui base path and the coverage path cannot be the same: ${base}, change coverage.reportsDirectory`
);
}interface Plugin {
name: string;
apply: string;
configureServer: {
order: string;
handler: (server: ViteDevServer) => void;
};
}Install with Tessl CLI
npx tessl i tessl/npm-vitest--ui