CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-loopback--build

A comprehensive set of build tools and configurations for LoopBack 4 and TypeScript projects providing CLI commands for compilation, linting, testing, and coverage

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

code-coverage.mddocs/

Code Coverage

NYC code coverage wrapper for generating comprehensive test coverage reports with minimal configuration.

Capabilities

lb-nyc Command

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 test

Programmatic 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" });

Configuration Discovery

Automatically discovers NYC configuration files in the project.

Configuration Search Order:

  1. .nycrc in project root
  2. .nycrc.json in project root
  3. .nycrc.yaml in project root
  4. .nycrc.yml in project root
  5. nyc section in package.json
  6. Falls back to @loopback/build/config/.nycrc

Default 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
}

Report Generation

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=lcov

Integration with Test Runners

Seamlessly 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=false

Coverage Thresholds

Supports 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 test

File Inclusion and Exclusion

Flexible 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 test

Command Line Option Passthrough

All 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
}

Usage Examples

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
}

CI/CD Integration

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 test

Threshold Enforcement:

# Fail build if coverage is below threshold
lb-nyc --check-coverage --lines 80 --functions 80 --branches 80 --statements 80 npm test

Error Handling

Proper 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

docs

code-coverage.md

code-formatting.md

code-linting.md

file-cleanup.md

index.md

process-management.md

test-execution.md

typescript-compilation.md

tile.json