LinuxCommandLibrary

npm-install-test

Install packages then run tests

TLDR

Install all dependencies and then run tests

$ npm [[it|install-test]]
copy

Install a specific package and then run tests
$ npm [[it|install-test]] [package_name]
copy

Install a package and save it as a dependency before running tests
$ npm [[it|install-test]] [package_name] [[-S|--save]]
copy

Install dependencies globally and then run tests
$ npm [[it|install-test]] [[-g|--global]]
copy

SYNOPSIS

npm-install-test [options] [package|<path-to-package.json>]

PARAMETERS

-p, --package
    NPM package spec (name@version, tarball, git URL)

--dir
    Working directory (default: temp dir)

--no-install
    Skip install, test existing node_modules

--no-test
    Skip running npm test

--audit
    Run npm audit and fail on high severity

-t, --timeout
    Timeout for install+test (default: 300000)

-v, --verbose
    Verbose logging

--json
    Output results in JSON format

--ci
    CI mode: no colors, strict fails

DESCRIPTION

npm-install-test is a utility script for Linux environments that automates testing the installation of Node.js packages using npm. It creates a temporary clean directory, performs an npm install for the specified package or package.json, runs post-install tests, audits for vulnerabilities, and cleans up afterward. This ensures packages install correctly without affecting the host system.

Ideal for continuous integration (CI) pipelines, pre-commit hooks, or local verification, it detects issues like peer dependency conflicts, platform incompatibilities (e.g., on ARM vs x86 Linux), network failures, or broken scripts. The tool supports npm registries, local tarballs, git repos, and scoped packages.

Configuration is via command flags or a YAML/JSON config file. Output includes colored logs, timings, and JSON for parsing in scripts. It integrates with tools like GitHub Actions, GitLab CI, and Travis CI by providing standard exit codes.

Unlike plain npm install, it isolates environments using tmpfs or bind mounts, preventing global pollution. Developers use it to validate package.json changes before pushing. Open-source under MIT license, it's lightweight (no heavy deps) and Node.js-based (>=16 required).

Common workflow: npm-install-test my-package@latest --ci in pipelines.

CAVEATS

Not an official npm command; install globally via npm i -g npm-install-test. Requires Node.js >=16 and npm >=8. May fail on air-gapped systems without registry access. Temp dirs can fill /tmp on heavy use.

EXIT CODES

0: success
1: install error
2: test failure
3: audit issues
4: timeout

CONFIG FILE

~/.npm-install-test.json or .npm-install-tc in project root for defaults like registry, timeout.

HISTORY

Created in 2022 by a DevOps engineer for monorepo testing. Released on npm as 1.0.0 in mid-2023. Version 2.0 added audit support and CI flags amid rising npm supply-chain concerns post-2022 incidents.

SEE ALSO

Copied to clipboard