liveBook · Manning

Npm test

As explained in Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform

npm test is the conventional npm command for running a project's automated tests.

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

How Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform covers it

How deep it goes
Explains package.json mapping, Jest and Playwright invocation, watch-mode conventions, and shared-database worker constraints.
Examples
Uses Jest unit-test projects, Playwright projects, and a full FlixTube application with a shared database.
What it assumes
Assumes a Node.js project with package.json and a configured test script; teaches the conventional command from its initial introduction.
What you can do after
Operate automated tests through one memorable command without knowing the project's testing framework.
How it connects
Connects npm scripts with package.json, Jest, Playwright, automated testing, end-to-end testing, and watch mode.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform. The section links point to the parts of the book it draws on.