๐งช Multi-Project Testing Engine (@nest-yalc-2/jest)
@nest-yalc-2/jest provides a multi-project test runner, custom matchers, SWC compiler integration, and HTML coverage report servers for NestJS monorepos.
๐ Key Featuresโ
- Multi-Project Jest Orchestration: Runs unit, integration, and E2E tests across dozens of monorepo sub-packages in parallel using Jest Projects.
- SWC Fast Compilation (
@swc/jest): Compiles TypeScript test files up to 10x faster than traditionalts-jest. - Coverage Server CLI (
npm run test:cov:serve): Serves interactive LCOV coverage HTML reports locally. - Custom Assertions: Provides NestJS and TypeORM specific test assertions.
๐ฌ Internal Architecture & Execution Mechanicsโ
flowchart TD
TestCommand["npm run test:cov"]
JestRunner["@nest-yalc-2/jest Multi-Project Orchestrator"]
SwcCompiler["@swc/jest Compiler Worker Pool"]
CoverageGen["LCOV Coverage Aggregator"]
HttpServer["http-server (:8080) LCOV Report Stream"]
TestCommand --> JestRunner
JestRunner --> SwcCompiler
SwcCompiler --> CoverageGen
CoverageGen --> HttpServer
๐ Architectural Comparison: @nest-yalc-2/jest vs Standard Jestโ
| Feature / Dimension | ๐งช @nest-yalc-2/jest (SWC) | ๐ข Standard ts-jest |
|---|---|---|
| Compilation Speed | SWC (~1.2s execution) | ts-jest (~12.5s execution) |
| Monorepo Project Runner | Native Multi-Project Setup | Single Config / Manual Projects |
| Coverage HTML Server | Built-in (npm run test:cov:serve) | Manual External Web Server |
๐ Practical Usage & Production Code Examplesโ
1. Running Test Suite Commandsโ
# Run unit tests across all monorepo modules
npm test
# Run tests with code coverage
npm run test:cov
# Serve interactive LCOV report at http://127.0.0.1:8080/
npm run test:cov:serve
2. Writing Unit Tests with @nest-yalc-2/jestโ
import { Test, TestingModule } from '@nestjs/testing';
import { UserManagementService } from './user-management.service';
describe('UserManagementService', () => {
let service: UserManagementService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [UserManagementService],
}).compile();
service = module.get<UserManagementService>(UserManagementService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});
โ ๏ธ Common Pitfalls & Anti-Patternsโ
[!CAUTION] Using
--no-cachein CI Pipelines: Disabling Jest cache in CI pipelines causes unnecessary SWC recompilations. Keep Jest caching enabled to maximize pipeline speed.
๐ก Best Practicesโ
[!TIP] 100% Coverage Threshold Enforcement: Configure CI pipelines with
npm run ci:checksto fail builds automatically if coverage drops below the required 100% threshold on core domain modules.