npm-install-test
Install packages then run tests
TLDR
Install all dependencies and then run tests
Install a specific package and then run tests
Install a package and save it as a dependency before running tests
Install dependencies globally and then run tests
SYNOPSIS
npm install-test [
PARAMETERS
--production
Install production dependencies only, skipping devDependencies. This is useful for deployment environments where development tools are not needed.
--prefix
Run this command in the context of the specified directory rather than the current working directory. All file system operations will be relative to this path.
--ignore-scripts
Do not run any preinstall, install, postinstall, pretest, or posttest scripts. This can be useful for security or debugging issues related to script execution.
--loglevel
Sets the level of logging output. Common levels include silent, error, warn, http, info (default), verbose, and silly.
--force
Forces npm install to fetch remote resources even if a local copy exists and to overwrite existing files. For npm test, it doesn't have a direct effect unless combined with other actions.
--dry-run
Shows what would be done without actually making any changes to the file system or executing scripts. Useful for previewing changes.
--workspace
Runs the command in the context of a specific workspace, identified by its name. Requires the project to be set up with npm workspaces.
--workspaces, -ws
Runs the command in the context of all configured workspaces. Often used to install dependencies or run tests across an entire monorepo.
DESCRIPTION
npm install-test is a convenience command that streamlines the common workflow of setting up a project's dependencies and then executing its test suite. It first performs a clean installation of all project dependencies, including any specified package-spec arguments, much like npm install. After a successful installation, it proceeds to run the test scripts defined in the project's package.json file, mirroring the behavior of npm test.
This command is particularly useful in continuous integration (CI) environments, local development for quick verification, or after pulling changes from a version control system, ensuring that the project's state is valid and all necessary components are in place before validating functionality through tests. It provides a single point of entry to perform both crucial steps sequentially.
CAVEATS
The command requires a valid package.json file in the current or specified directory, with defined dependencies and a 'test' script under the 'scripts' section. If either the installation or the test phase fails, the command will exit with a non-zero status code, indicating an error. While convenient, for complex scenarios or specific control over each phase, executing npm install followed by npm test separately might offer more flexibility.
EXIT STATUS
The command exits with code 0 on success. A non-zero exit code indicates that either the dependency installation failed or one or more tests did not pass. This makes it suitable for use in shell scripts and automated build processes to determine the success or failure of a project's setup and validation.
CONFIGURATION
Like other npm commands, npm install-test respects various configuration settings found in .npmrc files, environment variables, or command-line flags. This includes registry settings, proxy configurations, log levels, and other behaviors that influence how dependencies are fetched and how scripts are executed.
HISTORY
The npm install-test command was introduced as a convenience subcommand to address a common development and CI/CD pattern. Prior to its existence, users would typically execute npm install && npm test as two separate commands. Its inclusion in npm reflects an ongoing effort to simplify frequently performed operations and improve developer experience by providing more semantic, single-command solutions for common workflows.


