'How can I avoid "No test specified" errors in npm?
I'm using [email protected] on Mac High Sierra. I want to run tests that were setup in this Stratum client project. I have run npm install
successfully. But when I try and run individual tests, I get the error:
no test specified
What gives? I am in the root project directory and the tests are in my "test" folder. Here is what happens:
localhost:stratum-client-master davea$ npm install
up to date in 0.381s
localhost:stratum-client-master davea$ npm test test/callbacks.js
> [email protected] test /Users/davea/Documents/workspace/stratum-client-master
> echo "Error: no test specified" && exit 1 "test/callbacks.js"
Error: no test specified
sh: line 0: exit: too many arguments
npm ERR! Test failed. See above for more details.
Solution 1:[1]
Try replacing
"scripts": {
"test": "mocha"
},
in your package.json
.
Solution 2:[2]
You're outputting exactly what the package.json file was told to output. Take a peek under scripts
.
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"int-test": "mocha --require babel-core/register --recursive test"
},
Try int-test
, the other command in there.
Update: The package link has changed to the following and mocha should be the default test suite. You can run the other script with npm run bump-version
; the original script above can be run with npm run int-test
.
"scripts": {
"test": "mocha --recursive test",
"bump-version": "npm version patch"
},
Solution 3:[3]
You didn't specify which testing framework you're using such as Jest
or Mocha
.
In case of Jest, add this in your package.json
:
"scripts" : {
"test" : "jest"
}
In the case of mocha
refer to @Divyeshpal's answer.
Solution 4:[4]
if you are using Jest and enzyme for unit testing and you have a jest.config.json config file, you can update your package.json under scripts to the following:
"scripts":{
"test": "jest --config=./jest.config.json --coverage",
}
Solution 5:[5]
The error can be for "exit 1"
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Change it to this:
"scripts": {
"test": "echo \"No test specified\""
},
This change works because exit 1 creates an error.
Solution 6:[6]
find and make changes in your package.json
"scripts":{ "test":"mocha" }
Solution 7:[7]
The error can be for "exit 1"
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Change it to this:
"scripts": {
"test": "echo \"No test specified\""
},
This change worked for me because exit 1 created the error.
Solution 8:[8]
add this on your packages.json file:
"scripts":{
"test": "mocha --ui tdd tests/callbacks.js",
}
then npm test
on the console.
Solution 9:[9]
Replaceecho \"Error: no test specified\" && exit 1
in your
package.json
with
mocha
.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | |
Solution 3 | Penny Liu |
Solution 4 | tony2tones |
Solution 5 | Shuvo Habib |
Solution 6 | Aman Singh |
Solution 7 | Sarbjeet Singh |
Solution 8 | rüff0 |
Solution 9 | hGen |