What does the validation command mean for npm init

I'm trying to learn how to grunt. When I run npm init, I get a prompt in the process of creating a package.json file that asks for the "test" command - I'm not sure how to use this or what it expects. This does not seem to be well documented. If I leave it empty, I get this in the resulting package.json file:

"scripts": { //"test": "echo \"Error: no test specified\" && exit 1" }, 

Can someone shed some light on how to set up a test script?

+61
javascript package gruntjs
Jun 15 '13 at 21:16
source share
2 answers

first the scripts property in your package. json has nothing to do with grunting. its just a cli command from npm that will run if you run

 $ npm test 

Find out more about it here: https://npmjs.org/doc/scripts.html

eg. if you test your application with grunt and nodeunit you can just add this to the script block

 "scripts": { "test": "grunt nodeunit" } 

and your nodeunit task runs if you run "npm test"

this basically simplifies continuous integration, etc. if you change the basic test circuit.

Of course, you could add a task alias if you need to do more before and after running your tests (for example, concatenating before, cleaning after)

+42
Jun 15 '13 at 21:47
source share

As mentioned in the answer above, you can run your test command when you specify it when creating the json package from cmd or manually edit the json file. Basically, according to npm docs, it is used to run the provided script package test.

npm docs test

In my case, the Iam using it to test an angular application using Jasmine (spec.js files) can be found in this article: -

Getting started with Node.js and Jasmine

0
Sep 12 '17 at 19:28
source share



All Articles