run
npm test
Shortcut for `npm run test` — runs the `test` script from package.json. Aliases: `npm t`, `npm tst`.
npm test [-- <args>] Common flags
| Flag | Purpose |
|---|---|
| -- | Forward flags to the test runner (Jest, Vitest, Mocha) |
| --workspaces (-ws) | Run test in every workspace that defines one |
| --if-present | No-op when the script is missing (useful in monorepos) |
| --silent | Suppress npm's framing output |
Examples
npm test Run the project's test script
npm t -- --coverage Pass --coverage through to Jest/Vitest
npm test -ws --if-present Run tests across every workspace that has one
Gotcha
Like `start`, `npm test` is sugar for `npm run test`, so `pretest`/`posttest` scripts still execute. Runner-specific flags MUST come after `--` or npm will try to interpret them.
Related commands
npm run
Executes a script from the `scripts` block of package.json in a shell where node_modules/.bin is on PATH. Alias: `run-script`; running `npm run` with no arg lists every available script.
npm start
Shortcut for `npm run start` — runs the `start` script from package.json. If no `start` script is defined, npm falls back to `node server.js`.
npm ci
Performs a clean, deterministic install straight from package-lock.json (or npm-shrinkwrap.json) intended for CI environments. It deletes any existing node_modules and refuses to run if package.json and the lockfile are out of sync.
npm exec (npx)
Runs a package's binary from a local install, the cache, or on-the-fly from the registry without a global install. `npx` is the shell-friendly shim; both are equivalent in npm 10+.