Set up comprehensive frontend testing infrastructure

- Install Jest for unit testing with React Testing Library
- Install Playwright for end-to-end testing
- Configure Jest with proper TypeScript support and module mapping
- Create test setup files and utilities for both unit and e2e tests

Components:
* Jest configuration with coverage thresholds
* Playwright configuration with browser automation
* Unit tests for LoginForm, AuthContext, and useSocketIO hook
* E2E tests for authentication, dashboard, and agents workflows
* GitHub Actions workflow for automated testing
* Mock data and API utilities for consistent testing
* Test documentation with best practices

Testing features:
- Unit tests with 70% coverage threshold
- E2E tests with API mocking and user journey testing
- CI/CD integration for automated test runs
- Cross-browser testing support with Playwright
- Authentication system testing end-to-end

🚀 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
anthonyrawlins
2025-07-11 14:06:34 +10:00
parent c6d69695a8
commit aacb45156b
6109 changed files with 777927 additions and 1 deletions

View File

@@ -0,0 +1,353 @@
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [4.0.0](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-source-maps@4.0.0-alpha.5...istanbul-lib-source-maps@4.0.0) (2019-12-20)
**Note:** Version bump only for package istanbul-lib-source-maps
# [4.0.0-alpha.5](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-source-maps@4.0.0-alpha.4...istanbul-lib-source-maps@4.0.0-alpha.5) (2019-12-07)
**Note:** Version bump only for package istanbul-lib-source-maps
# [4.0.0-alpha.4](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-source-maps@4.0.0-alpha.3...istanbul-lib-source-maps@4.0.0-alpha.4) (2019-11-16)
### Bug Fixes
* sourceFinder cannot be async. ([#501](https://github.com/istanbuljs/istanbuljs/issues/501)) ([094f1b8](https://github.com/istanbuljs/istanbuljs/commit/094f1b83b4652c5ba492781620cb6358c685a849))
# [4.0.0-alpha.3](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-source-maps@4.0.0-alpha.2...istanbul-lib-source-maps@4.0.0-alpha.3) (2019-11-15)
### Bug Fixes
* mappedCoverage.addStatement is not a function ([#500](https://github.com/istanbuljs/istanbuljs/issues/500)) ([d77cc14](https://github.com/istanbuljs/istanbuljs/commit/d77cc147f7d791686af2975f7d906603335d0bfc)), closes [istanbuljs/nyc#940](https://github.com/istanbuljs/nyc/issues/940)
# [4.0.0-alpha.2](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-source-maps@4.0.0-alpha.1...istanbul-lib-source-maps@4.0.0-alpha.2) (2019-10-09)
### Features
* Convert to async API ([#489](https://github.com/istanbuljs/istanbuljs/issues/489)) ([f8ebbc9](https://github.com/istanbuljs/istanbuljs/commit/f8ebbc9))
### BREAKING CHANGES
* MapStore#transformCoverage is now async and returns a
the coverage data only. The `sourceFinder` method is now async and
provided directly on the `MapStore` instance.
# [4.0.0-alpha.1](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-source-maps@4.0.0-alpha.0...istanbul-lib-source-maps@4.0.0-alpha.1) (2019-10-06)
### Bug Fixes
* **package:** update rimraf to version 3.0.0 ([b6e7953](https://github.com/istanbuljs/istanbuljs/commit/b6e7953))
### Features
* Accept SourceStore and sourceStoreOpts options ([#482](https://github.com/istanbuljs/istanbuljs/issues/482)) ([0dc45a6](https://github.com/istanbuljs/istanbuljs/commit/0dc45a6))
* Add addInputSourceMapsSync and getSourceMapSync methods ([#484](https://github.com/istanbuljs/istanbuljs/issues/484)) ([dd7048e](https://github.com/istanbuljs/istanbuljs/commit/dd7048e))
### BREAKING CHANGES
* sourceStore and tmpdir options are removed.
# [4.0.0-alpha.0](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-source-maps@3.0.6...istanbul-lib-source-maps@4.0.0-alpha.0) (2019-06-19)
### Features
* Update dependencies, require Node.js 8 ([#401](https://github.com/istanbuljs/istanbuljs/issues/401)) ([bf3a539](https://github.com/istanbuljs/istanbuljs/commit/bf3a539))
### BREAKING CHANGES
* Node.js 8 is now required
## [5.0.6](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-source-maps-v5.0.5...istanbul-lib-source-maps-v5.0.6) (2024-07-02)
### Bug Fixes
* `istanbul-lib-source-maps` implicit `else` crash edge case ([#789](https://github.com/istanbuljs/istanbuljs/issues/789)) ([bbb5815](https://github.com/istanbuljs/istanbuljs/commit/bbb5815a62f293151447a9e1b4363382a8bf3a2f))
## [5.0.5](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-source-maps-v5.0.4...istanbul-lib-source-maps-v5.0.5) (2024-07-01)
### Bug Fixes
* `istanbul-lib-source-maps` to preserve implicit `else` when sourcemaps are used ([#706](https://github.com/istanbuljs/istanbuljs/issues/706)) ([d16a155](https://github.com/istanbuljs/istanbuljs/commit/d16a155b24bd137803779ad3772b4ea3f265a96f))
## [5.0.4](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-source-maps-v5.0.3...istanbul-lib-source-maps-v5.0.4) (2024-02-26)
### Bug Fixes
* handle missing source map ([1c2017d](https://github.com/istanbuljs/istanbuljs/commit/1c2017d5a3e20ef5725b77a8e4d76eff84b9a62f))
## [5.0.3](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-source-maps-v5.0.2...istanbul-lib-source-maps-v5.0.3) (2024-02-26)
### Bug Fixes
* correct CI check to properly release 5.0.1 ([a39fdfe](https://github.com/istanbuljs/istanbuljs/commit/a39fdfe3a2082ba82ef4243840bcffe10737a40f))
## [5.0.2](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-source-maps-v5.0.1...istanbul-lib-source-maps-v5.0.2) (2024-02-26)
### Bug Fixes
* correct CI badge in source-maps readme ([78aa783](https://github.com/istanbuljs/istanbuljs/commit/78aa783a54760b79d7e6d0f6e0d8c6c481b690d7))
## [5.0.1](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-source-maps-v5.0.0...istanbul-lib-source-maps-v5.0.1) (2024-02-26)
### Bug Fixes
* use `allGeneratedPositionsFor` for more accurate source map transforms ([#771](https://github.com/istanbuljs/istanbuljs/issues/771)) ([dde947c](https://github.com/istanbuljs/istanbuljs/commit/dde947c6ee808b54ebf1ba4faea1f89c43ef3df6))
## [5.0.0](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-source-maps-v4.0.1...istanbul-lib-source-maps-v5.0.0) (2024-02-26)
### ⚠ BREAKING CHANGES
* replace source-map with @jridgewell/trace-mapping ([#685](https://github.com/istanbuljs/istanbuljs/issues/685))
### Bug Fixes
* use `allGeneratedPositionsFor` for more accurate source map transforms ([#768](https://github.com/istanbuljs/istanbuljs/issues/768)) ([c6d0982](https://github.com/istanbuljs/istanbuljs/commit/c6d0982e960f6aed85d9f4c7d1da3b6479bb2272))
### Code Refactoring
* replace source-map with @jridgewell/trace-mapping ([#685](https://github.com/istanbuljs/istanbuljs/issues/685)) ([293f8b9](https://github.com/istanbuljs/istanbuljs/commit/293f8b97767e0a09646ef7a28543a13ffd92074d))
### [4.0.1](https://www.github.com/istanbuljs/istanbuljs/compare/istanbul-lib-source-maps-v4.0.0...istanbul-lib-source-maps-v4.0.1) (2021-10-12)
### Bug Fixes
* source mapping for branch statements ([#518](https://www.github.com/istanbuljs/istanbuljs/issues/518)) ([3833708](https://www.github.com/istanbuljs/istanbuljs/commit/38337081d97baa6295707d569dee9c4abc3f7da7))
## [3.0.6](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-source-maps@3.0.5...istanbul-lib-source-maps@3.0.6) (2019-04-24)
### Bug Fixes
* if LEAST_UPPER_BOUND returns null, try GREATEST_LOWER_BOUND ([#375](https://github.com/istanbuljs/istanbuljs/issues/375)) ([72b0f05](https://github.com/istanbuljs/istanbuljs/commit/72b0f05))
## [3.0.5](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-source-maps@3.0.4...istanbul-lib-source-maps@3.0.5) (2019-04-09)
**Note:** Version bump only for package istanbul-lib-source-maps
## [3.0.4](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-source-maps@3.0.3...istanbul-lib-source-maps@3.0.4) (2019-04-03)
**Note:** Version bump only for package istanbul-lib-source-maps
## [3.0.3](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-source-maps@3.0.2...istanbul-lib-source-maps@3.0.3) (2019-03-12)
### Bug Fixes
* Map unique files once, regardless of path separator ([#287](https://github.com/istanbuljs/istanbuljs/issues/287)) ([39a1e56](https://github.com/istanbuljs/istanbuljs/commit/39a1e56))
## [3.0.2](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-source-maps@3.0.1...istanbul-lib-source-maps@3.0.2) (2019-01-26)
**Note:** Version bump only for package istanbul-lib-source-maps
<a name="3.0.1"></a>
## [3.0.1](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-source-maps@3.0.0...istanbul-lib-source-maps@3.0.1) (2018-12-25)
### Bug Fixes
* correct variable name in source-map transform ([#257](https://github.com/istanbuljs/istanbuljs/issues/257)) ([de9c921](https://github.com/istanbuljs/istanbuljs/commit/de9c921))
<a name="3.0.0"></a>
# [3.0.0](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-source-maps@2.0.1...istanbul-lib-source-maps@3.0.0) (2018-12-19)
### Bug Fixes
* correctly calculate end position of sourcemap statement ([f97ffc7](https://github.com/istanbuljs/istanbuljs/commit/f97ffc7))
### BREAKING CHANGES
* coverage output can now contain Infinity, when a range extends past the source in a file.
<a name="2.0.1"></a>
## [2.0.1](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-source-maps@2.0.0...istanbul-lib-source-maps@2.0.1) (2018-07-07)
**Note:** Version bump only for package istanbul-lib-source-maps
<a name="2.0.0"></a>
# [2.0.0](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-source-maps@1.2.5...istanbul-lib-source-maps@2.0.0) (2018-06-06)
### Bug Fixes
* use null prototype for map objects ([#177](https://github.com/istanbuljs/istanbuljs/issues/177)) ([9a5a30c](https://github.com/istanbuljs/istanbuljs/commit/9a5a30c))
### BREAKING CHANGES
* a null prototype is now used in several places rather than the default `{}` assignment.
<a name="1.2.5"></a>
## [1.2.5](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-source-maps@1.2.4...istanbul-lib-source-maps@1.2.5) (2018-05-31)
### Bug Fixes
* process.cwd is a function not a string ([#163](https://github.com/istanbuljs/istanbuljs/issues/163)). ([#171](https://github.com/istanbuljs/istanbuljs/issues/171)) ([9c7802c](https://github.com/istanbuljs/istanbuljs/commit/9c7802c))
<a name="1.2.4"></a>
## [1.2.4](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-source-maps@1.2.3...istanbul-lib-source-maps@1.2.4) (2018-03-04)
**Note:** Version bump only for package istanbul-lib-source-maps
<a name="1.2.3"></a>
## [1.2.3](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-source-maps@1.2.2...istanbul-lib-source-maps@1.2.3) (2018-02-13)
**Note:** Version bump only for package istanbul-lib-source-maps
<a name="1.2.2"></a>
## [1.2.2](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-source-maps@1.2.1...istanbul-lib-source-maps@1.2.2) (2017-10-21)
**Note:** Version bump only for package istanbul-lib-source-maps
<a name="1.2.1"></a>
## [1.2.1](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-source-maps@1.2.0...istanbul-lib-source-maps@1.2.1) (2017-05-27)
<a name="1.2.0"></a>
# [1.2.0](https://github.com/istanbuljs/istanbul-lib-source-maps/compare/istanbul-lib-source-maps@1.1.1...istanbul-lib-source-maps@1.2.0) (2017-04-29)
### Features
* pull in debug module, to make debug messages optional ([#36](https://github.com/istanbuljs/istanbuljs/issues/36)) ([189519d](https://github.com/istanbuljs/istanbul-lib-source-maps/commit/189519d))
<a name="1.1.1"></a>
## [1.1.1](https://github.com/istanbuljs/istanbul-lib-source-maps/compare/istanbul-lib-source-maps@1.1.0...istanbul-lib-source-maps@1.1.1) (2017-03-27)
<a name="1.1.0"></a>
# [1.1.0](https://github.com/istanbuljs/istanbul-lib-source-maps/compare/v1.0.2...v1.1.0) (2016-11-10)
### Features
* read and apply any input source maps stored with coverage data ([#4](https://github.com/istanbuljs/istanbul-lib-source-maps/issues/4)) ([aea405b](https://github.com/istanbuljs/istanbul-lib-source-maps/commit/aea405b))
<a name="1.0.2"></a>
## [1.0.2](https://github.com/istanbuljs/istanbul-lib-source-maps/compare/v1.0.1...v1.0.2) (2016-10-03)
### Bug Fixes
* broken mapped coverage report ([#6](https://github.com/istanbuljs/istanbul-lib-source-maps/issues/6)) ([d9dd738](https://github.com/istanbuljs/istanbul-lib-source-maps/commit/d9dd738))
<a name="1.0.1"></a>
## [1.0.1](https://github.com/istanbuljs/istanbul-lib-source-maps/compare/v1.0.0...v1.0.1) (2016-09-13)
### Bug Fixes
* position validation shouldn't throw away locations with 0 ([#5](https://github.com/istanbuljs/istanbul-lib-source-maps/issues/5)) ([ac4b72c](https://github.com/istanbuljs/istanbul-lib-source-maps/commit/ac4b72c))
<a name="1.0.0"></a>
# [1.0.0](https://github.com/istanbuljs/istanbul-lib-source-maps/compare/v1.0.0-alpha.9...v1.0.0) (2016-08-31)
### Bug Fixes
* discard more bad source map positions ([#3](https://github.com/istanbuljs/istanbul-lib-source-maps/issues/3)) ([ed7b27f](https://github.com/istanbuljs/istanbul-lib-source-maps/commit/ed7b27f))

24
frontend/node_modules/istanbul-lib-source-maps/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,24 @@
Copyright 2015 Yahoo! Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Yahoo! Inc. nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL YAHOO! INC. BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@@ -0,0 +1,10 @@
# istanbul-lib-source-maps
[![Build Status](https://img.shields.io/github/actions/workflow/status/istanbuljs/istanbuljs/ci.yml?label=CI&logo=GitHub)](https://github.com/istanbuljs/istanbuljs/actions/workflows/ci.yml)
Source map support for istanbuljs.
## Debugging
`istanbul-lib-source-maps` uses the [debug](https://www.npmjs.com/package/debug) module. Run your application with the environment variable `DEBUG=istanbuljs`, to receive debug
output.

View File

@@ -0,0 +1,15 @@
/*
Copyright 2012-2015, Yahoo Inc.
Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
*/
'use strict';
const { MapStore } = require('./lib/map-store');
/**
* @module Exports
*/
module.exports = {
createSourceMapStore(opts) {
return new MapStore(opts);
}
};

View File

@@ -0,0 +1,184 @@
/*
Copyright 2015, Yahoo Inc.
Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
*/
'use strict';
const pathutils = require('./pathutils');
const {
originalPositionFor,
allGeneratedPositionsFor,
GREATEST_LOWER_BOUND,
LEAST_UPPER_BOUND
} = require('@jridgewell/trace-mapping');
/**
* AST ranges are inclusive for start positions and exclusive for end positions.
* Source maps are also logically ranges over text, though interacting with
* them is generally achieved by working with explicit positions.
*
* When finding the _end_ location of an AST item, the range behavior is
* important because what we're asking for is the _end_ of whatever range
* corresponds to the end location we seek.
*
* This boils down to the following steps, conceptually, though the source-map
* library doesn't expose primitives to do this nicely:
*
* 1. Find the range on the generated file that ends at, or exclusively
* contains the end position of the AST node.
* 2. Find the range on the original file that corresponds to
* that generated range.
* 3. Find the _end_ location of that original range.
*/
function originalEndPositionFor(sourceMap, generatedEnd) {
// Given the generated location, find the original location of the mapping
// that corresponds to a range on the generated file that overlaps the
// generated file end location. Note however that this position on its
// own is not useful because it is the position of the _start_ of the range
// on the original file, and we want the _end_ of the range.
const beforeEndMapping = originalPositionTryBoth(
sourceMap,
generatedEnd.line,
generatedEnd.column - 1
);
if (beforeEndMapping.source === null) {
return null;
}
// Convert that original position back to a generated one, with a bump
// to the right, and a rightward bias. Since 'generatedPositionFor' searches
// for mappings in the original-order sorted list, this will find the
// mapping that corresponds to the one immediately after the
// beforeEndMapping mapping.
const afterEndMappings = allGeneratedPositionsFor(sourceMap, {
source: beforeEndMapping.source,
line: beforeEndMapping.line,
column: beforeEndMapping.column + 1,
bias: LEAST_UPPER_BOUND
});
for (let i = 0; i < afterEndMappings.length; i++) {
const afterEndMapping = afterEndMappings[i];
if (afterEndMapping.line === null) continue;
const original = originalPositionFor(sourceMap, afterEndMapping);
// If the lines match, it means that something comes after our mapping,
// so it must end where this one begins.
if (original.line === beforeEndMapping.line) return original;
}
// If a generated mapping wasn't found (or all that were found were not on
// the same line), then there's nothing after this range and we can
// consider it to extend to infinity.
return {
source: beforeEndMapping.source,
line: beforeEndMapping.line,
column: Infinity
};
}
/**
* Attempts to determine the original source position, first
* returning the closest element to the left (GREATEST_LOWER_BOUND),
* and next returning the closest element to the right (LEAST_UPPER_BOUND).
*/
function originalPositionTryBoth(sourceMap, line, column) {
const mapping = originalPositionFor(sourceMap, {
line,
column,
bias: GREATEST_LOWER_BOUND
});
if (mapping.source === null) {
return originalPositionFor(sourceMap, {
line,
column,
bias: LEAST_UPPER_BOUND
});
} else {
return mapping;
}
}
function isInvalidPosition(pos) {
return (
!pos ||
typeof pos.line !== 'number' ||
typeof pos.column !== 'number' ||
pos.line < 0 ||
pos.column < 0
);
}
/**
* determines the original position for a given location
* @param {SourceMapConsumer} sourceMap the source map
* @param {Object} generatedLocation the original location Object
* @returns {Object} the remapped location Object
*/
function getMapping(sourceMap, generatedLocation, origFile) {
if (!generatedLocation) {
return null;
}
if (
isInvalidPosition(generatedLocation.start) ||
isInvalidPosition(generatedLocation.end)
) {
return null;
}
const start = originalPositionTryBoth(
sourceMap,
generatedLocation.start.line,
generatedLocation.start.column
);
let end = originalEndPositionFor(sourceMap, generatedLocation.end);
/* istanbul ignore if: edge case too hard to test for */
if (!(start && end)) {
return null;
}
if (!(start.source && end.source)) {
return null;
}
if (start.source !== end.source) {
return null;
}
/* istanbul ignore if: edge case too hard to test for */
if (start.line === null || start.column === null) {
return null;
}
/* istanbul ignore if: edge case too hard to test for */
if (end.line === null || end.column === null) {
return null;
}
if (start.line === end.line && start.column === end.column) {
end = originalPositionFor(sourceMap, {
line: generatedLocation.end.line,
column: generatedLocation.end.column,
bias: LEAST_UPPER_BOUND
});
end.column -= 1;
}
return {
source: pathutils.relativeTo(start.source, origFile),
loc: {
start: {
line: start.line,
column: start.column
},
end: {
line: end.line,
column: end.column
}
}
};
}
module.exports = getMapping;

View File

@@ -0,0 +1,228 @@
/*
Copyright 2015, Yahoo Inc.
Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
*/
'use strict';
const path = require('path');
const fs = require('fs');
const debug = require('debug')('istanbuljs');
const { TraceMap, sourceContentFor } = require('@jridgewell/trace-mapping');
const pathutils = require('./pathutils');
const { SourceMapTransformer } = require('./transformer');
/**
* Tracks source maps for registered files
*/
class MapStore {
/**
* @param {Object} opts [opts=undefined] options.
* @param {Boolean} opts.verbose [opts.verbose=false] verbose mode
* @param {String} opts.baseDir [opts.baseDir=null] alternate base directory
* to resolve sourcemap files
* @param {Class} opts.SourceStore [opts.SourceStore=Map] class to use for
* SourceStore. Must support `get`, `set` and `clear` methods.
* @param {Array} opts.sourceStoreOpts [opts.sourceStoreOpts=[]] arguments
* to use in the SourceStore constructor.
* @constructor
*/
constructor(opts) {
opts = {
baseDir: null,
verbose: false,
SourceStore: Map,
sourceStoreOpts: [],
...opts
};
this.baseDir = opts.baseDir;
this.verbose = opts.verbose;
this.sourceStore = new opts.SourceStore(...opts.sourceStoreOpts);
this.data = Object.create(null);
this.sourceFinder = this.sourceFinder.bind(this);
}
/**
* Registers a source map URL with this store. It makes some input sanity checks
* and silently fails on malformed input.
* @param transformedFilePath - the file path for which the source map is valid.
* This must *exactly* match the path stashed for the coverage object to be
* useful.
* @param sourceMapUrl - the source map URL, **not** a comment
*/
registerURL(transformedFilePath, sourceMapUrl) {
const d = 'data:';
if (
sourceMapUrl.length > d.length &&
sourceMapUrl.substring(0, d.length) === d
) {
const b64 = 'base64,';
const pos = sourceMapUrl.indexOf(b64);
if (pos > 0) {
this.data[transformedFilePath] = {
type: 'encoded',
data: sourceMapUrl.substring(pos + b64.length)
};
} else {
debug(`Unable to interpret source map URL: ${sourceMapUrl}`);
}
return;
}
const dir = path.dirname(path.resolve(transformedFilePath));
const file = path.resolve(dir, sourceMapUrl);
this.data[transformedFilePath] = { type: 'file', data: file };
}
/**
* Registers a source map object with this store. Makes some basic sanity checks
* and silently fails on malformed input.
* @param transformedFilePath - the file path for which the source map is valid
* @param sourceMap - the source map object
*/
registerMap(transformedFilePath, sourceMap) {
if (sourceMap && sourceMap.version) {
this.data[transformedFilePath] = {
type: 'object',
data: sourceMap
};
} else {
debug(
'Invalid source map object: ' +
JSON.stringify(sourceMap, null, 2)
);
}
}
/**
* Retrieve a source map object from this store.
* @param filePath - the file path for which the source map is valid
* @returns {Object} a parsed source map object
*/
getSourceMapSync(filePath) {
try {
if (!this.data[filePath]) {
return;
}
const d = this.data[filePath];
if (d.type === 'file') {
return JSON.parse(fs.readFileSync(d.data, 'utf8'));
}
if (d.type === 'encoded') {
return JSON.parse(Buffer.from(d.data, 'base64').toString());
}
/* The caller might delete properties */
return {
...d.data
};
} catch (error) {
debug('Error returning source map for ' + filePath);
debug(error.stack);
return;
}
}
/**
* Add inputSourceMap property to coverage data
* @param coverageData - the __coverage__ object
* @returns {Object} a parsed source map object
*/
addInputSourceMapsSync(coverageData) {
Object.entries(coverageData).forEach(([filePath, data]) => {
if (data.inputSourceMap) {
return;
}
const sourceMap = this.getSourceMapSync(filePath);
if (sourceMap) {
data.inputSourceMap = sourceMap;
/* This huge property is not needed. */
delete data.inputSourceMap.sourcesContent;
}
});
}
sourceFinder(filePath) {
const content = this.sourceStore.get(filePath);
if (content !== undefined) {
return content;
}
if (path.isAbsolute(filePath)) {
return fs.readFileSync(filePath, 'utf8');
}
return fs.readFileSync(
pathutils.asAbsolute(filePath, this.baseDir),
'utf8'
);
}
/**
* Transforms the coverage map provided into one that refers to original
* sources when valid mappings have been registered with this store.
* @param {CoverageMap} coverageMap - the coverage map to transform
* @returns {Promise<CoverageMap>} the transformed coverage map
*/
async transformCoverage(coverageMap) {
const hasInputSourceMaps = coverageMap
.files()
.some(
file => coverageMap.fileCoverageFor(file).data.inputSourceMap
);
if (!hasInputSourceMaps && Object.keys(this.data).length === 0) {
return coverageMap;
}
const transformer = new SourceMapTransformer(
async (filePath, coverage) => {
try {
const obj =
coverage.data.inputSourceMap ||
this.getSourceMapSync(filePath);
if (!obj) {
return null;
}
const smc = new TraceMap(obj);
smc.sources.forEach(s => {
if (s) {
const content = sourceContentFor(smc, s);
if (content) {
const sourceFilePath = pathutils.relativeTo(
s,
filePath
);
this.sourceStore.set(sourceFilePath, content);
}
}
});
return smc;
} catch (error) {
debug('Error returning source map for ' + filePath);
debug(error.stack);
return null;
}
}
);
return await transformer.transform(coverageMap);
}
/**
* Disposes temporary resources allocated by this map store
*/
dispose() {
this.sourceStore.clear();
}
}
module.exports = { MapStore };

View File

@@ -0,0 +1,113 @@
/*
Copyright 2015, Yahoo Inc.
Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
*/
'use strict';
const { FileCoverage } = require('istanbul-lib-coverage').classes;
function locString(loc) {
return [
loc.start.line,
loc.start.column,
loc.end.line,
loc.end.column
].join(':');
}
class MappedCoverage extends FileCoverage {
constructor(pathOrObj) {
super(pathOrObj);
this.meta = {
last: {
s: 0,
f: 0,
b: 0
},
seen: {}
};
}
addStatement(loc, hits) {
const key = 's:' + locString(loc);
const { meta } = this;
let index = meta.seen[key];
if (index === undefined) {
index = meta.last.s;
meta.last.s += 1;
meta.seen[key] = index;
this.statementMap[index] = this.cloneLocation(loc);
}
this.s[index] = this.s[index] || 0;
this.s[index] += hits;
return index;
}
addFunction(name, decl, loc, hits) {
const key = 'f:' + locString(decl);
const { meta } = this;
let index = meta.seen[key];
if (index === undefined) {
index = meta.last.f;
meta.last.f += 1;
meta.seen[key] = index;
name = name || `(unknown_${index})`;
this.fnMap[index] = {
name,
decl: this.cloneLocation(decl),
loc: this.cloneLocation(loc)
};
}
this.f[index] = this.f[index] || 0;
this.f[index] += hits;
return index;
}
addBranch(type, loc, branchLocations, hits) {
const key = ['b', ...branchLocations.map(l => locString(l))].join(':');
const { meta } = this;
let index = meta.seen[key];
if (index === undefined) {
index = meta.last.b;
meta.last.b += 1;
meta.seen[key] = index;
this.branchMap[index] = {
loc,
type,
locations: branchLocations.map(l => this.cloneLocation(l))
};
}
if (!this.b[index]) {
this.b[index] = branchLocations.map(() => 0);
}
hits.forEach((hit, i) => {
this.b[index][i] += hit;
});
return index;
}
/* Returns a clone of the location object with only the attributes of interest */
cloneLocation(loc) {
return {
start: {
line: loc.start.line,
column: loc.start.column
},
end: {
line: loc.end.line,
column: loc.end.column
}
};
}
}
module.exports = {
MappedCoverage
};

View File

@@ -0,0 +1,21 @@
/*
Copyright 2015, Yahoo Inc.
Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
*/
'use strict';
const path = require('path');
module.exports = {
isAbsolute: path.isAbsolute,
asAbsolute(file, baseDir) {
return path.isAbsolute(file)
? file
: path.resolve(baseDir || process.cwd(), file);
},
relativeTo(file, origFile) {
return path.isAbsolute(file)
? file
: path.resolve(path.dirname(origFile), file);
}
};

View File

@@ -0,0 +1,21 @@
/*
Copyright 2015, Yahoo Inc.
Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
*/
'use strict';
function getUniqueKey(pathname) {
return pathname.replace(/[\\/]/g, '_');
}
function getOutput(cache) {
return Object.values(cache).reduce(
(output, { file, mappedCoverage }) => ({
...output,
[file]: mappedCoverage
}),
{}
);
}
module.exports = { getUniqueKey, getOutput };

View File

@@ -0,0 +1,160 @@
/*
Copyright 2015, Yahoo Inc.
Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
*/
'use strict';
const debug = require('debug')('istanbuljs');
const libCoverage = require('istanbul-lib-coverage');
const { MappedCoverage } = require('./mapped');
const getMapping = require('./get-mapping');
const { getUniqueKey, getOutput } = require('./transform-utils');
class SourceMapTransformer {
constructor(finder, opts = {}) {
this.finder = finder;
this.baseDir = opts.baseDir || process.cwd();
this.resolveMapping = opts.getMapping || getMapping;
}
processFile(fc, sourceMap, coverageMapper) {
let changes = 0;
Object.entries(fc.statementMap).forEach(([s, loc]) => {
const hits = fc.s[s];
const mapping = this.resolveMapping(sourceMap, loc, fc.path);
if (mapping) {
changes += 1;
const mappedCoverage = coverageMapper(mapping.source);
mappedCoverage.addStatement(mapping.loc, hits);
}
});
Object.entries(fc.fnMap).forEach(([f, fnMeta]) => {
const hits = fc.f[f];
const mapping = this.resolveMapping(
sourceMap,
fnMeta.decl,
fc.path
);
const spanMapping = this.resolveMapping(
sourceMap,
fnMeta.loc,
fc.path
);
if (
mapping &&
spanMapping &&
mapping.source === spanMapping.source
) {
changes += 1;
const mappedCoverage = coverageMapper(mapping.source);
mappedCoverage.addFunction(
fnMeta.name,
mapping.loc,
spanMapping.loc,
hits
);
}
});
Object.entries(fc.branchMap).forEach(([b, branchMeta]) => {
const hits = fc.b[b];
const locs = [];
const mappedHits = [];
let source;
let skip;
branchMeta.locations.forEach((loc, i) => {
const mapping = this.resolveMapping(sourceMap, loc, fc.path);
if (mapping) {
if (!source) {
source = mapping.source;
}
if (mapping.source !== source) {
skip = true;
}
locs.push(mapping.loc);
mappedHits.push(hits[i]);
}
// Check if this is an implicit else
else if (
source &&
branchMeta.type === 'if' &&
i > 0 &&
loc.start.line === undefined &&
loc.start.end === undefined &&
loc.end.line === undefined &&
loc.end.end === undefined
) {
locs.push(loc);
mappedHits.push(hits[i]);
}
});
const locMapping = branchMeta.loc
? this.resolveMapping(sourceMap, branchMeta.loc, fc.path)
: null;
if (!skip && locs.length > 0) {
changes += 1;
const mappedCoverage = coverageMapper(source);
mappedCoverage.addBranch(
branchMeta.type,
locMapping ? locMapping.loc : locs[0],
locs,
mappedHits
);
}
});
return changes > 0;
}
async transform(coverageMap) {
const uniqueFiles = {};
const getMappedCoverage = file => {
const key = getUniqueKey(file);
if (!uniqueFiles[key]) {
uniqueFiles[key] = {
file,
mappedCoverage: new MappedCoverage(file)
};
}
return uniqueFiles[key].mappedCoverage;
};
for (const file of coverageMap.files()) {
const fc = coverageMap.fileCoverageFor(file);
const sourceMap = await this.finder(file, fc);
if (sourceMap) {
const changed = this.processFile(
fc,
sourceMap,
getMappedCoverage
);
if (!changed) {
debug(`File [${file}] ignored, nothing could be mapped`);
}
} else {
uniqueFiles[getUniqueKey(file)] = {
file,
mappedCoverage: new MappedCoverage(fc)
};
}
}
return libCoverage.createCoverageMap(getOutput(uniqueFiles));
}
}
module.exports = {
SourceMapTransformer
};

View File

@@ -0,0 +1,45 @@
{
"name": "istanbul-lib-source-maps",
"version": "5.0.6",
"description": "Source maps support for istanbul",
"author": "Krishnan Anantheswaran <kananthmail-github@yahoo.com>",
"main": "index.js",
"files": [
"lib",
"index.js"
],
"scripts": {
"test": "nyc mocha"
},
"dependencies": {
"@jridgewell/trace-mapping": "^0.3.23",
"debug": "^4.1.1",
"istanbul-lib-coverage": "^3.0.0"
},
"devDependencies": {
"chai": "^4.2.0",
"mocha": "^6.2.2",
"nyc": "^15.0.0-beta.2",
"ts-node": "^8.5.4"
},
"license": "BSD-3-Clause",
"bugs": {
"url": "https://github.com/istanbuljs/istanbuljs/issues"
},
"homepage": "https://istanbul.js.org/",
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/istanbuljs/istanbuljs.git",
"directory": "packages/istanbul-lib-source-maps"
},
"keywords": [
"istanbul",
"sourcemaps",
"sourcemap",
"source",
"maps"
],
"engines": {
"node": ">=10"
}
}