CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-istanbul-lib-source-maps

Source maps support for Istanbul code coverage toolkit, enabling accurate coverage reporting for transpiled JavaScript code

Overall
score

98%

Overview
Eval results
Files

task.mdevals/scenario-1/

Source Map Coverage Debugger

Build a tool that processes JavaScript code coverage data and provides detailed diagnostic information about source map issues. The tool should help developers understand why coverage mapping might be failing for their transpiled code.

Requirements

Your tool should:

  1. Accept a coverage map object containing coverage data for transpiled JavaScript files
  2. Accept a list of source map registrations (file paths and their corresponding source map URLs or objects)
  3. Process the coverage data and detect any problems with source map handling
  4. Provide detailed diagnostic output including:
    • Successfully registered source maps
    • Failed source map registrations (with reasons)
    • Files that have coverage but no associated source maps
    • Invalid or malformed source map data
  5. Enable verbose diagnostic logging when a DEBUG flag is enabled
  6. Handle errors gracefully without throwing exceptions - log issues and continue processing

Implementation Details

Create a file src/debugger.js that exports a CoverageDebugger class with the following interface:

class CoverageDebugger {
  constructor(options)
  registerSourceMap(filePath, sourceMapUrlOrObject)
  analyzeCoverage(coverageMap)
  getReport()
}

The constructor should accept an options object with:

  • verbose: boolean flag for detailed logging (defaults to false)

The registerSourceMap method should:

  • Accept a file path and either a source map URL string or a source map object
  • Handle both inline source maps (data URLs) and file-based source maps
  • Log registration failures without throwing errors

The analyzeCoverage method should:

  • Process a coverage map object
  • Check each file in the coverage data for associated source maps
  • Detect and log any issues (missing maps, invalid maps, etc.)
  • Return a summary object with counts of processed files, successful mappings, and errors

The getReport method should return a detailed report object containing:

  • registered: array of successfully registered source maps
  • failed: array of failed registrations with error details
  • unmapped: array of files with coverage but no source maps
  • stats: object with numerical summaries

Test Cases

Create tests in src/debugger.test.js:

Test Case 1: Valid Source Map Registration { .test }

Input:

const debugger = new CoverageDebugger({ verbose: false })
debugger.registerSourceMap('/path/to/bundle.js', {
  version: 3,
  sources: ['original.js'],
  mappings: 'AAAA'
})

Expected Output: The report should show 1 successfully registered source map for /path/to/bundle.js

Test Case 2: Invalid Source Map Detection { .test }

Input:

const debugger = new CoverageDebugger({ verbose: false })
debugger.registerSourceMap('/path/to/file.js', { invalid: 'data' })

Expected Output: The report should show 1 failed registration with an error indicating invalid source map format

Test Case 3: Coverage Without Source Maps { .test }

Input:

const debugger = new CoverageDebugger({ verbose: false })
const coverageMap = {
  '/app/bundle.js': {
    path: '/app/bundle.js',
    statementMap: { '0': { start: { line: 1, column: 0 }, end: { line: 1, column: 10 } } },
    s: { '0': 1 }
  }
}
debugger.analyzeCoverage(coverageMap)

Expected Output: The report should show /app/bundle.js in the unmapped files list

Test Case 4: Graceful Error Handling { .test }

Input:

const debugger = new CoverageDebugger({ verbose: false })
debugger.registerSourceMap('/path/to/file.js', 'data:invalid-format')
debugger.registerSourceMap('/path/to/file2.js', null)

Expected Output: No exceptions should be thrown; both failures should be logged in the failed registrations list

Dependencies { .dependencies }

istanbul-lib-source-maps { .dependency }

Provides source map support for Istanbul code coverage, including source map registration, validation, and diagnostic capabilities.

Install with Tessl CLI

npx tessl i tessl/npm-istanbul-lib-source-maps

tile.json