Coder Social home page Coder Social logo

detect-only-in-specs-on-commit-example's Introduction

detect-only-in-tests

Detects it.only in specs on commit (example)

How to stop committing test files with it.only in BDD tests?

  1. Use eslint with whatever rules you want
  2. Add eslint-plugin-no-only-tests and maybe set it as a warning by default
{
  "plugins": [
    "no-only-tests"
  ],
  "rules": {
    "no-only-tests/no-only-tests": 1
  }
  }
  1. Use husky and lint-staged to grab changed files before commit
  2. Enable "no-only-tests" rule in the lint-staged command from command line using eslint --rule to enable the rule. The package.json should define a script name invoked by the linter
"scripts": {
  "test": "eslint src/*.js",
  "precommit-lint": "eslint --fix --rule 'no-only-tests/no-only-tests: 2'",
  "precommit": "lint-staged"
},
"lint-staged": {
  "src/*.js": ["precommit-lint", "git add"],
  "verbose": false
}

Try committing JS file with it.only block and it reports and error

$ git commit -m "try commit"

> husky - npm run -s precommit
> husky - node v6.8.1

 ❯ Running tasks for src/*.js
   ✖ precommit-lint
     git add
 ↓ Running tasks for verbose [skipped]
   → No staged files match verbose
🚫 precommit-lint found some errors. Please fix them and try committing again.

/Users/git/detect-only-in-specs/src/foo-spec.js
  2:6  error  it.only not permitted  no-only-tests/no-only-tests

✖ 1 problem (1 error, 0 warnings)

> husky - pre-commit hook failed (add --no-verify to bypass)
> husky - to debug, use 'npm run precommit'

detect-only-in-specs-on-commit-example's People

Contributors

bahmutov avatar

Stargazers

 avatar

Watchers

 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.