JSPM

@kitiumai/npm-package-tester

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 75
  • Score
    100M100P100Q11692F
  • License MIT

AI-powered CLI testing tool for npm packages with Docker isolation, private package support, and automated test generation using Claude, GPT-4, Gemini

Package Exports

  • @kitiumai/npm-package-tester
  • @kitiumai/npm-package-tester/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@kitiumai/npm-package-tester) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

npm-package-tester

npm version License: MIT TypeScript Node.js Version PRs Welcome GitHub issues GitHub stars

๐Ÿงช 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


Table of Contents


The Problem

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.

The Solution

npm-package-tester automatically:

  1. ๐Ÿ“ฆ Analyzes your package.json to detect CLI commands
  2. ๐Ÿณ Creates fresh Docker containers with specified Node versions
  3. ๐Ÿ“ฅ Installs your package
  4. ๐Ÿงช Runs each CLI command with common flags (--help, --version, etc.)
  5. โœ… Reports which commands work and which don't

Features

  • ๐Ÿ” 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

Quick Start

# 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

Example Output

Default Testing

๐Ÿ“ฆ 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!

AI-Powered Testing

๐Ÿ“ฆ 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!

How It Works

1. Command Detection

// Reads package.json
{
  "name": "my-cli-tool",
  "bin": {
    "mycli": "./dist/cli.js",      // Primary command
    "my": "./dist/cli.js"           // Alias
  }
}

// Detects: mycli, my

2. Docker Environment

# Spins up for each Node version
FROM node:20-alpine
RUN npm install -g my-cli-tool
RUN mycli --help
RUN mycli --version

3. Smart Testing

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

Use Cases

1. Pre-Publish Validation

# Before publishing
npm run build
npt test .
npm publish

2. CI/CD Integration

# .github/workflows/test.yml
- name: Test CLI
  run: |
    npm install -g npm-package-tester
    npt test . --node 16,18,20

3. Testing Published Packages

# Verify your package works after publishing
npt test your-package-name@latest

4. Debugging Installation Issues

# Keep containers to inspect
npt test . --keep-containers
docker exec -it <container-id> sh

Configuration

Create .npmtestrc.json:

{
  "nodeVersions": ["16", "18", "20"],
  "parallel": true,
  "timeout": 30000,
  "customTests": [
    {
      "name": "Generate help",
      "command": "mycli generate --help",
      "expect": {
        "exitCode": 0,
        "stdout": "Usage:"
      }
    }
  ]
}

API Usage

import { testPackage } from 'npm-package-tester';

const results = await testPackage('eslint', {
  nodeVersions: ['20'],
  parallel: false,
});

console.log(`Passed: ${results.passed}/${results.total}`);

CLI Options

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

AI-Powered Testing

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:

  1. ๐Ÿ“– Analyze the package README and CLI help
  2. ๐Ÿง  Understand what the package does
  3. ๐ŸŽฏ Generate realistic test scenarios with:
    • Appropriate input files
    • Realistic command arguments
    • Expected output validation
  4. โœ… 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 โœ…

Supported AI Providers

Provider Model Setup
Anthropic Claude Sonnet 4.5 Get key from console.anthropic.com
OpenAI GPT-4o Get key from platform.openai.com
Google 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.

Testing Private Packages

npm-package-tester fully supports private npm packages with authentication:

Using npm Token

# 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

Using Custom Registry

# Test from private registry (like Verdaccio, Artifactory, GitHub Packages)
npt test @company/package \
  --npm-registry https://npm.company.com \
  --npm-token YOUR_REGISTRY_TOKEN

How it Works

  1. The tool creates a .npmrc file in the Docker container
  2. Configures authentication with your token
  3. Installs the package securely
  4. Runs all tests normally

Security Note: Tokens are only used within isolated Docker containers and are not stored or logged.

Supported Registries

  • โœ… npm (private packages)
  • โœ… GitHub Packages
  • โœ… GitLab Package Registry
  • โœ… Verdaccio
  • โœ… JFrog Artifactory
  • โœ… Azure Artifacts
  • โœ… Any npm-compatible registry

Architecture

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

Clean Architecture

  • 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)

Requirements

  • Docker installed and running
  • Node.js >= 16
  • npm or yarn
  • (Optional) AI provider API key for intelligent test generation

Limitations

  • 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

Roadmap

  • 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

Contributing

We welcome contributions! Here's how you can help:

Ways to Contribute

  • ๐Ÿ› 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

Development Setup

# Clone the repository
git clone https://github.com/kitium-ai/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

Guidelines

  • 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

Code of Conduct

Be respectful, inclusive, and constructive. We're all here to learn and build great tools together!

License

MIT ยฉ Ashish Yadav

Support


Made with โค๏ธ for npm package authors

โญ Star us on GitHub if you find this useful!