Registry / testing / mocha-vite-puppeteer

mocha-vite-puppeteer

JSON →
library3.0.1jsnpmunverified

Run Mocha front-end tests with Vite bundler and Puppeteer browser launcher. Current stable version is 3.0.1. Release cadence is irregular based on contributions. Key differentiators: leverages Vite for fast bundling, works with any Vite project (not framework-specific), supports JS and TS via Vite, and provides built-in reporters plus custom reporter support (e.g., mocha-junit-reporter). It bridges Mocha testing with Vite's modern tooling, offering a streamlined workflow compared to older setups like Karma or Webpack-based runners.

npm install mocha-vite-puppeteer
INSTALL
IMPORT
SIG · MOCHA-VITE-PUPPETE
M
mocha-vite-puppeteer
testingjavascriptv3.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

mocha-vite-puppeteer
npx mocha-vite-puppeteer
import { mochaVitePuppeteer } from 'mocha-vite-puppeteer'
This package is a command-line tool, not a library. The primary usage is via npx or as a devDependency script.
mocha
import { describe, it } from 'mocha'
const { describe, it } = require('mocha')
Mocha is a peer dependency and used via ESM imports in test files.
chai
import { expect } from 'chai'
import chai from 'chai' (when using named exports)
chai is commonly used for assertions; expect is a named export.

Shows how to set up and run a Mocha test with Vite bundler and Puppeteer using mocha-vite-puppeteer.

// package.json script "scripts": { "test": "mocha-vite-puppeteer" } // Counter.test.jsx import { expect } from 'chai'; import React from 'react'; import { render, screen } from '@testing-library/react'; import Counter from './Counter'; describe('Counter', () => { it('should increment', () => { render(<Counter />); const btn = screen.getByText('count is: 0'); btn.click(); screen.getByText('count is: 1'); }); }); // Run: // npx mocha-vite-puppeteer
mocha-vite-puppeteer --version
Debug
Known issues
gotchaPuppeteer may not be installed automatically; ensure puppeteer is in devDependencies.
fix
npm install --save-dev puppeteer
affects: >=3.0.0
gotchaThe package uses import.meta.globEager which is a Vite-specific API; not available in other bundlers.
fix
Use Vite as your bundler when using custom test.html with globEager.
affects: >=3.0.0
gotchaCustom reporter options file must be valid JSON, else reporter may fail silently.
fix
Ensure reporter-options file is valid JSON and contains the expected keys.
affects: >=3.0.0
gotchaBy default, the package looks for test.html in the root; if not present, it creates a default one. Custom test.html must be alongside index.html.
fix
Place custom test.html in the project root or use --entry flag to specify path.
affects: >=3.0.0
Errors
Common errors & fixes
Error: Cannot find module 'puppeteer'
Puppeteer is not installed as a dependency.
fix
npm install --save-dev puppeteer
TypeError: mocha.setup is not a function
Mocha not properly imported in test setup file.
fix
Add import 'mocha' before calling mocha.setup().
Error: No test files found matching pattern
The glob pattern for test files doesn't match any files.
fix
Check file naming and ensure test files end with .test.js or .test.jsx (or adjust glob in test-loader.js).
Error: 'import.meta.globEager' is not supported outside of Vite
Using custom test.html with import.meta.globEager outside Vite environment.
fix
Ensure you are running with Vite (the default mode) and not using a different bundler.
Upgrade
Version history
3.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
mocha-vite-puppeteer — npm install mocha-vite-puppeteer · libregistry