# gulp-mocha

> Run Mocha tests

Latest version **10.0.1** (published 2024-04-19) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types package; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 10.0.1 |
| Published | 2024-04-19 |
| First published | 2013-12-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/gulp-mocha) |
| Module format | ESM |
| Node | >=18 |
| Dependencies | 5 |
| Unpacked size | 6.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 378 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | gulpplugin, mocha, test, testing, unit, framework, runner, tdd, bdd, qunit, spec, tap |

## Links

- npm: https://www.npmjs.com/package/gulp-mocha
- Repository: https://github.com/sindresorhus/gulp-mocha
- Homepage: https://github.com/sindresorhus/gulp-mocha#readme
- Issues: https://github.com/sindresorhus/gulp-mocha/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/gulp-mocha

## Dependencies (5)

- [dargs](https://npm.io/package/dargs.md) ^8.1.0
- [execa](https://npm.io/package/execa.md) ^8.0.1
- [mocha](https://npm.io/package/mocha.md) ^10.2.0
- [supports-color](https://npm.io/package/supports-color.md) ^9.4.0
- [gulp-plugin-extras](https://npm.io/package/gulp-plugin-extras.md) ^0.3.0

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 10.0.1 (latest) — 2024-04-19
- 10.0.0 — 2023-11-03
- 9.0.0 — 2023-10-26
- 8.0.0 — 2021-02-18
- 7.0.2 — 2019-10-04
- 7.0.1 — 2019-08-20
- 7.0.0 — 2019-08-18
- 6.0.0 — 2018-05-23
- 5.0.0 — 2017-12-30
- 4.3.1 — 2017-04-27
- 4.3.0 — 2017-04-01
- 4.2.0 — 2017-03-29
- 4.1.0 — 2017-03-07
- 4.0.1 — 2017-02-20
- 4.0.0 — 2017-02-20
- … 24 more at https://npm.io/package/gulp-mocha/versions

## README

# gulp-mocha

> Run [Mocha](https://github.com/mochajs/mocha) tests

*Keep in mind that this is just a thin wrapper around Mocha and your issue is most likely with Mocha.*

## Install

```sh
npm install --save-dev gulp-mocha
```

## Usage

```js
import gulp from 'gulp';
import mocha from 'gulp-mocha';

export default () => (
	gulp.src('test.js', {read: false})
		// `gulp-mocha` needs file paths so you cannot have any plugins before it.
		.pipe(mocha({reporter: 'nyan'}))
);
```

## API

### mocha(options?)

#### options

Type: `object`

Options are passed directly to the `mocha` binary, so you can use any its [command-line options](http://mochajs.org/#usage) in a camelCased form. Arrays and key/value objects are correctly converted to the comma separated list format Mocha expects. Listed below are some of the more commonly used options:

##### ui

Type: `string`\
Default: `'bdd'`\
Values: `'bdd' | 'tdd' | 'qunit' | 'exports'`

The interface to use.

##### reporter

Type: `string`\
Default: `spec`\
Values: [Reporters](https://github.com/mochajs/mocha/tree/master/lib/reporters)

The reporter that will be used.

This option can also be used to utilize third-party reporters. For example, if you `npm install mocha-lcov-reporter` you can then do use `mocha-lcov-reporter` as value.

##### reporterOptions

Type: `object`\
Example: `{reportFilename: 'index.html'}`

Reporter specific options.

##### globals

Type: `string[]`

List of accepted global variable names, example `['YUI']`. Accepts wildcards to match multiple global variables, e.g. `['gulp*']` or even `['*']`. See [Mocha globals option](http://mochajs.org/#globals-option).

##### timeout

Type: `number`\
Default: `2000`

Test-case timeout in milliseconds.

##### bail

Type: `boolean`\
Default: `false`

Bail on the first test failure.

##### checkLeaks

Type: `boolean`\
Default: `false`

Check for global variable leaks.

##### grep

Type: `string`

Only run tests matching the given pattern which is internally compiled to a RegExp.

##### require

Type: `string[]`

Require custom modules before tests are run.

##### compilers

Type: `string`\
Example: `js:babel-core/register`

Specify a compiler.

## FAQ

### Test suite not exiting

If your test suite is not exiting it might be because you still have a lingering callback, most often caused by an open database connection. You should close this connection or do the following:

```js
export default () => (
	gulp.src('test.js')
		.pipe(mocha())
		.once('error', err => {
			console.error(err);
			process.exit(1);
		})
		.once('end', () => {
			process.exit();
		})
);
```

Or you might just need to pass the `exit` option:

```js
export const test = () => (
	gulp.src(['test/**/*.js'], {read: false})
		.pipe(mocha({reporter: 'list', exit: true}))
		.on('error', console.error)
);
```

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