Source maps support for Istanbul code coverage toolkit, enabling accurate coverage reporting for transpiled JavaScript code
Overall
score
98%
Build a utility that normalizes and resolves file paths from coverage data to ensure consistent file identification across different operating systems and environments.
When processing code coverage data from different environments (Windows vs Unix, containerized vs local, relative vs absolute paths), file paths can vary significantly. Your task is to create a path normalization utility that handles these variations correctly.
Create a module that exports a PathNormalizer class with the following functionality:
The normalizer should convert relative paths to absolute paths based on a configurable base directory:
The normalizer should determine if a given path is absolute:
C:\path\file.js)/path/file.js)The normalizer should resolve paths relative to source files:
The normalizer should generate consistent keys for file paths:
src/utils.js with base /home/user/project produces /home/user/project/src/utils.js @test/home/user/file.js with any base returns /home/user/file.js unchanged @test/home/user/file.js is absolute returns true @testC:\Users\file.js is absolute returns true @testsrc/file.js is absolute returns false @test../lib/helper.js relative to /home/project/src/main.js produces /home/project/lib/helper.js @testC:\project\src\file.js and /project/src/file.js produces normalized, consistent keys @test@generates
/**
* PathNormalizer class for handling file path operations
*/
class PathNormalizer {
/**
* Creates a new PathNormalizer instance
* @param {string} [baseDir] - Base directory for resolving relative paths (defaults to process.cwd())
*/
constructor(baseDir) {
// IMPLEMENTATION HERE
}
/**
* Converts a relative path to an absolute path using the configured base directory
* @param {string} file - The file path to convert
* @returns {string} The absolute path
*/
toAbsolute(file) {
// IMPLEMENTATION HERE
}
/**
* Checks if a path is absolute
* @param {string} file - The file path to check
* @returns {boolean} True if the path is absolute, false otherwise
*/
isAbsolute(file) {
// IMPLEMENTATION HERE
}
/**
* Resolves a file path relative to another file
* @param {string} file - The file path to resolve
* @param {string} referenceFile - The reference file path
* @returns {string} The resolved absolute path
*/
resolveRelativeTo(file, referenceFile) {
// IMPLEMENTATION HERE
}
/**
* Generates a normalized unique key for a pathname
* @param {string} pathname - The file path
* @returns {string} A normalized key for deduplication
*/
getUniqueKey(pathname) {
// IMPLEMENTATION HERE
}
}
module.exports = { PathNormalizer };Provides path resolution utilities for handling file paths across different platforms and environments.
Install with Tessl CLI
npx tessl i tessl/npm-istanbul-lib-source-mapsdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10