1. mocha-loader
Mocha loader for webpack
mocha-loader
Package: mocha-loader
Created by: webpack-contrib
Last modified: Mon, 20 Jun 2022 01:31:58 GMT
Version: 5.1.5
License: MIT
Downloads: 25,191
Repository: https://github.com/webpack-contrib/mocha-loader

Install

npm install mocha-loader
yarn add mocha-loader

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

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code