Skip to content

Latest commit

 

History

History
193 lines (145 loc) · 5.33 KB

File metadata and controls

193 lines (145 loc) · 5.33 KB

Containerized Testing

This project enforces container-only testing to ensure consistent, reproducible test environments across all development platforms. All testing is performed through Docker Compose with Podman priority, eliminating platform-specific inconsistencies.

🚀 Quick Start

Prerequisites

Install Podman (recommended) or Docker:

# Podman (recommended)
brew install podman
podman machine start

# OR Docker
brew install --cask docker

Running Tests

# Run all tests
pnpm test

# Run tests with coverage
pnpm test:coverage

# Run tests in watch mode
pnpm test:watch

All test commands automatically run in Linux containers, ensuring identical environments regardless of your host platform.

🏗️ Architecture

Container Stack

  • Base Image: node:22-alpine3.19 (Alpine Linux 3.19 + Node.js 22)
  • Runtime: Podman (priority) with Docker Compose fallback
  • Orchestration: Docker Compose with volume mounting
  • Isolation: Full Linux container environment

Key Features

  • Platform Consistency: 100% Linux container execution
  • Zero Local Dependencies: No native testing on host machines
  • Fast Iteration: Optimized layer caching and volume mounting
  • Developer Experience: One-command testing workflows

📁 File Structure

├── Dockerfile                    # Testing container definition
├── docker-compose.yml           # Container orchestration
├── scripts/container-test.js    # Container detection & execution
├── package.json                # Container-only test scripts
└── .dockerignore              # Build optimization

🛠️ Container Configuration

Dockerfile

  • Base: node:22-alpine3.19
  • Dependencies: Native addon build tools (gcc, make, python3)
  • Security: Non-root node user
  • Optimization: Layer caching and .dockerignore

Docker Compose Services

  • node-syslog-test: Standard testing
  • node-syslog-test-watch: Watch mode development
  • node-syslog-coverage: Coverage reporting

Container Detection

The scripts/container-test.js automatically:

  1. Detects Podman (preferred) or Docker
  2. Validates Docker Compose availability
  3. Builds container image with caching
  4. Executes tests in isolated environment

🎯 Benefits

For Developers

  • Consistent Environment: Same Linux container everywhere
  • No Setup Hassles: Works out of the box on macOS, Linux, Windows
  • Fast Performance: Optimized for sub-10-second startup
  • IDE Integration: Full debugging and watch support

For CI/CD

  • Environment Parity: Local containers match GitHub Actions
  • Reliable Testing: No platform-specific flakiness
  • Consistent Results: Identical test runs everywhere

🔧 Advanced Usage

Direct Container Access

# Access container shell
podman-compose run --rm node-syslog-test bash

# Build container manually
podman build -t node-syslog-test .

# Run specific tests
podman-compose run --rm node-syslog-test pnpm vitest test/syslog.test.ts

Environment Variables

  • CONTAINERIZED: Set to true inside containers
  • FORCE_COLOR: Preserves colored output
  • CI=true: Enables CI-optimized behavior

Volume Mounting

  • Project: /app (live code changes)
  • Dependencies: Separate node_modules volume
  • Coverage: Mounted to host ./coverage

🐛 Troubleshooting

Common Issues

Podman not found

brew install podman
podman machine start

Permission denied

# Fix volume permissions
podman-compose run --rm node-syslog-test chown -R node:node /app

Container build fails

# Clear cache and rebuild
podman system prune -f
pnpm test  # Triggers rebuild

Slow performance

  • Ensure SSD storage
  • Check available RAM (minimum 4GB recommended)
  • Verify Podman machine resources

Debug Mode

Enable verbose logging:

NODE_ENV=development pnpm test

🔄 Migration from Local Testing

If migrating from local testing:

  1. No Local Tests: All pnpm test commands now run in containers
  2. Same Interface: Existing commands work unchanged
  3. Better Results: More reliable, consistent testing

Breaking Changes

  • Tests no longer run directly on host machines
  • Native addon compilation happens in containers
  • Platform-specific test differences eliminated

📊 Performance

Benchmarks

  • Cold Start: ~8-12 seconds (including build)
  • Warm Start: ~2-3 seconds (cached layers)
  • Test Execution: ~200-300ms (20 tests)
  • Memory Usage: ~200-300MB per container

Optimization Features

  • Layer Caching: Reuses unchanged dependencies
  • Volume Mounting: Live code updates without rebuilds
  • Parallel Execution: Multiple containers can run simultaneously

🚦 Status

  • Core Testing: Fully functional
  • Coverage Reports: Working with volume mounting
  • Watch Mode: Development-ready
  • CI/CD Integration: GitHub Actions compatible
  • 🔄 Native Addon: Mocked during container testing
  • 🔄 Performance: Ongoing optimization

🤝 Contributing

When contributing:

  1. All tests must pass in containers: pnpm test
  2. Ensure container compatibility
  3. Test on multiple platforms if possible
  4. Document any container-specific requirements

Containerized testing ensures consistent, reliable development for all contributors.