A comprehensive set of build tools and configurations for LoopBack 4 and TypeScript projects providing CLI commands for compilation, linting, testing, and coverage
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
NYC code coverage wrapper for generating comprehensive test coverage reports with minimal configuration.
Runs NYC (Istanbul) code coverage tool with passthrough support for all NYC options.
/**
* NYC code coverage function with full option passthrough
* @param argv - Command line arguments including NYC options and target command
* @param options - Execution options for dry run and process control
* @returns ChildProcess when executed, string when dry run
*/
function nyc(argv: string[], options?: RunOptions): ChildProcess | string;CLI Usage:
# Run tests with coverage
lb-nyc npm run mocha
# Run tests with coverage using lb-mocha
lb-nyc lb-mocha "dist/__tests__"
# Generate coverage report
lb-nyc report
# Generate HTML coverage report
lb-nyc report --reporter=html
# Generate LCOV report for CI
lb-nyc report --reporter=text-lcov
# Run with custom configuration
lb-nyc --include "dist/src/**" npm testProgrammatic Usage:
import { nyc } from "@loopback/build";
// Run tests with coverage
const child = nyc(["npm", "run", "mocha"]);
// Dry run to see command
const command = nyc(["--reporter=html", "npm", "test"], { dryRun: true });
console.log(command); // Shows the NYC command that would be executed
// Run coverage in custom directory
nyc(["lb-mocha", "dist/__tests__"], { cwd: "/path/to/project" });Automatically discovers NYC configuration files in the project.
Configuration Search Order:
.nycrc in project root.nycrc.json in project root.nycrc.yaml in project root.nycrc.yml in project rootnyc section in package.json@loopback/build/config/.nycrcDefault Configuration:
// @loopback/build/config/.nycrc contents:
interface NYCConfig {
extension: [".js", ".ts"]; // File extensions to instrument
reporter: ["html"]; // Coverage report format
"exclude-after-remap": false; // Include remapped files in coverage
}Supports all NYC reporters and report generation options.
interface NYCReporters {
"text": string; // Console text output
"text-summary": string; // Brief console summary
"html": string; // HTML report in coverage/ directory
"lcov": string; // LCOV format for tools
"json": string; // JSON format
"json-summary": string; // JSON summary
"cobertura": string; // Cobertura XML format
"teamcity": string; // TeamCity format
"clover": string; // Clover XML format
}Usage Examples:
# Multiple reporters
lb-nyc --reporter=text --reporter=html npm test
# Custom output directory
lb-nyc --report-dir=./coverage-reports npm test
# Generate report from existing data
lb-nyc report --reporter=lcovSeamlessly integrates with various test runners and npm scripts.
With Mocha:
# Using lb-mocha
lb-nyc lb-mocha "dist/__tests__"
# Using npm script
lb-nyc npm run mocha
# Using standard mocha
lb-nyc ./node_modules/.bin/mocha "dist/__tests__"With Jest:
# Using Jest
lb-nyc npm run jest
# Direct Jest execution
lb-nyc jest --coverage=falseSupports coverage threshold enforcement.
interface CoverageThresholds {
"check-coverage": boolean; // Enable threshold checking
"lines": number; // Line coverage threshold
"functions": number; // Function coverage threshold
"branches": number; // Branch coverage threshold
"statements": number; // Statement coverage threshold
}Usage:
# Enforce 80% coverage
lb-nyc --check-coverage --lines 80 --functions 80 --branches 80 --statements 80 npm test
# Per-file thresholds
lb-nyc --check-coverage --per-file --lines 80 npm testFlexible file pattern support for coverage instrumentation.
interface FilePatterns {
"include": string[]; // Glob patterns for files to include
"exclude": string[]; // Glob patterns for files to exclude
"extension": string[]; // File extensions to instrument
}Common Patterns:
# Include only source files
lb-nyc --include "src/**" --exclude "**/*.test.js" npm test
# Exclude test files and node_modules
lb-nyc --exclude "**/test/**" --exclude "**/node_modules/**" npm test
# Include TypeScript and JavaScript
lb-nyc --extension .js --extension .ts npm testAll NYC command line options are supported and passed through.
interface NYCOptions {
"--reporter": string[]; // Coverage reporters to use
"--report-dir": string; // Output directory for reports
"--temp-dir": string; // Temporary directory for coverage data
"--include": string[]; // Files to include in coverage
"--exclude": string[]; // Files to exclude from coverage
"--extension": string[]; // File extensions to instrument
"--check-coverage": boolean; // Enforce coverage thresholds
"--lines": number; // Line coverage threshold
"--functions": number; // Function coverage threshold
"--branches": number; // Branch coverage threshold
"--statements": number; // Statement coverage threshold
"--per-file": boolean; // Apply thresholds per file
"--skip-full": boolean; // Skip files with 100% coverage
"--show-process-tree": boolean; // Show process tree
"--instrument": boolean; // Enable instrumentation
"--source-map": boolean; // Enable source map support
"--produce-source-map": boolean; // Generate source maps
"--all": boolean; // Include all files in report
"--cache": boolean; // Enable instrumentation caching
"--cache-dir": string; // Cache directory location
}Basic Coverage:
import { nyc } from "@loopback/build";
// Run tests with coverage
nyc(["npm", "run", "test"], { dryRun: false });
// Generate HTML report
nyc(["report", "--reporter=html"], { dryRun: false });Package.json Integration:
{
"scripts": {
"test": "lb-mocha \"dist/__tests__\"",
"test:coverage": "lb-nyc npm run test",
"coverage": "npm run test:coverage && open coverage/index.html",
"coverage:ci": "lb-nyc --reporter=text-lcov npm run test | coveralls"
},
"nyc": {
"include": ["dist/src/**"],
"exclude": ["dist/__tests__/"],
"reporter": ["text", "html"],
"check-coverage": true,
"lines": 80,
"functions": 80,
"branches": 80,
"statements": 80
}
}Configuration File Examples:
// .nycrc
{
"include": ["dist/src/**"],
"exclude": [
"dist/__tests__/",
"**/*.d.ts"
],
"extension": [".js", ".ts"],
"reporter": ["text", "html", "lcov"],
"check-coverage": true,
"lines": 85,
"functions": 85,
"branches": 80,
"statements": 85,
"per-file": true,
"all": true,
"cache": true
}Optimized for continuous integration and deployment workflows.
Coverage Upload:
# Generate LCOV for Coveralls
lb-nyc report --reporter=text-lcov | coveralls
# Generate for Codecov
lb-nyc report --reporter=lcovonly
codecov
# Generate for SonarQube
lb-nyc --reporter=lcov --reporter=text-lcov npm testThreshold Enforcement:
# Fail build if coverage is below threshold
lb-nyc --check-coverage --lines 80 --functions 80 --branches 80 --statements 80 npm testProper error handling and reporting for coverage operations.
// Threshold failures exit with non-zero code
// File pattern errors are reported with helpful messages
// Reporter errors show available reporter options
// Configuration errors provide clear guidance