npm test is the conventional npm command for running a project's automated tests. Its meaning comes from the package.json test script, so the same command can invoke different testing tools. section 9.5.8 section 10.6.2
Configure the command by defining a test script:
- Set "test" to "jest" to run Jest tests. section 9.5.8
- Set "test" to a Playwright command when the project uses Playwright; a single worker may be required when tests share a database. section 9.8.6
- Add a separate test:watch script for Jest live reload; this is a personal convention rather than an npm standard. section 9.5.8
Run end-to-end tests
Install the monorepo dependencies, start the complete application, wait for the gateway to come online, then run npm test in a new terminal. The command invokes Playwright and reports the UI test results. section 10.6.2
Listing 9.4 Package.json with npm scripts for running Jest
{
"name": "example-1",
"version": "1.0.0",
"scripts": {
"test": "jest", #1
"test:watch": "jest --watchAll" #2
},
"devDependencies": {
"jest": "^29.6.4" #3
},
"dependencies": {
#4
}
}
Inspect a complete package.json example showing Jest and test:watch scripts. section 9.5.8
