tests only succeed once. No tests found; Jest, Babel, lint-staged, husky.
See original GitHub issue🐛 Bug Report
When ran via cli (not husky precommit hook), npm run test will succeed. Also, when running the precommit git hook after initially creating or renaming a test file, npm run test will succeed. However, I’m failing after rerunning the git commit hook with a previously committed test.
➜ git commit -m "test"
husky > pre-commit (node v14.2.0)
✔ Preparing...
⚠ Running tasks...
❯ Running tasks for ./src/**/*.{js,jsx,ts,tsx}
✖ npm run test [FAILED]
↓ Skipped because of errors from tasks. [SKIPPED]
✔ Reverting to original state because of errors...
✔ Cleaning up...
✖ npm run test:
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! projects@5.59.1 test: `jest --notify --coverage "/Users/alane/Documents/projects/bots/project/src/index.js"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the project@5.59.1 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/alane/.npm/_logs/2020-07-21T02_00_31_704Z-debug.log
> project@5.59.1 test /Users/alane/Documents/projects/bots/project
> jest --notify --coverage "/Users/alane/Documents/projects/bots/project/src/index.js"
No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In /Users/alane/Documents/projects/bots/project
48 files checked.
testMatch: **/__tests__/**/*.[jt]s?(x), **/?(*.)+(spec|test).[tj]s?(x) - 1 match
testPathIgnorePatterns: /node_modules/ - 48 matches
testRegex: - 0 matches
Pattern: /Users/alane/Documents/projects/bots/project/src/index.js - 0 matches
husky > pre-commit hook failed (add --no-verify to bypass)
To Reproduce
package.json
"scripts": {
"start": "pm2 start processes.json --only prod",
"dev": "pm2 start processes.json --only dev",
"devmon": "nodemon --exec 'babel-node --inspect=0.0.0.0 src/index.js'",
"config": "nodemon configure.sh",
"stop": "pm2 delete processes.json",
"prettier": "prettier --write ./src/**/*",
"lint": "eslint src/**/*.js --fix --color",
"build": "rm -rf build && babel ./src --out-dir ./build",
"watch:test": "jest --watch",
"test": "jest --notify --coverage"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"./src/**/*.{js,jsx,ts,tsx}": [
"npm run prettier",
"npm run lint",
"npm run build",
"npm run test"
]
},
"jest": {
"testEnvironment": "node",
"collectCoverage": true,
"coverageDirectory": "coverage",
"collectCoverageFrom": [
"src/**/*.js"
],
"coveragePathIgnorePatterns": [
"/node_modules/"
]
},
"babel": {
"only": [
"src"
],
"env": {
"test": {
"presets": [
"@babel/preset-env"
],
"plugins": [
"@babel/plugin-proposal-optional-chaining",
"@babel/plugin-transform-runtime",
"@babel/plugin-transform-modules-commonjs",
"@babel/plugin-proposal-class-properties"
],
"sourceMaps": "inline",
"retainLines": true
},
"production": {
"presets": [
"@babel/preset-env"
],
"plugins": [
"@babel/plugin-proposal-optional-chaining",
"@babel/plugin-transform-runtime",
"@babel/plugin-transform-modules-commonjs",
"@babel/plugin-proposal-class-properties"
]
},
"development": {
"presets": [
"@babel/preset-env"
],
"plugins": [
"@babel/plugin-proposal-optional-chaining",
"@babel/plugin-transform-runtime",
"@babel/plugin-transform-modules-commonjs",
"@babel/plugin-proposal-class-properties"
],
"sourceMaps": "inline",
"retainLines": true
}
}
}
Expected behavior
Previously committed tests would be found, ran, and succeed.
envinfo
MacOSX, also Ubuntu 18.04 Docker image
System:
OS: macOS 10.15.5
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Binaries:
Node: 14.2.0 - /usr/local/bin/node
npm: 6.14.5 - /usr/local/bin/npm
npmPackages:
jest: ^26.1.0 => 26.1.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:6
Top Results From Across the Web
No Test case found Jest - Stack Overflow
Jest is trying to run the files on your staging area, that's why it's appending some file paths. What you need is --findRelatedTests...
Read more >Run jest for unit tests of modified files only | by SunCommander
In this article, you will learn how to run Jest for modified files only in a Pull Request. This can be done using...
Read more >themxb-test-demo - npm Package Health Analysis - Snyk
Learn more about themxb-test-demo: package health score, popularity, security, maintenance ... npm install --save husky lint-staged prettier.
Read more >openvidu-react-test - npm
react-scripts is a development dependency in the generated projects (including this one). You almost never need to update create-react-app ...
Read more >Run Linting, Tests and Prettier in git Hooks with Husky
That's going to be pre-commit. Then we can give this a value. This'll be a script that runs. [00:53] Let's start with npm...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m also seeing this, reverting to jest@25 fixes it
lint-staged
passes the names of the files that have changed, sojest
is called likejest file-1.js file-2.js
(or/Users/alane/Documents/projects/bots/project/src/index.js
in your specific case).I guess we could make
--all
ignore any passedtestPathPattern
? That way you could stickjest --all
into yourlint-staged
config.If you don’t wanna run all files but only related tests you can do
jest --findRelatedTests
/cc @thymikee @jeysal thoughts?