Skip to main content

Testing Guide

How to run tests in the AI Primitives Hub extension.

For test writing patterns (style, helpers, anti-patterns, deduplication rules), see test/AGENTS.md. This file covers commands and tooling only.

Testing Architecture

The project uses a two-tier test layout, both running under Mocha TDD style (suite / test / assert):

TierLocationRuns InPurpose
Unit / Property / E2E (mocked)test/{services,adapters,commands,ui,utils,storage,e2e}/**/*.test.tsNode.js with vscode mocked via test/mocha.setup.jsPure logic, data flow, multi-component workflows
Integration (real VS Code)test/suite/**/*.test.tsElectron via test/runExtensionTests.jsExtension activation, command registration, UI wiring

Tests compile to test-dist/ first (npm run compile-tests) — Mocha runs the compiled JS.

Quick Start

# All tests (unit + integration)
LOG_LEVEL=ERROR npm test

# Unit / property / e2e only (no VS Code host)
LOG_LEVEL=ERROR npm run test:unit

# Integration tests (real VS Code)
npm run test:integration

# Single file (auto-compiles)
npm run test:one -- test/services/bundle-installer.test.ts

# Coverage
npm run test:coverage # all tests
npm run test:coverage:unit # unit only, c8 html report
npm run test:coverage:integration # integration only

Use LOG_LEVEL=ERROR to suppress debug output.

Test Directory Layout

test/
├── adapters/ # Adapter unit tests
├── commands/ # Command handler tests
├── services/ # Service layer tests
├── storage/ # Storage tests
├── ui/ # UI component tests
├── utils/ # Utility tests
├── e2e/ # Multi-component workflow tests (mocked VS Code)
├── suite/ # Real VS Code integration tests
├── fixtures/ # Test data and mock responses
├── helpers/ # Shared test utilities
├── mocks/ # Mock implementations
├── mocha.setup.js # Mocks `require('vscode')` before tests load
└── vscode-mock.js # VS Code API mock implementation

Test Types

TypeSuffixPurpose
Unit.test.tsSingle component
Property.property.test.tsInvariant testing with fast-check
E2Etest/e2e/*.test.tsMulti-component workflows (mocked VS Code)
Integrationtest/suite/*.test.tsReal VS Code extension host

Debugging

LOG_LEVEL=DEBUG npm run test:one -- test/path/to/test.ts

# Capture for analysis
LOG_LEVEL=ERROR npm test 2>&1 | tee test.log | tail -20

Coverage

npm run test:coverage:unit # c8 html output in coverage/

Coverage reports are written to the coverage/ directory.

See Also