Registry / testing / mocha-webpack

mocha-webpack

JSON →
library1.1.0jsnpmunverified

A CLI tool that integrates Mocha test runner with Webpack bundling, allowing you to test modules that rely on Webpack features (loaders, plugins, resolve aliases) without pre-building or using hacks. Version 1.1.0 is the latest stable release (as of late 2018). It supports Mocha >=2.4.5 <=5 and Webpack 2.x/3.x. Key differentiators: bundling tests into a single bundle with Webpack's full pipeline (loaders, resolve, plugins), built-in source map support, memory-fs for speed (no disk writes), customizable file watcher, and support for multiple entry files/patterns. The project is effectively unmaintained (last release 2017) for Webpack 4+ compatibility.

npm install mocha-webpack
INSTALL
IMPORT
SIG · MOCHA-WEBPACK
M
mocha-webpack
testingjavascriptv1.1.0
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 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

mocha-webpack
npx mocha-webpack --webpack-config webpack.config.js test/**/*.spec.js
mocha-webpack --require source-map-support/register test/**/*.spec.js
mocha-webpack includes source-map-support by default since v1.0.0. CLI usage only; no programmatic API exported.
mocha-webpack (require from Node)
import 'mocha-webpack'; // or require('mocha-webpack') — only side effects
const { run } = require('mocha-webpack');
mocha-webpack does not export any functions or objects; requiring it merely registers the CLI command. Use CLI arguments instead.

Configures mocha-webpack with a webpack config file, custom opts file, and runs tests matching a glob pattern.

// package.json scripts { "scripts": { "test": "mocha-webpack --webpack-config webpack.test.js --opts ./mocha-webpack.opts test/**/*.spec.js" } } // mocha-webpack.opts --timeout 10000 --reporter spec // webpack.test.js (example) const path = require('path'); module.exports = { mode: 'development', resolve: { extensions: ['.js', '.jsx', '.json'] }, module: { rules: [ { test: /\.jsx?$/, exclude: /node_modules/, use: { loader: 'babel-loader', options: { presets: ['@babel/preset-env', '@babel/preset-react'] } } } ] } }; // Run: npx mocha-webpack --webpack-config webpack.test.js test/**/*.spec.js
mocha-webpack --version
Debug
Known issues
deprecatedmocha-webpack is unmaintained since v1.1.0 (2017). No Webpack 4/5 compatibility. Use mochapack or webpack-shell-plugin instead.
fix
Migrate to mochapack (https://github.com/sysgears/mochapack) or configure webpack+mocha manually.
affects: >=1.0.0
breakingv1.0.0 switched from writing bundle to disk to using memory-fs. If you relied on the generated bundle file, it no longer exists.
fix
Remove any references to generated bundle file. Use --webpack-config to specify output settings or rely on memory-fs.
affects: >=1.0.0 <1.0.0
breakingv1.0.0 replaced 'glob-like' file resolution with real glob. Patterns like 'test/unit/*' may resolve differently if `resolve.extensions` not set.
fix
Ensure webpack resolve.extensions includes '.js' and other extensions used in your tests.
affects: >=1.0.0 <1.0.0
gotchamocha-webpack will ignore webpack's `entry` and `output` configuration; it overrides them internally. Do not set them in your webpack config, or they will be overwritten.
fix
Omit `entry` and `output` from your webpack test config, or use `--webpack-config` that merges partial configs.
affects: *
gotchaWebpack 4 is not supported. Attempting to use mocha-webpack with webpack@4 will fail at module resolution.
fix
Use webpack@3.x or switch to mochapack (supports webpack 4+).
affects: >=1.0.0
deprecatedThe `--opts` flag defaults to looking for `mocha-webpack.opts` or `mocha.opts` in the current directory. If you have both, mocha-webpack prefers `mocha-webpack.opts`.
fix
Rename your opts file to `mocha-webpack.opts` or use `--opts path/to/your.opts`.
affects: >=0.3.0
Errors
Common errors & fixes
Error: Cannot find module 'mocha-webpack' from '<PROJECT>' at Function.module.exports [as runMain] (module.js:xxx:xx)
Mocha-webpack is not installed globally or locally when running via CLI.
fix
Install mocha-webpack locally: `npm install --save-dev mocha-webpack` and use npx or package.json scripts.
Error: webpack.optimize.OccurrenceOrderPlugin is not a constructor
Using mocha-webpack with webpack 4, which removed deprecated plugins.
fix
Downgrade to webpack@3 or migrate to mochapack.
TypeError: Cannot read property 'getFiles' of undefined
This error appears in v1.0.1 and was fixed; related to file resolution issues.
fix
Update to mocha-webpack@1.1.0 which fixed this bug.
Error: Module not found: Error: Can't resolve 'fs' in '<PROJECT>/node_modules/mocha-webpack'
Webpack target/node misconfiguration; mocha-webpack expects Node environment.
fix
Set webpack target to 'node' in your webpack config: `target: 'node'`.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
mocharequiredpeer dependency: test runner framework
webpackrequiredpeer dependency: module bundler for test compilation
Agent activity
4 hits · last 30 days
node
4
Resources