Miss any of our Open RFC calls?Watch the recordings here! »

mocha-loader

5.1.0 • Public • Published

npm node deps test chat

Mocha Loader

Allows Mocha tests to be loaded and run via webpack

Install

npm i -D mocha-loader

Usage

CLI

webpack --module-bind 'mocha-loader!./test'

Require

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

Config (recommended)

import test from './test';

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/,
      },
    ],
  },
};

Options

None

Examples

Basic

module.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');
    }
  });
});

Keywords

Install

npm i mocha-loader

DownloadsWeekly Downloads

8,412

Version

5.1.0

License

MIT

Unpacked Size

12.5 kB

Total Files

8

Last publish

Collaborators

  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar