Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

npm

testing

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. 
like image 896
Dave Avatar asked Feb 18 '18 23:02

Dave


People also ask

How do I run a specific test in npm?

npm run only one test n order to run a specific test, you'll need to use the jest command. npm test will not work. To access jest directly on the command line, install it via npm i -g jest-cli or yarn global add jest-cli. Then simply run your specific test with jest bar.

Why npm start not working?

Check the ignore-script config If you see the start script is present inside your package. json file but still can't run the script, you need to check the console output. If there's no output at all, then you may have the ignore-scripts npm configuration set to true .

What is the use of npm test command?

The npm test command is used to test a package. This command runs the test script that is contained in a package, if you provided one.

What is npm Run command?

npm run sets the NODE environment variable to the node executable with which npm is executed. If you try to run a script without having a node_modules directory and it fails, you will be given a warning to run npm install , just in case you've forgotten.


2 Answers

Try replacing

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

in your package.json.

like image 96
Divyesh pal Avatar answered Sep 28 '22 01:09

Divyesh pal


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" }, 
like image 37
MDev20 Avatar answered Sep 28 '22 01:09

MDev20