Skip to content
This repository has been archived by the owner on Dec 22, 2020. It is now read-only.

webpack-contrib/mocha-loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

7f292ad · Dec 22, 2020
Oct 13, 2020
Oct 9, 2020
Oct 9, 2020
Dec 2, 2019
Aug 12, 2019
Aug 12, 2019
Aug 12, 2019
Aug 12, 2019
Aug 12, 2019
Jun 11, 2020
Oct 15, 2020
Aug 12, 2019
Dec 22, 2020
Dec 2, 2019
Aug 12, 2019
Aug 12, 2019
Dec 2, 2019
Jun 11, 2020
Oct 15, 2020
Oct 15, 2020

Repository files navigation

DEPRECATED

If you would like to continue to support/maintenance this package please contact me https://twitter.com/alexander_akait

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