eslint-plugin-no-only-or-skip-tests

2.6.2 • Public • Published

eslint-plugin-no-only-or-skip-tests

This repo is an extension of Levi Buzolic's excellent eslint-plugin-no-only-tests repo.

ESLint rule for .only or .skip tests in mocha, jest, jasmin and other JS testing libraries.

By default the following test blocks are matched by default: describe, it, context, tape, test, fixture, serial.

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

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-or-skip-tests:

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

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

Usage

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

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

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

"rules": {
  "no-only-or-skip-tests/no-only-tests": "error",
  "no-only-or-skip-tests/no-skip-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-or-skip-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 autofixing only when the fix option is set to true to avoid changing runtime code unintentionally when configured in an editor.

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

Options

Option Type Description
block Array<string> Specify the block names that your testing framework uses.
Defaults to ["describe", "it", "context", "test", "tape", "fixture", "serial"]
focus Array<string> Specify the focus scope that your testing framework uses.
Defaults to ["only"]
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

Package Sidebar

Install

npm i eslint-plugin-no-only-or-skip-tests

Weekly Downloads

77

Version

2.6.2

License

MIT

Unpacked Size

9.79 kB

Total Files

6

Last publish

Collaborators

  • mscaveney