{"id":25951,"library":"mocha-vite-puppeteer","title":"mocha-vite-puppeteer","description":"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.","status":"active","version":"3.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/larsthorup/mocha-vite-puppeteer","tags":["javascript","mocha","vite","puppeteer"],"install":[{"cmd":"npm install mocha-vite-puppeteer","lang":"bash","label":"npm"},{"cmd":"yarn add mocha-vite-puppeteer","lang":"bash","label":"yarn"},{"cmd":"pnpm add mocha-vite-puppeteer","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is a command-line tool, not a library. The primary usage is via npx or as a devDependency script.","wrong":"import { mochaVitePuppeteer } from 'mocha-vite-puppeteer'","symbol":"mocha-vite-puppeteer","correct":"npx mocha-vite-puppeteer"},{"note":"Mocha is a peer dependency and used via ESM imports in test files.","wrong":"const { describe, it } = require('mocha')","symbol":"mocha","correct":"import { describe, it } from 'mocha'"},{"note":"chai is commonly used for assertions; expect is a named export.","wrong":"import chai from 'chai' (when using named exports)","symbol":"chai","correct":"import { expect } from 'chai'"}],"quickstart":{"code":"// package.json script\n\"scripts\": {\n  \"test\": \"mocha-vite-puppeteer\"\n}\n\n// Counter.test.jsx\nimport { expect } from 'chai';\nimport React from 'react';\nimport { render, screen } from '@testing-library/react';\nimport Counter from './Counter';\n\ndescribe('Counter', () => {\n  it('should increment', () => {\n    render(<Counter />);\n    const btn = screen.getByText('count is: 0');\n    btn.click();\n    screen.getByText('count is: 1');\n  });\n});\n\n// Run:\n// npx mocha-vite-puppeteer","lang":"javascript","description":"Shows how to set up and run a Mocha test with Vite bundler and Puppeteer using mocha-vite-puppeteer."},"warnings":[{"fix":"npm install --save-dev puppeteer","message":"Puppeteer may not be installed automatically; ensure puppeteer is in devDependencies.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Use Vite as your bundler when using custom test.html with globEager.","message":"The package uses import.meta.globEager which is a Vite-specific API; not available in other bundlers.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Ensure reporter-options file is valid JSON and contains the expected keys.","message":"Custom reporter options file must be valid JSON, else reporter may fail silently.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Place custom test.html in the project root or use --entry flag to specify path.","message":"By 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.","severity":"gotcha","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"npm install --save-dev puppeteer","cause":"Puppeteer is not installed as a dependency.","error":"Error: Cannot find module 'puppeteer'"},{"fix":"Add import 'mocha' before calling mocha.setup().","cause":"Mocha not properly imported in test setup file.","error":"TypeError: mocha.setup is not a function"},{"fix":"Check file naming and ensure test files end with .test.js or .test.jsx (or adjust glob in test-loader.js).","cause":"The glob pattern for test files doesn't match any files.","error":"Error: No test files found matching pattern"},{"fix":"Ensure you are running with Vite (the default mode) and not using a different bundler.","cause":"Using custom test.html with import.meta.globEager outside Vite environment.","error":"Error: 'import.meta.globEager' is not supported outside of Vite"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}