# mocha-loader

> Mocha loader for webpack

Latest version **5.1.5** (published 2020-10-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install mocha-loader
pnpm add mocha-loader
yarn add mocha-loader
bun add mocha-loader
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.1.5 |
| Published | 2020-10-15 |
| First published | 2012-11-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 10.13.0 |
| Dependencies | 4 |
| Unpacked size | 13.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 145 |
| Author | Tobias Koppers @sokra |
| Maintainers | d3viant0ne, evilebottnawi, sokra, jhnns, michael-ciniawsky, bebraw, ericclemmons, tricoder, thelarkinn, jankanty |
| Keywords | webpack, mocha |

## Links

- npm: https://www.npmjs.com/package/mocha-loader
- Repository: https://github.com/webpack-contrib/mocha-loader
- Issues: https://github.com/webpack-contrib/mocha-loader/issues
- Funding: https://opencollective.com/webpack
- npm.io page: https://npm.io/package/mocha-loader

## Dependencies (4)

- [css-loader](https://npm.io/package/css-loader.md) ^5.0.0
- [loader-utils](https://npm.io/package/loader-utils.md) ^2.0.0
- [schema-utils](https://npm.io/package/schema-utils.md) ^3.0.0
- [style-loader](https://npm.io/package/style-loader.md) ^2.0.0

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 5.1.5 (latest) — 2020-10-15
- 5.1.4 — 2020-10-10
- 5.1.3 — 2020-10-09
- 5.1.2 — 2020-07-31
- 5.1.1 — 2020-07-27
- 5.1.0 — 2020-06-11
- 5.0.0 — 2020-03-24
- 4.0.2 — 2020-03-19
- 4.0.1 — 2020-01-09
- 4.0.0 — 2019-12-02
- 3.0.0 — 2019-08-15
- 2.0.1 — 2019-02-25
- 2.0.0 — 2018-08-27
- 1.1.3 — 2018-01-24
- 1.1.2 — 2018-01-05
- … 16 more at https://npm.io/package/mocha-loader/versions

## README

<div align="center">
  <img width="200" height="200"
    src="https://cdn.worldvectorlogo.com/logos/mocha.svg">
  <a href="https://github.com/webpack/webpack">
    <img width="200" height="200" hspace="20"
      src="https://webpack.js.org/assets/icon-square-big.svg">
  </a>
</div>

[![npm][npm]][npm-url]
[![node][node]][node-url]
[![deps][deps]][deps-url]
[![tests][tests]][tests-url]
[![coverage][cover]][cover-url]
[![chat][chat]][chat-url]
[![size][size]][size-url]

# mocha-loader

Allows [Mocha](https://mochajs.org/) tests to be loaded and run via webpack.

## Getting Started

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

```console
npm install --save-dev mocha-loader mocha
```

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

**file.js**

```js
import test from './test.js';
```

**webpack.config.js**

```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):

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

No options for loader.

## Examples

### Basic

**file.js**

```js
module.exports = true;
```

**test.js**

```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](./.github/CONTRIBUTING.md)

## License

[MIT](./LICENSE)

[npm]: https://img.shields.io/npm/v/mocha-loader.svg
[npm-url]: https://npmjs.com/package/mocha-loader
[node]: https://img.shields.io/node/v/mocha-loader.svg
[node-url]: https://nodejs.org
[deps]: https://david-dm.org/webpack-contrib/mocha-loader.svg
[deps-url]: https://david-dm.org/webpack-contrib/mocha-loader
[tests]: https://github.com/webpack-contrib/mocha-loader/workflows/mocha-loader/badge.svg
[tests-url]: https://github.com/webpack-contrib/mocha-loader/actions
[cover]: https://codecov.io/gh/webpack-contrib/mocha-loader/branch/master/graph/badge.svg
[cover-url]: https://codecov.io/gh/webpack-contrib/mocha-loader
[chat]: https://badges.gitter.im/webpack/webpack.svg
[chat-url]: https://gitter.im/webpack/webpack
[size]: https://packagephobia.now.sh/badge?p=mocha-loader
[size-url]: https://packagephobia.now.sh/result?p=mocha-loader

---
_Source: https://npm.io/package/mocha-loader · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
