You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

mocha-loader

Package Overview
Dependencies
Maintainers
10
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mocha-loader

Mocha loader for webpack

4.0.2
Source
npmnpm
Version published
Weekly downloads
15K
43.94%
Maintainers
10
Weekly downloads
 
Created
Source

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

webpack

FAQs

Package last updated on 19 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts