What is the test command when creating package.json?

When creating package.json from the command line using npm init to create a module in Node.js there is a test command field that I do not know about. There is also no mention of this in the docs also when running npm help json also in the CLI.

Please explain what this means.

+8
source share
2 answers

test command is a command that runs whenever you call npm test .

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

Example:
- say that you are deploying a project for AWS or some other cloud hosting provider,
- you can configure your infrastructure to run npm test automatically.
- If there are problems during these tests, your ci / cd will automatically roll back to deployment.

Test execution
You can use karma, jest or selenium / nightmare / phantomjs or any other scripting script library / environment that allows you to write and run tests, and then install the required command in the scripts.test file and finally run it from npm test .

+6
source share

Assuming you mean scripts.test :

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

This field contains the program (/ command line) that should run when npm test called. Typically, this program is a tester like mocha , ava , jest , ...

The default value is a placeholder that prints an error message (try running npm test in the same directory as your package.json ).

+3
source share

All Articles