How can I avoid "No test specified" errors in npm?
Asked Answered
N

10

46

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.
Ninnyhammer answered 18/2, 2018 at 23:2 Comment(0)
C
44

Try replacing

"scripts": {
  "test": "mocha"
},

in your package.json.

Cilurzo answered 17/5, 2018 at 21:59 Comment(3)
I get mocha not found error nowHanna
'mocha' is not recognized as an internal or external command,Moorwort
Mocha needs to be installed first before use, thus please run the below command npm i mocha or refer to this doc npmjs.com/package/mochaCilurzo
I
22

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"
},
Iatry answered 18/2, 2018 at 23:7 Comment(2)
I did try "npm int-test" as their documentaiton recommended but got the error "Usage: npm <command> ... Did you mean one of these? test install-test" so tthen I migrated to what I had above.Ninnyhammer
In order to run a command in the script tag, you must specify the run subcommand. npm run int-test. npm test is just a short-hand for npm run test. It might be a good idea to replace the test command with the int-test so that you can run npm test.Bighead
F
17

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.

Felsite answered 28/7, 2020 at 12:9 Comment(1)
Hi, i am using Jasmine frame work, instead of jest what i need to add?Pietje
M
11

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.

Manus answered 6/5, 2020 at 21:22 Comment(0)
M
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",
}
Michealmicheil answered 29/12, 2018 at 11:24 Comment(0)
G
4

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.

Gymnosophist answered 7/5, 2021 at 8:54 Comment(1)
Simple, maybe not the best practice, but it worked for me, thank you!Shanell
D
1

find and make changes in your package.json

"scripts":{ "test":"mocha" }

Delastre answered 22/7, 2020 at 13:48 Comment(0)
F
0

add this on your packages.json file:

"scripts":{
    "test": "mocha --ui tdd tests/callbacks.js",
}

then npm test on the console.

Frankiefrankincense answered 29/7, 2018 at 7:21 Comment(0)
Z
0

I also had such a problem, I repeated (npm install selenium-webdriver) the command after which everything fell into place

Zoogloea answered 23/5 at 11:15 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Mv
U
-2

Replace
echo \"Error: no test specified\" && exit 1 in your package.json with mocha.

Unstuck answered 9/7, 2021 at 6:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.