GithubHelp home page GithubHelp logo

sualko / eslint-plugin-no-only-tests Goto Github PK

View Code? Open in Web Editor NEW

This project forked from levibuzolic/eslint-plugin-no-only-tests

0.0 0.0 0.0 170 KB

ESLint rule for catching focused/only test blocks

Home Page: https://www.npmjs.com/package/eslint-plugin-no-only-tests

License: MIT License

JavaScript 100.00%

eslint-plugin-no-only-tests's Introduction

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"]
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

eslint-plugin-no-only-tests's People

Contributors

levibuzolic avatar dependabot[bot] avatar bwendt-mylo avatar coltonbrwn avatar bahmutov avatar roughy avatar tgreen7 avatar ma7moudat avatar thorsent avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.