Socket
Socket
Sign inDemoInstall

@kernel-panic/jest-runner-mocha

Package Overview
Dependencies
160
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @kernel-panic/jest-runner-mocha

An experimental Mocha runner for Jest


Version published
Weekly downloads
1
decreased by-91.67%
Maintainers
1
Created
Weekly downloads
 

Changelog

Source

3.1.0

  • Experimental support for --coverageProvider v8 option.

Readme

Source

Build Status npm version dependencies Status devDependencies Status Known Vulnerabilities

It's a fork!

It is an experimental fork of https://github.com/rogeliog/jest-runner-mocha with some experimental features:

  • Support for mocha custom version
  • Support for setupFilesAfterEnv
  • Support for custom clearMocks implementation (ex. for sinon)
  • See more in changelog!

Usage

Install

Install jest(it needs Jest 21+) and @kernel-panic/jest-runner-mocha


npm install --save-dev jest @kernel-panic/jest-runner-mocha

Add it to your Jest config

In your package.json

{
  "jest": {
    "runner": "@kernel-panic/jest-runner-mocha"
  }
}

Or in jest.config.js

module.exports = {
  runner: '@kernel-panic/jest-runner-mocha',
}

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

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

module.exports = {
	clearMocks: () => {
		sinon.sandbox.restore();
	}
};

FAQs

Last updated on 07 Feb 2020

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc