question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can i run tests before commit using lint-staged and react-scripts?

See original GitHub issue

Curently have

  "devDependencies": {
    "husky": "^0.13.3",
    "lint-staged": "^3.4.2",
    "prettier": "^1.3.1",
    "react-scripts": "1.0.5"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "precommit": "lint-staged"
  },
  "lint-staged": {
    "src/**/*.js": [
      "prettier",
      "git add"
    ]
  }
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
luftywiranda13commented, May 23, 2017

@spacecrio this is how I implement it

"scripts": {
  "precommit": "lint-staged",
  "test:staged": "cross-env CI=true react-scripts test --env=jsdom --findRelatedTests"
}

then

"lint-staged": {
  "src/**/*.js": [
    "test:staged",
    "git add"
  ]
}

for the env variable, use cross-env… it is cross platform

hope it helps!

6reactions
luftywiranda13commented, May 23, 2017

without passing CI=true jest will automatically run in watch mode by default. so it’s not suitable for testing staged files.

IMO until this time, doing like what I wrote in the comment before is perfectly fine. Also by passing --findRelatedTestswill make things faster because jest (under the hood) will find related tests and run selected tests based on files which are currently in staging area.

Read more comments on GitHub >

github_iconTop Results From Across the Web

setting up lint-staged for jest - Stack Overflow
There is a work around to set husky lint-staged using react-scripts test and avoid ejecting and configuring your own babel and jest.
Read more >
Husky + Lint-Staged on a React TypeScript Project
To trigger some action before committing, we will use the Git Hook called “pre-commit”. Let's now create an action to execute our 'test'...
Read more >
Build a robust React app with Husky pre-commit hooks and ...
Adding a pre-commit hook with Husky and lint-staged​​ In our hook, we will check for linter errors and warnings, type errors, failing tests,...
Read more >
Lint Staged With Husky for Pre-commit Validations - YouTube
Learn how to use lint staged with husky to implement linting and formatting your code with Prettier and Eslint on pre - commit....
Read more >
Automated Code Linting and Testing | by Harsh Verma - Medium
Script test:staged — By default the react-scripts run the test cases in watch mode but this will hang such type of CI(Continous Integration) ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found