Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

eslint-plugin-no-only-tests

levibuzolic3.8mMIT3.3.0

ESLint rule for .only blocks in mocha tests

eslint, eslintplugin, eslint-plugin, mocha, rule, only, describe, it, fixture

readme

eslint-plugin-no-only-tests

Version Downloads GitHub Tests

ESLint rule for .only tests in Mocha, Jest, Jasmine, Mocha Cakes 2 and other JS testing libraries.

The following test blocks are matched by default: describe, it, context, tape, test, fixture, serial, Feature, Scenario, Given, And, When and Then.

Designed to prevent you from committing focused (.only) tests to CI, which may prevent your entire test suite from running.

If the testing framework you use doesn't use .only to focus tests, you can override the matchers with options.

Installation

Install ESLint if you haven't done so already, then install eslint-plugin-no-only-tests:

npm install --save-dev eslint-plugin-no-only-tests
# or
yarn add --dev eslint-plugin-no-only-tests

Note: If you installed ESLint globally (using the -g flag) then you must also install eslint-plugin-no-only-tests globally.

Usage

Add no-only-tests to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

"plugins": [
  "no-only-tests"
]

Then add the rule to the rules section of your .eslintrc:

"rules": {
  "no-only-tests/no-only-tests": "error"
}

If you use a testing framework that uses a test block name that isn't present in the defaults, or a different way of focusing test (something other than .only) you can specify an array of blocks and focus methods to match in the options.

"rules": {
  "no-only-tests/no-only-tests": [
    "error", {
      "block": ["test", "it", "assert"],
      "focus": ["only", "focus"]
    }
  ]
}

The above example will catch any uses of test.only, test.focus, it.only, it.focus, assert.only and assert.focus.

This rule supports opt-in autofixing when the fix option is set to true to avoid changing runtime code unintentionally when configured in an editor.

"rules": {
  "no-only-tests/no-only-tests": ["error", {"fix": true}]
}

Options

Option Type Description
block string[] Specify the block names that your testing framework uses. Add a * to the end of any string to enable prefix matching (ie. test* will match testExample.only)
Defaults to ["describe", "it", "context", "test", "tape", "fixture", "serial", "Feature", "Scenario", "Given", "And", "When", "Then"]
focus string[] Specify the focus scope that your testing framework uses.
Defaults to ["only"]
functions string[] Specify not permitted functions. Good examples are fit or xit.
Defaults to [] (disabled)
fix boolean Enable this rule to auto-fix violations, useful for a pre-commit hook, not recommended for users with auto-fixing enabled in their editor.
Defaults to false

changelog

v3.0.0

Added

  • Block scope matchers can accept a trailing * to optionally match blocks by prefix #35

Breaking

  • Block matchers no longer match prefixes of blocks by default, can now be configured via options #35

v2.6.0

  • Disable auto fixing by default, allow it to be optionally enabled. #26

v2.5.0

  • Add support for auto fixing violations - #19 @tgreen7

v2.4.0

  • Add support for defining 2 levels deep in blocks (ie. ava.default)

v2.3.1

  • Bump js-yaml from 3.13.0 to 3.13.1 due to security vulnerability - #11

v2.3.0

  • Allow test block names to be specified in options - #10

v2.2.0

  • Added rule for catching .only blocks for serial - #9 @IevgenRagulin

v2.1.0

  • Added rule for catching .only blocks for fixture - #8 @roughy

v2.0.1

  • Fixed major bug where rule would cause errors for objects with key only - #7 @bendemboski

v2.0.0

  • Updated rule format to ESLint 3
  • Updated ESLInt dependency to >=3.0.0
  • Updated node engine to >=4.0.0
  • Get CircleCI up and running

v1.2.0

  • Added rules for catching .only blocks for test, context and tape

v1.1.0

  • Updated rule to use Identifier rather than CallExpression
  • Changed reporter to give a more generic message (removed reference to mocha)
  • Added additional test coverage

v1.0.1

  • Added additional test coverage
  • Removed unnecessary dependencies in package.json

v1.0.0

  • Initial version