CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-mocha-webpack

A test runner that combines Mocha testing framework with webpack bundling capabilities for modern JavaScript applications

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

Mocha Webpack

Mocha 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.

Package Information

  • Package Name: mocha-webpack
  • Package Type: npm
  • Language: JavaScript (ES6/Flow types)
  • Installation: npm install webpack mocha mocha-webpack --save-dev

Core Imports

const 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';

Basic Usage

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);
  });

Architecture

Mocha Webpack is built around several key components:

  • MochaWebpack Class: Fluent API for configuring and running tests programmatically
  • CLI Interface: Command-line tool with extensive options matching mocha's interface
  • Test Runner: Internal engine that coordinates webpack compilation and mocha execution
  • Watch Mode: Intelligent file watching that analyzes dependency graphs to run only affected tests
  • Memory Compilation: Webpack builds are kept in memory for better performance without writing files to disk

Capabilities

Programmatic API

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>;
}

Programmatic API

Command Line Interface

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

Command Line Interface

Types

/**
 * 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;
}
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/mocha-webpack@1.1.x
Publish Source
CLI
Badge
tessl/npm-mocha-webpack badge