test-as-package is a JavaScript/TypeScript utility designed for testing a local repository as if it were an already deployed npm package. This is particularly useful for internal monorepos or libraries where verifying the consumer-facing behavior, including CLI commands and package exports, is crucial without the need for actual publishing. The current stable version is 2.0.4, with patch releases occurring regularly for dependency updates and minor fixes; major versions are less frequent but typically introduce significant changes. A key differentiator is its ability to pack and install the local package into a temporary Node.js `node_modules` environment without modifying the project's `package.json` or `package-lock.json`, thus ensuring a clean testing environment that closely mirrors an actual installation. It offers both a convenient CLI interface for direct execution of test commands and a programmatic API for more granular control within test suites.
npm install test-as-packageVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to use `runPackageCli` within a test suite to execute your package's CLI, capture its output, and assert against its exit code, stdout, and stderr. This example assumes `@augment-vir/assert` and `@augment-vir/test` are also installed for testing utilities.
Upgrade your Node.js installation to version 22 or newer. Consider using nvm or a similar tool for managing Node.js versions, such as `nvm install 22 && nvm use 22`.
Carefully review the package's GitHub releases page and commit history when upgrading between major versions to identify specific breaking changes and necessary code adjustments.
Always use `npm install --save-dev test-as-package` or `yarn add --dev test-as-package` when adding this package to your project.
Modify your `npm test` script to include your desired test runner, for example: `"test": "test-as-package jest"` or `"test": "test-as-package ts-node path/to/my-tests.ts"`.
Understand that `test-as-package` creates an isolated testing environment. If you need to test actual `package.json` modifications, consider dedicated integration testing against a deployed package or a more elaborate setup.
Ensure `test-as-package` is installed as a dev dependency (`npm i -D test-as-package`) and that your `npm scripts` or shell environment correctly resolves `node_modules/.bin` commands. If running directly, ensure `$(npm bin)/test-as-package` is used or global installation is performed (not generally recommended).
Ensure your project is configured for ESM and use `import { runPackageCli } from 'test-as-package';`. Verify the symbol name `runPackageCli` is spelled correctly and that it is a named export.Update your Node.js environment to version 22 or newer. Use a Node Version Manager (NVM) to switch to or install the required version, e.g., `nvm install 22` and `nvm use 22`.
For type-only imports, ensure you are using `import type { CliOutput } from 'test-as-package';`. Double-check the exact casing and spelling of the type names against the package's type definitions.No dependency data recorded yet.