Home

Awesome

Build Status npm version

<div align="center"> <!-- replace with accurate logo e.g from https://worldvectorlogo.com/ --> <img width="150" height="150" src="https://cdn.worldvectorlogo.com/logos/mocha.svg"> <a href="https://facebook.github.io/jest/"> <img width="150" height="150" vspace="" hspace="25" src="https://cdn.worldvectorlogo.com/logos/jest.svg"> </a> <h1>jest-runner-mocha</h1> <p>Mocha runner for Jest</p> <p>This makes it easy to integrate existing Mocha projects with Jest.</p> </div> <div align="center"> <img src="https://user-images.githubusercontent.com/574806/30088955-728bf97e-925e-11e7-9b25-6aac237085ca.gif"> </div>

Usage

Install

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

yarn add --dev jest jest-runner-mocha

# or with NPM

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

Add it to your Jest config

In your package.json

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

Or in jest.config.js

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

Run Jest

yarn jest

Options

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

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

optionexample
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

optionexampledescription
useBabelRc"useBabelRc": trueread .babelrc when instrumenting for code coverage (required if you transpile your code with babel).

Coverage

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

You can also use other Jest options like coveragePathIgnorePatterns and coverageReporters