LinuxCommandLibrary

npm-test

TLDR

Run tests

$ npm test
copy
Run tests with arguments
$ npm test -- --coverage
copy
Run tests silently
$ npm test --silent
copy
Shorthand
$ npm t
copy

SYNOPSIS

npm test [-- args]

DESCRIPTION

npm test runs the "test" script defined in package.json. It's an alias for "npm run test" and is the conventional command for running a project's test suite.
Exit code 0 indicates success; non-zero indicates test failure.

PARAMETERS

--

Pass arguments to test script.
--silent
Reduce output.
--ignore-scripts
Don't run scripts.

PACKAGE.JSON

$ {
  "scripts": {
    "test": "jest",
    "test:watch": "jest --watch",
    "test:coverage": "jest --coverage"
  }
}
copy

COMMON TEST SCRIPTS

$ # Jest
"test": "jest"

# Mocha
"test": "mocha"

# Vitest
"test": "vitest"

# TAP
"test": "tap test/*.js"
copy

CAVEATS

Requires test script to be defined. Default exits with error if no script. Use npm run test:name for custom test scripts.

HISTORY

npm test became the standard test command for Node.js projects, integrated into CI/CD pipelines universally.

SEE ALSO

Copied to clipboard