Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

mocha-loader

webpack-contrib16.4kMIT5.1.5

Mocha loader for webpack

webpack, mocha

readme

npm node deps tests coverage chat size

mocha-loader

Allows Mocha tests to be loaded and run via webpack.

Getting Started

To begin, you'll need to install mocha-loader and mocha:

npm install --save-dev mocha-loader mocha

Then add the plugin to your webpack config. For example:

file.js

import test from './test.js';

webpack.config.js

module.exports = {
  entry: './entry.js',
  output: {
    path: __dirname,
    filename: 'bundle.js',
  },
  module: {
    rules: [
      {
        test: /test\.js$/,
        use: 'mocha-loader',
        exclude: /node_modules/,
      },
    ],
  },
};

And run webpack via your preferred method.

Alternative usage (without configuration):

import test from 'mocha-loader!./test.js';

No options for loader.

Examples

Basic

file.js

module.exports = true;

test.js

describe('Test', () => {
  it('should succeed', (done) => {
    setTimeout(done, 1000);
  });

  it('should fail', () => {
    setTimeout(() => {
      throw new Error('Failed');
    }, 1000);
  });

  it('should randomly fail', () => {
    if (require('./module')) {
      throw new Error('Randomly failed');
    }
  });
});

Contributing

Please take a moment to read our contributing guidelines if you haven't yet done so.

CONTRIBUTING

License

MIT

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

5.1.5 (2020-10-15)

  • update css-loader

5.1.4 (2020-10-10)

  • update style-loader

5.1.3 (2020-10-09)

  • update schema-utils

5.1.2 (2020-07-31)

Bug Fixes

5.1.1 (2020-07-27)

Chore

  • updating dependencies

5.1.0 (2020-06-11)

Features

5.0.0 (2020-03-24)

Bug Fixes

  • remove broken handling of "target": "node" (#92) (b84eb10)

BREAKING CHANGES

  • the node target doesn't supported

4.0.2 (2020-03-19)

  • update deps

4.0.1 (2020-01-09)

Bug Fixes

4.0.0 (2019-12-02)

Fixes

  • compatibility with webpack@5

BREAKING CHANGES

  • minimum required nodejs version is 10.13
  • minimum required mocha version is 5

3.0.0 (2019-08-15)

Features

  • improve validation errors

BREAKING CHANGES

  • drop support for Node < 8.9.0
  • minimum supported webpack version is 4

2.0.0 (2018-08-27)

Chores

BREAKING CHANGES

  • package: requires node >= v6.0.0

1.1.3 (2018-01-24)

1.1.2 (2018-01-05)