Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does grunt "test command" do on npm init

I'm trying to learn grunt. When I run npm init, I get a prompt in the process of creating a package.json file that asks for "test command" - I'm not sure how to utilize this, or what it's expecting. It doesn't seem to be well documented. If I leave it blank, I get this in the resulting package.json file:

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

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

like image 639
mheavers Avatar asked Jun 15 '13 21:06

mheavers


People also ask

What is Test command npm init?

The test command is an arbitrary command used as a convention to run the testing process. It will always be generated when you run the npm init command.

What is the use of npm test?

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 happens when you run npm test?

Using the command npm run deploy in your terminal will start the publishing process. Prepending pre or post to any run script will automatically run it before or after the root task. In this case, npm run predeploy will automatically run the tests before deploying the project to Surge.


1 Answers

at first, the scripts-property in your package.json has nothing to do with grunt itself. its just a cli-command from npm, wich will be run if you run

$ npm test 

read more about that here: https://npmjs.org/doc/scripts.html

e.g. if you test your application with the grunt & nodeunit you could just add that to the scripts-block

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

and your nodeunit-task is run if you run 'npm test'

this basically makes it easier for continuous integration and so on, if you change your underlying testframework.

of course you could add an alias-task if you need more to be done before and after your tests are run (e.g. concatenation before, cleanup after)

like image 55
hereandnow78 Avatar answered Oct 03 '22 03:10

hereandnow78