A test runner that combines Mocha testing framework with webpack bundling capabilities for modern JavaScript applications
npx @tessl/cli install tessl/npm-mocha-webpack@1.1.0Mocha Webpack is a test runner that combines the power of the Mocha testing framework with webpack's module bundling capabilities. It serves as a wrapper around webpack and mocha, automatically precompiling test files with webpack before executing them with mocha.
npm install webpack mocha mocha-webpack --save-devconst createMochaWebpack = require('mocha-webpack');For ES6 modules (using Babel transpiled src):
import createMochaWebpack from 'mocha-webpack/src/createMochaWebpack';
import MochaWebpack from 'mocha-webpack/src/MochaWebpack';const createMochaWebpack = require('mocha-webpack');
const mochaWebpack = createMochaWebpack();
mochaWebpack
.addEntry('./test/**/*.test.js')
.webpackConfig(require('./webpack.config.js'))
.reporter('spec')
.run()
.then((failures) => {
process.exit(failures);
})
.catch((err) => {
console.error(err);
process.exit(1);
});Mocha Webpack is built around several key components:
Factory function and fluent MochaWebpack class for programmatic test configuration and execution.
/**
* Creates a new MochaWebpack instance
* @returns {MochaWebpack} New MochaWebpack instance
*/
function createMochaWebpack(): MochaWebpack;
class MochaWebpack {
addEntry(file: string): MochaWebpack;
addInclude(file: string): MochaWebpack;
webpackConfig(config: object): MochaWebpack;
run(): Promise<number>;
watch(): Promise<void>;
}Complete CLI with extensive options for running tests from the command line, including watch mode and webpack configuration.
# Basic usage
mocha-webpack [options] [files...]
# Common options
--watch, -w # Watch files for changes
--webpack-config # Path to webpack config
--reporter, -R # Test reporter
--grep, -g # Only run tests matching pattern/**
* Configuration options for MochaWebpack instance
*/
interface MochaWebpackOptions {
cwd: string;
webpackConfig: object;
bail: boolean;
reporter: string | Function;
reporterOptions: object;
ui: string;
fgrep?: string;
grep?: string | RegExp;
invert: boolean;
ignoreLeaks: boolean;
fullStackTrace: boolean;
colors?: boolean;
useInlineDiffs: boolean;
timeout: number;
retries?: number;
slow: number;
asyncOnly: boolean;
delay: boolean;
interactive: boolean;
quiet: boolean;
growl?: boolean;
}