π§ͺ Automatically test npm packages by discovering their CLI commands and running them in isolated Docker environments
π€ AI-Powered: Generate realistic test scenarios using Claude, GPT-4, Gemini, or Groq π Private Packages: Full support for private npm packages and custom registries β‘ Fast & Reliable: Run tests in parallel across multiple Node versions
- The Problem
- The Solution
- Features
- Quick Start
- Example Output
- AI-Powered Testing
- Testing Private Packages
- CLI Options
- How It Works
- Use Cases
- Configuration
- API Usage
- Architecture
- Requirements
- Contributing
- License
When you publish an npm package with CLI commands, you need to verify:
- β Does it install correctly?
- β Do all CLI commands work?
- β Does it work across different Node versions?
- β Does the --help flag work?
- β Does the --version flag work?
- β Does it run without crashing?
Manual testing is tedious and error-prone.
npm-package-tester
automatically:
- π¦ Analyzes your package.json to detect CLI commands
- π³ Creates fresh Docker containers with specified Node versions
- π₯ Installs your package
- π§ͺ Runs each CLI command with common flags (--help, --version, etc.)
- β Reports which commands work and which don't
- π Auto-Discovery: Automatically detects all CLI commands from
package.json
- π³ Docker Isolation: Tests in clean environments
- π Multi-Version: Test across Node 16, 18, 20, etc.
- β‘ Parallel Testing: Run tests concurrently for speed
- π Detailed Reports: Clear pass/fail results with complete test breakdown
- π― Smart Testing: Automatically tries --help, --version, and no-args
- π€ AI-Powered Scenarios: Generate realistic test scenarios using Claude, GPT-4, Gemini, or Groq
- π Private Packages: Full support for private npm packages with authentication
- π¦ Custom Registries: Works with private npm registries
- π¨ Lightweight: Minimal dependencies, fast execution
# Install globally
npm install -g npm-package-tester
# Test a package from npm
npt test eslint
# Test your local package
npt test ./my-package
# Test across multiple Node versions
npt test prettier --node 16,18,20
# AI-powered intelligent testing (generates realistic scenarios)
npt test env-type-generator --ai-provider anthropic --ai-token YOUR_API_KEY
# Use OpenAI instead
npt test my-package --ai-provider openai --ai-token YOUR_OPENAI_KEY
# Test private packages
npt test @your-org/private-package --npm-token YOUR_NPM_TOKEN
# Test from custom registry
npt test @company/package --npm-registry https://npm.company.com --npm-token YOUR_TOKEN
# Keep containers for debugging
npt test --keep-containers
π¦ Package: eslint
Version: 8.50.0
π³ Node 20
β eslint --help (125ms)
β eslint --version (98ms)
β eslint [no args] (102ms)
π Summary
ββββββββββββββββββββββββββββββββββββββββββββββββββ
Total: 3 tests
Passed: 3
Failed: 0
Duration: 325ms
π Test Details
ββββββββββββββββββββββββββββββββββββββββββββββββββ
π― Default Tests
β eslint --help (125ms)
β eslint --version (98ms)
β eslint (no args) (102ms)
β
All tests passed!
π¦ Package: env-type-generator
Version: 1.0.0
Auto-generate TypeScript types from .env files with zero config
π³ Node 20
β env-type-gen (1512ms)
β env-type-gen (4871ms)
β env-type-gen (1307ms)
π Summary
ββββββββββββββββββββββββββββββββββββββββββββββββββ
Total: 3 tests
Passed: 3
Failed: 0
Duration: 7690ms
π Test Details
ββββββββββββββββββββββββββββββββββββββββββββββββββ
π€ AI-Generated Tests
β basic-type-generation (1512ms)
β multiple-env-files-with-parsing -e .env .env.local -p (4871ms)
β strict-mode-all-required -e .env.example -o ./types/env.d.ts (1307ms)
β
All tests passed!
// Reads package.json
{
"name": "my-cli-tool",
"bin": {
"mycli": "./dist/cli.js", // Primary command
"my": "./dist/cli.js" // Alias
}
}
// Detects: mycli, my
# Spins up for each Node version
FROM node:20-alpine
RUN npm install -g my-cli-tool
RUN mycli --help
RUN mycli --version
For each command, automatically tests:
command --help
(should show help)command --version
(should show version)command
(no args - should not crash)- Custom scenarios you define
# Before publishing
npm run build
npt test .
npm publish
# .github/workflows/test.yml
- name: Test CLI
run: |
npm install -g npm-package-tester
npt test . --node 16,18,20
# Verify your package works after publishing
npt test your-package-name@latest
# Keep containers to inspect
npt test . --keep-containers
docker exec -it <container-id> sh
Create .npmtestrc.json
:
{
"nodeVersions": ["16", "18", "20"],
"parallel": true,
"timeout": 30000,
"customTests": [
{
"name": "Generate help",
"command": "mycli generate --help",
"expect": {
"exitCode": 0,
"stdout": "Usage:"
}
}
]
}
import { testPackage } from 'npm-package-tester';
const results = await testPackage('eslint', {
nodeVersions: ['20'],
parallel: false,
});
console.log(`Passed: ${results.passed}/${results.total}`);
Usage: npt test [options] <package>
Options:
-n, --node <versions> Node versions (comma-separated)
-p, --parallel Run tests in parallel
-k, --keep-containers Keep containers after test
-t, --timeout <ms> Timeout per test (default: 30000)
--npm-token <token> npm authentication token for private packages
--npm-registry <url> Custom npm registry URL
--ai-provider <provider> AI provider (anthropic, openai, google, groq)
--ai-token <token> AI API token/key
--ai-model <model> AI model name (optional, auto-detects best)
--no-help Skip --help tests
--no-version Skip --version tests
-v, --verbose Verbose output
Instead of just testing --help
and --version
, use AI to generate realistic test scenarios:
npt test env-type-generator --ai-provider anthropic --ai-token YOUR_TOKEN
The AI will:
- π Analyze the package README and CLI help
- π§ Understand what the package does
- π― Generate realistic test scenarios with:
- Appropriate input files
- Realistic command arguments
- Expected output validation
- β Validate file creation, content, and exit codes
Example AI-Generated Scenarios:
π€ Generating test scenarios with AI...
β¨ Generated 4 AI test scenarios
π³ Node 20
β basic-env-file-generation (1400ms)
β env-with-comments (1706ms)
β nested-env-variables (5040ms)
β strict-mode-with-custom-output (1517ms)
π 4/4 tests passed β
Provider | Model | Setup |
---|---|---|
Anthropic | Claude Sonnet 4.5 | Get key from console.anthropic.com |
OpenAI | GPT-4o | Get key from platform.openai.com |
Gemini 2.0 Flash | Get key from ai.google.dev | |
Groq | Llama 3.3 70B | Get key from console.groq.com |
The best model for each provider is automatically selected.
npm-package-tester
fully supports private npm packages with authentication:
# Test private package from npm registry
npt test @your-org/private-package --npm-token YOUR_NPM_TOKEN
# Get your npm token from ~/.npmrc or create one with:
# npm token create --read-only
# Test from private registry (like Verdaccio, Artifactory, GitHub Packages)
npt test @company/package \
--npm-registry https://npm.company.com \
--npm-token YOUR_REGISTRY_TOKEN
- The tool creates a
.npmrc
file in the Docker container - Configures authentication with your token
- Installs the package securely
- Runs all tests normally
Security Note: Tokens are only used within isolated Docker containers and are not stored or logged.
- β npm (private packages)
- β GitHub Packages
- β GitLab Package Registry
- β Verdaccio
- β JFrog Artifactory
- β Azure Artifacts
- β Any npm-compatible registry
npm-package-tester
βββ PackageAnalyzer # Reads package.json, detects commands
βββ CommandDetector # Identifies CLI binaries
βββ DockerManager # Creates/manages containers
βββ TestRunner # Executes commands in containers
βββ ScenarioRunner # Runs AI-generated test scenarios
βββ ScenarioGenerator # Generates scenarios using AI
βββ AIProvider # Multi-provider AI abstraction (Claude, GPT-4, Gemini, Groq)
βββ ResultFormatter # Pretty output
βββ CLI # User interface
- Domain: Types, interfaces (no dependencies)
- Application: Business logic (PackageAnalyzer, TestRunner, ScenarioRunner)
- AI: AI providers and scenario generation
- Infrastructure: Docker, file system (external concerns)
- CLI: User interface (commander, chalk)
- Docker installed and running
- Node.js >= 16
- npm or yarn
- (Optional) AI provider API key for intelligent test generation
- Only tests packages with CLI commands
- Requires Docker (no Windows native support yet)
- Can't test interactive prompts automatically
- Network-dependent (pulls Docker images)
- AI features require API credits
- AI-powered test scenario generation
- Multi-provider AI support (Anthropic, OpenAI, Google, Groq)
- Support testing interactive CLIs
- Cloud runners (no local Docker needed)
- Performance benchmarking
- Screenshot/visual testing for TUI apps
- Windows native support (WSL2)
- Custom Docker images
- CI/CD badges
- Historical test tracking
We welcome contributions! Here's how you can help:
- π Report Bugs: Create a bug report
- π‘ Suggest Features: Request a feature
- π Improve Documentation: Fix typos, add examples, clarify instructions
- π§ͺ Add Tests: Increase test coverage
- π§ Fix Issues: Check out good first issues
# Clone the repository
git clone https://github.com/ashishyd/npm-package-tester.git
cd npm-package-tester
# Install dependencies
npm install
# Build the project
npm run build
# Run tests
npm test
# Run linting
npm run lint
- Follow the existing code style
- Write tests for new features
- Update documentation as needed
- Ensure all tests pass before submitting PR
- Keep PRs focused on a single feature or bug fix
Be respectful, inclusive, and constructive. We're all here to learn and build great tools together!
MIT Β© Ashish Yadav
- testcontainers - Integration testing with Docker
- verdaccio - Private npm registry
- np - Better npm publish
- π Documentation
- π¬ GitHub Discussions
- π Issue Tracker
- π§ Email
Made with β€οΈ for npm package authors
β Star us on GitHub if you find this useful!