Socket
Socket
Sign inDemoInstall

@web/test-runner-coverage-v8

Package Overview
Dependencies
192
Maintainers
7
Versions
46
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.0-canary-20230420104136 to 0.0.0-canary-20231122093600

2

dist/index.d.ts

@@ -5,5 +5,5 @@ /// <reference types="node" />

import { Profiler } from 'inspector';
declare type V8Coverage = Profiler.ScriptCoverage;
type V8Coverage = Profiler.ScriptCoverage;
export declare function v8ToIstanbul(config: TestRunnerCoreConfig, testFiles: string[], coverage: V8Coverage[], userAgent?: string): Promise<CoverageMapData>;
export { V8Coverage };
//# sourceMappingURL=index.d.ts.map

@@ -1,21 +0,25 @@

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.v8ToIstanbul = void 0;
const path_1 = require("path");
const v8_to_istanbul_1 = __importDefault(require("v8-to-istanbul"));
const test_runner_core_1 = require("@web/test-runner-core");
const picomatch_1 = __importDefault(require("picomatch"));
const lru_cache_1 = __importDefault(require("lru-cache"));
const utils_1 = require("./utils");
import { extname, join, isAbsolute, sep, posix } from 'path';
import v8toIstanbulLib from 'v8-to-istanbul';
import { fetchSourceMap } from '@web/test-runner-core';
import picoMatch from 'picomatch';
import LruCache from 'lru-cache';
import { readFile } from 'node:fs/promises';
import { toFilePath } from './utils.js';
const cachedMatchers = new Map();
// Cache the v8-to-istanbul converters between calls since they
// result in loading files from disk repeatedly otherwise.
const cachedConverters = new lru_cache_1.default({
max: 200,
// Cache the sourcemap/source objects to avoid repeatedly having to load
// them from disk per call
const cachedSources = new LruCache({
maxSize: 1024 * 1024 * 50,
sizeCalculation: n => n.source.length,
});
// coverage base dir must be separated with "/"
const coverageBaseDir = process.cwd().split(path_1.sep).join('/');
const coverageBaseDir = process.cwd().split(sep).join('/');
function hasOriginalSource(source) {
return ('sourceMap' in source &&
source.sourceMap !== undefined &&
typeof source.sourceMap.sourcemap === 'object' &&
source.sourceMap.sourcemap !== null &&
Array.isArray(source.sourceMap.sourcemap.sourcesContent) &&
source.sourceMap.sourcemap.sourcesContent.length > 0);
}
function getMatcher(patterns) {

@@ -28,6 +32,6 @@ if (!patterns || patterns.length === 0) {

if (!matcher) {
const resolvedPatterns = patterns.map(pattern => !path_1.isAbsolute(pattern) && !pattern.startsWith('*')
? path_1.posix.join(coverageBaseDir, pattern)
const resolvedPatterns = patterns.map(pattern => !isAbsolute(pattern) && !pattern.startsWith('*')
? posix.join(coverageBaseDir, pattern)
: pattern);
matcher = picomatch_1.default(resolvedPatterns);
matcher = picoMatch(resolvedPatterns);
cachedMatchers.set(key, matcher);

@@ -37,6 +41,5 @@ }

}
async function v8ToIstanbul(config, testFiles, coverage, userAgent) {
var _a, _b;
const included = getMatcher((_a = config === null || config === void 0 ? void 0 : config.coverageConfig) === null || _a === void 0 ? void 0 : _a.include);
const excluded = getMatcher((_b = config === null || config === void 0 ? void 0 : config.coverageConfig) === null || _b === void 0 ? void 0 : _b.exclude);
export async function v8ToIstanbul(config, testFiles, coverage, userAgent) {
const included = getMatcher(config?.coverageConfig?.include);
const excluded = getMatcher(config?.coverageConfig?.exclude);
const istanbulCoverage = {};

@@ -53,3 +56,3 @@ for (const entry of coverage) {

// ignore non-files
!!path_1.extname(path) &&
!!extname(path) &&
// ignore virtual files

@@ -59,17 +62,23 @@ !path.startsWith('/__web-test-runner') &&

try {
const filePath = path_1.join(config.rootDir, utils_1.toFilePath(path));
const filePath = join(config.rootDir, toFilePath(path));
if (!testFiles.includes(filePath) && included(filePath) && !excluded(filePath)) {
const sources = await test_runner_core_1.fetchSourceMap({
protocol: config.protocol,
host: config.hostname,
port: config.port,
browserUrl: `${url.pathname}${url.search}${url.hash}`,
userAgent,
});
const cachedConverter = cachedConverters.get(filePath);
const converter = cachedConverter !== null && cachedConverter !== void 0 ? cachedConverter : v8_to_istanbul_1.default(filePath, 0, sources);
if (!cachedConverter) {
await converter.load();
cachedConverters.set(filePath, converter);
const browserUrl = `${url.pathname}${url.search}${url.hash}`;
const cachedSource = cachedSources.get(browserUrl);
const sources = cachedSource ??
(await fetchSourceMap({
protocol: config.protocol,
host: config.hostname,
port: config.port,
browserUrl,
userAgent,
}));
if (!cachedSource) {
if (!hasOriginalSource(sources)) {
const contents = await readFile(filePath, 'utf8');
sources.originalSource = contents;
}
cachedSources.set(browserUrl, sources);
}
const converter = v8toIstanbulLib(filePath, 0, sources);
await converter.load();
converter.applyCoverage(entry.functions);

@@ -87,3 +96,2 @@ Object.assign(istanbulCoverage, converter.toIstanbul());

}
exports.v8ToIstanbul = v8ToIstanbul;
//# sourceMappingURL=index.js.map

@@ -1,13 +0,6 @@

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.toFilePath = void 0;
const path_1 = __importDefault(require("path"));
import path from 'path';
const REGEXP_TO_FILE_PATH = new RegExp('/', 'g');
function toFilePath(browserPath) {
return browserPath.replace(REGEXP_TO_FILE_PATH, path_1.default.sep);
export function toFilePath(browserPath) {
return browserPath.replace(REGEXP_TO_FILE_PATH, path.sep);
}
exports.toFilePath = toFilePath;
//# sourceMappingURL=utils.js.map
// this file is autogenerated with the generate-mjs-dts-entrypoints script
export * from './dist/index';
export * from './dist/index.js';
{
"name": "@web/test-runner-coverage-v8",
"version": "0.0.0-canary-20230420104136",
"version": "0.0.0-canary-20231122093600",
"publishConfig": {

@@ -17,4 +17,6 @@ "access": "public"

"main": "dist/index.js",
"type": "module",
"exports": {
".": {
"types": "./index.d.ts",
"import": "./index.mjs",

@@ -25,3 +27,3 @@ "require": "./dist/index.js"

"engines": {
"node": ">=16.0.0"
"node": ">=18.0.0"
},

@@ -47,3 +49,3 @@ "scripts": {

"dependencies": {
"@web/test-runner-core": "0.0.0-canary-20230420104136",
"@web/test-runner-core": "0.0.0-canary-20231122093600",
"istanbul-lib-coverage": "^3.0.0",

@@ -50,0 +52,0 @@ "lru-cache": "^8.0.4",

@@ -8,15 +8,17 @@ import { extname, join, isAbsolute, sep, posix } from 'path';

import LruCache from 'lru-cache';
import { readFile } from 'node:fs/promises';
import { toFilePath } from './utils';
import { toFilePath } from './utils.js';
type V8Coverage = Profiler.ScriptCoverage;
type Matcher = (test: string) => boolean;
type V8Converter = ReturnType<typeof v8toIstanbulLib>;
type IstanbulSource = Required<Parameters<typeof v8toIstanbulLib>>[2];
const cachedMatchers = new Map<string, Matcher>();
// Cache the v8-to-istanbul converters between calls since they
// result in loading files from disk repeatedly otherwise.
const cachedConverters = new LruCache<string, V8Converter>({
max: 200,
// Cache the sourcemap/source objects to avoid repeatedly having to load
// them from disk per call
const cachedSources = new LruCache<string, IstanbulSource>({
maxSize: 1024 * 1024 * 50,
sizeCalculation: n => n.source.length,
});

@@ -27,2 +29,13 @@

function hasOriginalSource(source: IstanbulSource): boolean {
return (
'sourceMap' in source &&
source.sourceMap !== undefined &&
typeof source.sourceMap.sourcemap === 'object' &&
source.sourceMap.sourcemap !== null &&
Array.isArray(source.sourceMap.sourcemap.sourcesContent) &&
source.sourceMap.sourcemap.sourcesContent.length > 0
);
}
function getMatcher(patterns?: string[]) {

@@ -76,18 +89,25 @@ if (!patterns || patterns.length === 0) {

if (!testFiles.includes(filePath) && included(filePath) && !excluded(filePath)) {
const sources = await fetchSourceMap({
protocol: config.protocol,
host: config.hostname,
port: config.port,
browserUrl: `${url.pathname}${url.search}${url.hash}`,
userAgent,
});
const browserUrl = `${url.pathname}${url.search}${url.hash}`;
const cachedSource = cachedSources.get(browserUrl);
const sources =
cachedSource ??
((await fetchSourceMap({
protocol: config.protocol,
host: config.hostname,
port: config.port,
browserUrl,
userAgent,
})) as IstanbulSource);
const cachedConverter = cachedConverters.get(filePath);
const converter = cachedConverter ?? v8toIstanbulLib(filePath, 0, sources as any);
if (!cachedConverter) {
await converter.load();
cachedConverters.set(filePath, converter);
if (!cachedSource) {
if (!hasOriginalSource(sources)) {
const contents = await readFile(filePath, 'utf8');
(sources as IstanbulSource & { originalSource: string }).originalSource = contents;
}
cachedSources.set(browserUrl, sources);
}
const converter = v8toIstanbulLib(filePath, 0, sources);
await converter.load();
converter.applyCoverage(entry.functions);

@@ -94,0 +114,0 @@ Object.assign(istanbulCoverage, converter.toIstanbul());

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc