jest-runner-mocha-next

3.2.0 • Public • Published

Build Status npm version dependencies Status devDependencies Status Known Vulnerabilities

It's a fork!

It is an experimental fork of jest-runner-mocha with some amazing features and fixes:

  • Support for mocha custom version
  • Support for setupFilesAfterEnv
  • Support for custom clearMocks implementation (ex. for sinon)
  • Support for jest flag coverageProvider v8 (node 10+ only)
  • See more in changelog!

Usage

Install

Install jest(it needs Jest 21+) and jest-runner-mocha-next

 
npm install --save-dev jest jest-runner-mocha-next
 

Add it to your Jest config

In your package.json

{
  "jest": {
    "runner": "jest-runner-mocha-next"
  }
}

Or in jest.config.js

module.exports = {
  runner: 'jest-runner-mocha-next',
}

Run Jest

npx jest

Options

This project uses cosmiconfig, so you can provide config via:

  • a jest-runner-mocha property in your package.json
  • a jest-runner-mocha.config.js JS file
  • a .jest-runner-mocharc JSON file

In package.json

{
  "jest-runner-mocha": {
    "cliOptions": {
      // Options here
    },
    "coverageOptions": {
      // Options here
    }
  }
}

or in jest-runner-mocha.config.js

module.exports = {
  cliOptions: {
    // Options here
  },
  "coverageOptions": {
    // Options here
  }
}

cliOptions

jest-runner-mocha maps some mocha CLI arguments to config options. For example --ui is cliOptions.ui

option example
ui "ui": "tdd"
timeout "timeout": 10000
compiler "compiler": "./path/to/babel-register"
file "file": ["./path/to/include.js", "/supports/multiple/files.js"]

coverageOptions

jest-runner-mocha has some optional configuration for code coverage

option example description
useBabelRc "useBabelRc": true read .babelrc when instrumenting for code coverage (required if you transpile your code with babel).

Coverage

Coverage works outside of the box, simply npx jest -- --coverage

You can also use other Jest options like coveragePathIgnorePatterns and coverageReporters

Custom clearMocks function

Just make an export with a clearMocks function in your setupFilesAfterEnv, like this:

'use strict';
 
const sinon = require('sinon');
const nock = require('nock');
 
module.exports = {
    clearMocks: (suite) => {
        sinon.sandbox.restore();
        if(!nock.isDone()) {
            console.log(`Warning: pending mocks in ${suite.file}${nock.pendingMocks()}`);
            nock.cleanAll();
        }
    }
};
 

Readme

Keywords

none

Package Sidebar

Install

npm i jest-runner-mocha-next

Weekly Downloads

0

Version

3.2.0

License

MIT

Unpacked Size

20.5 kB

Total Files

9

Last publish

Collaborators

  • jehy-true