Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the test command while creating package.json?

While creating package.json from command line using npm init for creating a module in Node.js, there is a test command field that I don't know about. There's no mention of it in the docs too on executing npm help json also in the CLI.

Please explain what it is about.

like image 266
Aakash Verma Avatar asked Jul 03 '17 07:07

Aakash Verma


People also ask

Which command creates package json?

To create a package. json file with values that you supply, use the npm init command.

Is it npm test or npm run test?

TL;DR there is no difference. It's just a shortcut for npm tests which run the test command in the package. json file. npm run test performs the same action in this case.


1 Answers

The test command is the command that is run whenever you call npm test.

This is important when integrating with continuous integration/continuous deployment tools (such as jenkins, codeship, teamcity).

Example:
- say you deploy a project to AWS or some other cloud hosting provider,
- you can set up your infrastructure to automatically run npm test.
- If there are problems within those tests, your ci/cd will automatically rollback before deploying.

To execute tests
You can use karma, jest, or selenium/nightmare/phantomjs or about any other test scripting library/framework that allows you to write and execute tests and then set the required command in scripts.test and finally run it from npm test.

like image 117
Denis Tsoi Avatar answered Oct 11 '22 06:10

Denis Tsoi