@tapjs/processinfo 2.1.3 → 2.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/register-coverage.d.ts.map +1 -1
- package/dist/cjs/register-coverage.js +11 -6
- package/dist/cjs/register-coverage.js.map +1 -1
- package/dist/mjs/esm.d.mts +8 -1
- package/dist/mjs/esm.d.mts.map +1 -1
- package/dist/mjs/esm.mjs +22 -20
- package/dist/mjs/esm.mjs.map +1 -1
- package/dist/mjs/register-coverage.d.ts.map +1 -1
- package/dist/mjs/register-coverage.js +11 -6
- package/dist/mjs/register-coverage.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-coverage.d.ts","sourceRoot":"","sources":["../../lib/register-coverage.ts"],"names":[],"mappings":";AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAInC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAE3D,eAAO,IAAI,OAAO,EAAE,OAAO,GAAG,SAAqB,CAAA;AA8CnD,eAAO,MAAM,QAAQ,YAYpB,CAAA;
|
|
1
|
+
{"version":3,"file":"register-coverage.d.ts","sourceRoot":"","sources":["../../lib/register-coverage.ts"],"names":[],"mappings":";AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAInC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAE3D,eAAO,IAAI,OAAO,EAAE,OAAO,GAAG,SAAqB,CAAA;AA8CnD,eAAO,MAAM,QAAQ,YAYpB,CAAA;AAaD,eAAO,MAAM,oBAAoB,QAC1B,MAAM,eACE,mBAAmB,SAyDjC,CAAA"}
|
|
@@ -63,11 +63,16 @@ const register = () => {
|
|
|
63
63
|
};
|
|
64
64
|
exports.register = register;
|
|
65
65
|
/* c8 ignore stop */
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
66
|
+
// NB: this is the *generated* line lengths, not the source
|
|
67
|
+
const lineLengths = (f) => {
|
|
68
|
+
try {
|
|
69
|
+
const content = (0, fs_1.readFileSync)(f, 'utf8');
|
|
70
|
+
return content.split(/\n|\u2028|\u2029/).map(l => l.length);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return [];
|
|
74
|
+
}
|
|
75
|
+
};
|
|
71
76
|
const coverageOnProcessEnd = (cwd, processInfo) => {
|
|
72
77
|
// Similar to the coverage tracking bootstrap problem above, c8
|
|
73
78
|
// doesn't see that this function runs, even though it DOES see
|
|
@@ -105,7 +110,7 @@ const coverageOnProcessEnd = (cwd, processInfo) => {
|
|
|
105
110
|
if (s) {
|
|
106
111
|
const { payload } = s;
|
|
107
112
|
sourceMapCache[obj.url] = Object.assign(Object.create(null), {
|
|
108
|
-
lineLengths: lineLengths(f
|
|
113
|
+
lineLengths: lineLengths(f),
|
|
109
114
|
data: payload,
|
|
110
115
|
});
|
|
111
116
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-coverage.js","sourceRoot":"","sources":["../../lib/register-coverage.ts"],"names":[],"mappings":";;;AAAA,sDAAsD;AACtD,8DAA8D;AAC9D,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,4BAA4B,KAAK,GAAG,CAAA;AAChE,2BAA2D;AAC3D,yCAAmC;AACnC,mCAAwD;AACxD,6BAAmC;AACnC,qDAA6C;AAGlC,QAAA,OAAO,GAAwB,SAAS,CAAA;AAEnD,uDAAuD;AACvD,oDAAoD;AACpD,qDAAqD;AACrD,MAAM,OAAO,GAAG,IAAA,2BAAU,EAAC,iCAAiC,CAAC,CAAA;AAE7D,4DAA4D;AAC5D,gEAAgE;AAChE,mEAAmE;AACnE,8DAA8D;AAC9D,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,6BAA6B,IAAI,EAAE,CAAA;AAC7D,MAAM,YAAY,GAAa,KAAK,CAAC,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;YAC7B,MAAM,CAAC,GAAG,IAAA,sBAAa,EAAC,CAAC,CAAC,CAAA;YAC1B,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE;gBAClD,OAAO,KAAK,CAAA;aACb;YACD,IAAI,CAAC,EAAE;gBACL,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,CAAA;gBACrB,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;oBAC3D,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC;oBAC3B,IAAI,EAAE,OAAO;iBACd,CAAC,CAAA;aACH;YACD,OAAO,IAAI,CAAA;QACb,CAAC,CAAC,CAAA;QAEF,IAAA,kBAAa,EAAC,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,CAAA;QAC7D,qBAAqB;IACvB,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AA3DY,QAAA,oBAAoB,wBA2DhC;AACD,oBAAoB","sourcesContent":["// start tracking coverage, unless disabled explicltly\n// export so that we know to collect at the end of the process\nconst enabled = process.env._TAPJS_PROCESSINFO_COVERAGE_ !== '0'\nimport { mkdirSync, readFileSync, writeFileSync } from 'fs'\nimport { Session } from 'inspector'\nimport { findSourceMap, SourceMapPayload } from 'module'\nimport { fileURLToPath } from 'url'\nimport { getExclude } from './get-exclude.js'\nimport { ProcessInfoNodeData } from './get-process-info.js'\n\nexport let SESSION: Session | undefined = undefined\n\n// NB: coverage exclusion is in addition to processinfo\n// exclusion. Only show coverage for a file we care\n// about at least somewhat, but coverage is a subset.\nconst exclude = getExclude('_TAPJS_PROCESSINFO_COV_EXCLUDE_')\n\n// This is a \\n delimited list of files to show coverage for\n// If not set, or empty, then coverage is included for all files\n// that pass the exclusion RegExp filter. If included in this list,\n// then coverage will be recorded, even if it matches exclude.\nconst cfEnv = process.env._TAPJS_PROCESSINFO_COV_FILES_ || ''\nconst coveredFiles: string[] = cfEnv.trim().split('\\n').filter(f => !!f)\nconst fileCovered = (\n f: string,\n s?: SourceMapPayload,\n files: string[] = []\n) => {\n const testFiles = [f]\n if (s) {\n for (const src of s.sources || []) {\n testFiles.push(fileURLToPath(src))\n }\n }\n if (!testFiles.some(f => files.includes(f))) return false\n\n // if at least one of them are explicitly covered, then include it,\n // otherwise omit if we explicitly listed\n if (coveredFiles.length) {\n return testFiles.some(f => coveredFiles.includes(f))\n }\n\n for (const f of testFiles) {\n if (!exclude.test(f)) return true\n }\n return false\n}\n\n// C8 can't see that this function runs, best theory is that it\n// collides with what it's doing with the coverage it's collecting\n// This ignore can possibly be removed once this is being tested\n// with a version of tap that uses this library, but it might just\n// be an unresolveable bootstrap problem.\n// The test does verify that it ran, because otherwise, there would\n// be no coverage, and it verifies that it gets the expected coverage.\n/* c8 ignore start */\nexport const register = () => {\n if (!enabled) return\n process.env._TAPJS_PROCESSINFO_COVERAGE_ = '1'\n\n SESSION = new Session()\n SESSION.connect()\n SESSION.post('Profiler.enable')\n SESSION.post('Runtime.enable')\n SESSION.post('Profiler.startPreciseCoverage', {\n callCount: true,\n detailed: true,\n })\n}\n/* c8 ignore stop */\n\n// NB: this is the *generated* line lengths, not the source\nconst lineLengths = (f: string): number[] => {\n try {\n const content = readFileSync(f, 'utf8')\n return content.split(/\\n|\\u2028|\\u2029/).map(l => l.length)\n } catch {\n return []\n }\n}\n\nexport const coverageOnProcessEnd = (\n cwd: string,\n processInfo: ProcessInfoNodeData\n) => {\n // Similar to the coverage tracking bootstrap problem above, c8\n // doesn't see that this function runs, even though it DOES see\n // that the function defined below runs, which is weird.\n /* c8 ignore start */\n if (!SESSION) return\n const session = SESSION\n\n const f = `${cwd}/.tap/coverage/${processInfo.uuid}.json`\n mkdirSync(`${cwd}/.tap/coverage`, { recursive: true })\n\n session.post('Profiler.takePreciseCoverage', (er, cov) => {\n session.post('Profiler.stopPreciseCoverage')\n /* c8 ignore stop */\n\n // something very strange and bad happened\n /* c8 ignore start */\n if (er) {\n throw er\n }\n /* c8 ignore stop */\n\n // Create a source-map-cache that c8 uses in report generation\n const sourceMapCache: {\n [k: string]: {\n lineLengths: number[]\n data: SourceMapPayload\n }\n } = {}\n Object.assign(cov, {\n 'source-map-cache': sourceMapCache,\n })\n\n cov.result = cov.result.filter(obj => {\n if (!/^file:/.test(obj.url)) {\n return false\n }\n const f = fileURLToPath(obj.url)\n // see if it has a source map\n const s = findSourceMap(f)\n if (!fileCovered(f, s?.payload, processInfo.files)) {\n return false\n }\n if (s) {\n const { payload } = s\n sourceMapCache[obj.url] = Object.assign(Object.create(null), {\n lineLengths: lineLengths(f),\n data: payload,\n })\n }\n return true\n })\n\n writeFileSync(f, JSON.stringify(cov, null, 2) + '\\n', 'utf8')\n /* c8 ignore start */\n })\n}\n/* c8 ignore stop */\n"]}
|
package/dist/mjs/esm.d.mts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import type { Serializable } from 'worker_threads';
|
|
1
3
|
export * from './index.js';
|
|
2
|
-
|
|
4
|
+
type GPPort = {
|
|
5
|
+
postMessage: (x: Serializable) => any;
|
|
6
|
+
};
|
|
7
|
+
export declare const globalPreload: (context: {
|
|
8
|
+
port?: GPPort;
|
|
9
|
+
}) => string;
|
|
3
10
|
export declare const load: (url: string, context: any, nextLoad: Function) => Promise<any>;
|
|
4
11
|
//# sourceMappingURL=esm.d.mts.map
|
package/dist/mjs/esm.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"esm.d.mts","sourceRoot":"","sources":["../../lib/esm.mts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"esm.d.mts","sourceRoot":"","sources":["../../lib/esm.mts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAOlD,cAAc,YAAY,CAAA;AAU1B,KAAK,MAAM,GAAG;IACZ,WAAW,EAAE,CAAC,CAAC,EAAE,YAAY,KAAK,GAAG,CAAA;CACtC,CAAA;AAED,eAAO,MAAM,aAAa,YAAa;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,WAkBvD,CAAA;AAGD,eAAO,MAAM,IAAI,QACV,MAAM,WACF,GAAG,YACF,QAAQ,iBAcnB,CAAA"}
|
package/dist/mjs/esm.mjs
CHANGED
|
@@ -1,33 +1,29 @@
|
|
|
1
1
|
// usage: node '--loader=@tapjs/processinfo/esm' foo.mjs
|
|
2
2
|
import { fileURLToPath } from 'url';
|
|
3
3
|
import { getExclude } from './get-exclude.js';
|
|
4
|
+
import { getProcessInfo } from './get-process-info.js';
|
|
4
5
|
import { resolve } from './require-resolve.js';
|
|
5
6
|
// copy main module so that we can --loader=@tapjs/processinfo and use
|
|
6
7
|
// this as the entry point as well.
|
|
7
8
|
export * from './index.js';
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
// on Node v20, loaders are executed in a separate isolated environment
|
|
11
|
-
// As a result, to register coverage and track files, we need to act in
|
|
12
|
-
// the globalPreload function. The load() method posts a message with the
|
|
13
|
-
// filename being loaded, because any registrations that happen in the
|
|
14
|
-
// loader thread will not have any effect.
|
|
15
|
-
// Using diagnostics channel means that this will keep working in all
|
|
16
|
-
// the versions supported, and easily be transferrable to an --import
|
|
17
|
-
// argument that attaches the loaders at run-time.
|
|
18
|
-
export const globalPreload = () => {
|
|
9
|
+
let PORT = undefined;
|
|
10
|
+
export const globalPreload = (context) => {
|
|
19
11
|
// this will be something like path/to/dist/mjs/lib/esm.mjs
|
|
20
12
|
// but we need path/to/dist/cjs/cjs.js
|
|
21
13
|
const base = resolve('../cjs/cjs.js');
|
|
14
|
+
const { port } = context || {};
|
|
15
|
+
PORT = port;
|
|
22
16
|
return `
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
)
|
|
17
|
+
if (typeof port !== 'undefined') {
|
|
18
|
+
const { createRequire } = getBuiltin('module')
|
|
19
|
+
const require = createRequire(${JSON.stringify(base)})
|
|
20
|
+
const { getProcessInfo } = require('./get-process-info.js')
|
|
21
|
+
// must be called eagerly here.
|
|
22
|
+
// this does all the registration as well.
|
|
23
|
+
const processInfo = getProcessInfo()
|
|
24
|
+
port.onmessage = (e) => processInfo.files.push(e.data)
|
|
25
|
+
port.unref()
|
|
26
|
+
}
|
|
31
27
|
`;
|
|
32
28
|
};
|
|
33
29
|
const exclude = getExclude('_TAPJS_PROCESSINFO_EXCLUDE_');
|
|
@@ -35,7 +31,13 @@ export const load = async (url, context, nextLoad) => {
|
|
|
35
31
|
if (/^file:/.test(url)) {
|
|
36
32
|
const filename = fileURLToPath(url);
|
|
37
33
|
if (!exclude.test(filename)) {
|
|
38
|
-
PORT
|
|
34
|
+
if (PORT) {
|
|
35
|
+
PORT.postMessage(filename);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
// call lazily so we don't double-register
|
|
39
|
+
getProcessInfo().files.push(filename);
|
|
40
|
+
}
|
|
39
41
|
}
|
|
40
42
|
}
|
|
41
43
|
return nextLoad(url, context);
|
package/dist/mjs/esm.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"esm.mjs","sourceRoot":"","sources":["../../lib/esm.mts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"esm.mjs","sourceRoot":"","sources":["../../lib/esm.mts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAA;AAEnC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAE9C,sEAAsE;AACtE,mCAAmC;AACnC,cAAc,YAAY,CAAA;AAa1B,IAAI,IAAI,GAAuB,SAAS,CAAA;AACxC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,OAA0B,EAAE,EAAE;IAC1D,2DAA2D;IAC3D,sCAAsC;IACtC,MAAM,IAAI,GAAG,OAAO,CAAC,eAAe,CAAC,CAAA;IACrC,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,IAAI,EAAE,CAAA;IAC9B,IAAI,GAAG,IAAI,CAAA;IACX,OAAO;;;kCAGyB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;;;;;;;;CAQrD,CAAA;AACD,CAAC,CAAA;AAED,MAAM,OAAO,GAAG,UAAU,CAAC,6BAA6B,CAAC,CAAA;AACzD,MAAM,CAAC,MAAM,IAAI,GAAG,KAAK,EACvB,GAAW,EACX,OAAY,EACZ,QAAkB,EAClB,EAAE;IACF,IAAI,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;QACtB,MAAM,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC,CAAA;QACnC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;YAC3B,IAAI,IAAI,EAAE;gBACR,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAA;aAC3B;iBAAM;gBACL,0CAA0C;gBAC1C,cAAc,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;aACtC;SACF;KACF;IACD,OAAO,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;AAC/B,CAAC,CAAA","sourcesContent":["// usage: node '--loader=@tapjs/processinfo/esm' foo.mjs\nimport { fileURLToPath } from 'url'\nimport type { Serializable } from 'worker_threads'\nimport { getExclude } from './get-exclude.js'\nimport { getProcessInfo } from './get-process-info.js'\nimport { resolve } from './require-resolve.js'\n\n// copy main module so that we can --loader=@tapjs/processinfo and use\n// this as the entry point as well.\nexport * from './index.js'\n\n// on Node v20, loaders are executed in a separate isolated environment\n// As a result, to register coverage and track files, we need to act in\n// the globalPreload function. The load() method posts a message with the\n// filename being loaded, because any registrations that happen in the\n// loader thread will not have any effect.\n// The check for the 'port' being undefined is to allow for support back to\n// 16.12, which had a globalPreload method, but did not have a sendMessage\n// port in that environment.\ntype GPPort = {\n postMessage: (x: Serializable) => any\n}\nlet PORT: undefined | GPPort = undefined\nexport const globalPreload = (context: { port?: GPPort }) => {\n // this will be something like path/to/dist/mjs/lib/esm.mjs\n // but we need path/to/dist/cjs/cjs.js\n const base = resolve('../cjs/cjs.js')\n const { port } = context || {}\n PORT = port\n return `\nif (typeof port !== 'undefined') {\n const { createRequire } = getBuiltin('module')\n const require = createRequire(${JSON.stringify(base)})\n const { getProcessInfo } = require('./get-process-info.js')\n // must be called eagerly here.\n // this does all the registration as well.\n const processInfo = getProcessInfo()\n port.onmessage = (e) => processInfo.files.push(e.data)\n port.unref()\n}\n`\n}\n\nconst exclude = getExclude('_TAPJS_PROCESSINFO_EXCLUDE_')\nexport const load = async (\n url: string,\n context: any,\n nextLoad: Function\n) => {\n if (/^file:/.test(url)) {\n const filename = fileURLToPath(url)\n if (!exclude.test(filename)) {\n if (PORT) {\n PORT.postMessage(filename)\n } else {\n // call lazily so we don't double-register\n getProcessInfo().files.push(filename)\n }\n }\n }\n return nextLoad(url, context)\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-coverage.d.ts","sourceRoot":"","sources":["../../lib/register-coverage.ts"],"names":[],"mappings":";AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAInC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAE3D,eAAO,IAAI,OAAO,EAAE,OAAO,GAAG,SAAqB,CAAA;AA8CnD,eAAO,MAAM,QAAQ,YAYpB,CAAA;
|
|
1
|
+
{"version":3,"file":"register-coverage.d.ts","sourceRoot":"","sources":["../../lib/register-coverage.ts"],"names":[],"mappings":";AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAInC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAE3D,eAAO,IAAI,OAAO,EAAE,OAAO,GAAG,SAAqB,CAAA;AA8CnD,eAAO,MAAM,QAAQ,YAYpB,CAAA;AAaD,eAAO,MAAM,oBAAoB,QAC1B,MAAM,eACE,mBAAmB,SAyDjC,CAAA"}
|
|
@@ -59,11 +59,16 @@ export const register = () => {
|
|
|
59
59
|
});
|
|
60
60
|
};
|
|
61
61
|
/* c8 ignore stop */
|
|
62
|
-
//
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
// NB: this is the *generated* line lengths, not the source
|
|
63
|
+
const lineLengths = (f) => {
|
|
64
|
+
try {
|
|
65
|
+
const content = readFileSync(f, 'utf8');
|
|
66
|
+
return content.split(/\n|\u2028|\u2029/).map(l => l.length);
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
};
|
|
67
72
|
export const coverageOnProcessEnd = (cwd, processInfo) => {
|
|
68
73
|
// Similar to the coverage tracking bootstrap problem above, c8
|
|
69
74
|
// doesn't see that this function runs, even though it DOES see
|
|
@@ -101,7 +106,7 @@ export const coverageOnProcessEnd = (cwd, processInfo) => {
|
|
|
101
106
|
if (s) {
|
|
102
107
|
const { payload } = s;
|
|
103
108
|
sourceMapCache[obj.url] = Object.assign(Object.create(null), {
|
|
104
|
-
lineLengths: lineLengths(f
|
|
109
|
+
lineLengths: lineLengths(f),
|
|
105
110
|
data: payload,
|
|
106
111
|
});
|
|
107
112
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-coverage.js","sourceRoot":"","sources":["../../lib/register-coverage.ts"],"names":[],"mapp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AW,EAAE,WAAW,CAAC,CAAC,CAAC;oBAC3B,IAAI,EAAE,OAAO;iBACd,CAAC,CAAA;aACH;YACD,OAAO,IAAI,CAAA;QACb,CAAC,CAAC,CAAA;QAEF,aAAa,CAAC,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,CAAA;QAC7D,qBAAqB;IACvB,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AACD,oBAAoB","sourcesContent":["// start tracking coverage, unless disabled explicltly\n// export so that we know to collect at the end of the process\nconst enabled = process.env._TAPJS_PROCESSINFO_COVERAGE_ !== '0'\nimport { mkdirSync, readFileSync, writeFileSync } from 'fs'\nimport { Session } from 'inspector'\nimport { findSourceMap, SourceMapPayload } from 'module'\nimport { fileURLToPath } from 'url'\nimport { getExclude } from './get-exclude.js'\nimport { ProcessInfoNodeData } from './get-process-info.js'\n\nexport let SESSION: Session | undefined = undefined\n\n// NB: coverage exclusion is in addition to processinfo\n// exclusion. Only show coverage for a file we care\n// about at least somewhat, but coverage is a subset.\nconst exclude = getExclude('_TAPJS_PROCESSINFO_COV_EXCLUDE_')\n\n// This is a \\n delimited list of files to show coverage for\n// If not set, or empty, then coverage is included for all files\n// that pass the exclusion RegExp filter. If included in this list,\n// then coverage will be recorded, even if it matches exclude.\nconst cfEnv = process.env._TAPJS_PROCESSINFO_COV_FILES_ || ''\nconst coveredFiles: string[] = cfEnv.trim().split('\\n').filter(f => !!f)\nconst fileCovered = (\n f: string,\n s?: SourceMapPayload,\n files: string[] = []\n) => {\n const testFiles = [f]\n if (s) {\n for (const src of s.sources || []) {\n testFiles.push(fileURLToPath(src))\n }\n }\n if (!testFiles.some(f => files.includes(f))) return false\n\n // if at least one of them are explicitly covered, then include it,\n // otherwise omit if we explicitly listed\n if (coveredFiles.length) {\n return testFiles.some(f => coveredFiles.includes(f))\n }\n\n for (const f of testFiles) {\n if (!exclude.test(f)) return true\n }\n return false\n}\n\n// C8 can't see that this function runs, best theory is that it\n// collides with what it's doing with the coverage it's collecting\n// This ignore can possibly be removed once this is being tested\n// with a version of tap that uses this library, but it might just\n// be an unresolveable bootstrap problem.\n// The test does verify that it ran, because otherwise, there would\n// be no coverage, and it verifies that it gets the expected coverage.\n/* c8 ignore start */\nexport const register = () => {\n if (!enabled) return\n process.env._TAPJS_PROCESSINFO_COVERAGE_ = '1'\n\n SESSION = new Session()\n SESSION.connect()\n SESSION.post('Profiler.enable')\n SESSION.post('Runtime.enable')\n SESSION.post('Profiler.startPreciseCoverage', {\n callCount: true,\n detailed: true,\n })\n}\n/* c8 ignore stop */\n\n// NB: this is the *generated* line lengths, not the source\nconst lineLengths = (f: string): number[] => {\n try {\n const content = readFileSync(f, 'utf8')\n return content.split(/\\n|\\u2028|\\u2029/).map(l => l.length)\n } catch {\n return []\n }\n}\n\nexport const coverageOnProcessEnd = (\n cwd: string,\n processInfo: ProcessInfoNodeData\n) => {\n // Similar to the coverage tracking bootstrap problem above, c8\n // doesn't see that this function runs, even though it DOES see\n // that the function defined below runs, which is weird.\n /* c8 ignore start */\n if (!SESSION) return\n const session = SESSION\n\n const f = `${cwd}/.tap/coverage/${processInfo.uuid}.json`\n mkdirSync(`${cwd}/.tap/coverage`, { recursive: true })\n\n session.post('Profiler.takePreciseCoverage', (er, cov) => {\n session.post('Profiler.stopPreciseCoverage')\n /* c8 ignore stop */\n\n // something very strange and bad happened\n /* c8 ignore start */\n if (er) {\n throw er\n }\n /* c8 ignore stop */\n\n // Create a source-map-cache that c8 uses in report generation\n const sourceMapCache: {\n [k: string]: {\n lineLengths: number[]\n data: SourceMapPayload\n }\n } = {}\n Object.assign(cov, {\n 'source-map-cache': sourceMapCache,\n })\n\n cov.result = cov.result.filter(obj => {\n if (!/^file:/.test(obj.url)) {\n return false\n }\n const f = fileURLToPath(obj.url)\n // see if it has a source map\n const s = findSourceMap(f)\n if (!fileCovered(f, s?.payload, processInfo.files)) {\n return false\n }\n if (s) {\n const { payload } = s\n sourceMapCache[obj.url] = Object.assign(Object.create(null), {\n lineLengths: lineLengths(f),\n data: payload,\n })\n }\n return true\n })\n\n writeFileSync(f, JSON.stringify(cov, null, 2) + '\\n', 'utf8')\n /* c8 ignore start */\n })\n}\n/* c8 ignore stop */\n"]}
|