Registry / testing / karma-vite

karma-vite

JSON →
library1.0.5jsnpmunverified

A Karma plugin that uses Vite to transform ES modules for testing. Current stable version is 1.0.5, released December 2023, supporting Vite 2 through 5. It enables using Vite's fast development server and module transformation within Karma test runner. Unlike karma-webpack or karma-rollup, it leverages Vite's on-demand compilation and HMR-like middleware for quicker test re-runs. Requires Karma 6+ and Vite 2-5 as peer dependencies. Ships TypeScript types.

npm install karma-vite
INSTALL
IMPORT
SIG · KARMA-VITE
K
karma-vite
testingjavascriptv1.0.5
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

karma-vite
module.exports = (config) => { config.set({ plugins: ['karma-vite'], frameworks: ['vite'] }); };
const karmaVite = require('karma-vite');
The plugin is a Karma framework plugin; it should be registered via 'plugins' array in karma.conf.js, not required directly in test files.
KarmaViteConfig
import type { KarmaViteConfig } from 'karma-vite';
const { KarmaViteConfig } = require('karma-vite');
TypeScript users can import the KarmaViteConfig interface for configuring the vite property in karma.conf.js. CJS require is not supported for types; use import type.
karma-vite (as a plugin)
plugins: ['karma-vite']
plugins: [require('karma-vite')]
Karma resolves plugin names from npm packages; using require() for the plugin object is unnecessary and can break plugin resolution.

Minimal Karma configuration to run Jasmine tests with Vite transformation. Tests are ES modules with .ts extension, and Vite handles TypeScript compilation.

// karma.conf.js module.exports = (config) => { config.set({ plugins: ['karma-vite', 'karma-jasmine'], frameworks: ['vite', 'jasmine'], files: [ { pattern: 'test/**/*.spec.ts', type: 'module', watched: false, served: false, }, ], }); };
Debug
Known issues
gotchaThe files pattern must include type: 'module', watched: false, and served: false. Missing these can cause infinite loops or modules not being served.
fix
Set type: 'module', watched: false, served: false on all test file entries.
affects: >=1.0.0
breakingKarma testing never starts if urlRoot is the default value ('/') in Karma config.
fix
Upgrade to 1.0.1 or later. Alternatively, set urlRoot to a non-root path (e.g., '/karma/').
affects: 1.0.0
deprecatedSupport for Vite 2 was removed in v1.0.5 (since Vite 2 is no longer maintained).
fix
Use Vite 3, 4, or 5 with karma-vite >=1.0.5.
affects: >=1.0.5
gotchaviteClientMiddleware always calls next() even when it should not, causing middleware chaining issues in some Karma setups.
fix
Upgrade to 1.0.3 or later.
affects: >=1.0.0 <1.0.3
gotchaVite define variables are not applied when using karma-vite v1.0.0.
fix
Upgrade to 1.0.1 or later.
affects: 1.0.0
gotchaCoverage reports can be generated via vite-plugin-istanbul, but only if 'coverage' reporter is present in Karma config. If coverage reporter is not configured, coverage instrumentation may silently not work.
fix
Ensure karma-coverage plugin is installed and add 'coverage' to reporters array in Karma config.
affects: >=1.0.0
Errors
Common errors & fixes
Karma never starts. Tests are not executed.
urlRoot is set to default '/' in Karma config, which conflicts with karma-vite middleware.
fix
Set urlRoot to a non-root path (e.g., '/karma/') in karma.conf.js, or upgrade to karma-vite v1.0.1+.
Cannot find module 'karma-vite'
Plugin not installed or not registered correctly in karma config.
fix
Run 'npm install -D karma-vite'. Ensure 'karma-vite' is listed in the plugins array (not require()'d directly).
TypeError: Cannot read properties of undefined (reading 'call')
viteClientMiddleware receives an undefined response object due to middleware chain issues (affects v1.0.0–1.0.2).
fix
Upgrade to karma-vite v1.0.3 or later.
Vite config 'define' not working. Environment variables are undefined in tests.
Bug in karma-vite v1.0.0 where Vite's define config is ignored.
fix
Upgrade to karma-vite v1.0.1 or later.
Upgrade
Version history
1.0.5latest on npm
Audit
Dependencies
karmarequiredPeer dependency; Karma test runner required to run tests
viterequiredPeer dependency; Vite is used for module transformation and dev server
Agent activity
4 hits · last 30 days
node
4
Resources
karma-vite — npm install karma-vite · libregistry