Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
romankurakin opened this issue May 23, 2017 · 5 comments
Closed

Comments

@romankurakin
Copy link

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"
    ]
  }
}
@romankurakin
Copy link
Author

romankurakin commented May 23, 2017

"precommit": "lint-staged && set CI=true&&npm test" work, but it looks like hack and it platform specific

@luftywiranda13
Copy link
Contributor

luftywiranda13 commented 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!

@romankurakin
Copy link
Author

@luftywiranda13 its work, thank you

But it would be great to be able to just run all tests like run "$ yarn jest" in the project created by the creat-reaction-app without env CI=true

@luftywiranda13
Copy link
Contributor

luftywiranda13 commented 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.

@quantuminformation
Copy link

Thx for this guys, very helpful.

@lock lock bot locked and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants