@tapjs/processinfo 2.0.1 → 2.1.0

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/README.md CHANGED
@@ -104,3 +104,29 @@ for (const f of proc.files) {
104
104
  Note: unless there has been a previous wrapped process run, nothing will be
105
105
  present in the data. That is, `data.root` will be null, and all the maps
106
106
  will be empty.
107
+
108
+ ## Controlling Coverage
109
+
110
+ To disable coverage entirely, set
111
+ `_TAPJS_PROCESSINFO_COVERAGE_=0` in the environment.
112
+
113
+ To exclude certain file paths from coverage, set the
114
+ `_TAPJS_PROCESSINFO_COV_EXCLUDE_` to a regular expression string.
115
+ By default, it will ignore:
116
+
117
+ - Anything in a folder named `node_modules`, `.tap`,
118
+ `tap-snapshots`, `test`, `tests`, `__test__`, `__tests__`, or
119
+ starting with `tap-testdir-`.
120
+ - Any file named `*.test.{ext}` where `{ext}` is one of js, cjs,
121
+ mjs, ts, cts, mts, jsx, or tsx.
122
+
123
+ To include only a specific set of files for coverage (as with
124
+ node-tap's `coverage-map` option), set
125
+ `_TAPJS_PROCESSINFO_COV_FILES_` to a `\n` delimited list of the
126
+ files to include. These will have their coverage reported even if
127
+ they would be excluded by the `_TAPJS_PROCESSINFO_COV_EXCLUDE_`
128
+ regexp.
129
+
130
+ Note that coverage _instrumentation_ is by necessity enabled for
131
+ all files, but it's only written to disk if the file (or any of
132
+ its sources, if it has a sourcemap) is included.
@@ -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;AAenD,eAAO,MAAM,QAAQ,YAYpB,CAAA;AAUD,eAAO,MAAM,oBAAoB,QAC1B,MAAM,eACE,mBAAmB,SAyDjC,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;AAUD,eAAO,MAAM,oBAAoB,QAC1B,MAAM,eACE,mBAAmB,SAyDjC,CAAA"}
@@ -14,6 +14,32 @@ exports.SESSION = undefined;
14
14
  // exclusion. Only show coverage for a file we care
15
15
  // about at least somewhat, but coverage is a subset.
16
16
  const exclude = (0, get_exclude_js_1.getExclude)('_TAPJS_PROCESSINFO_COV_EXCLUDE_');
17
+ // This is a \n delimited list of files to show coverage for
18
+ // If not set, or empty, then coverage is included for all files
19
+ // that pass the exclusion RegExp filter. If included in this list,
20
+ // then coverage will be recorded, even if it matches exclude.
21
+ const cfEnv = process.env._TAPJS_PROCESSINFO_COV_FILES_ || '';
22
+ const coveredFiles = cfEnv.trim().split('\n').filter(f => !!f);
23
+ const fileCovered = (f, s, files = []) => {
24
+ const testFiles = [f];
25
+ if (s) {
26
+ for (const src of s.sources || []) {
27
+ testFiles.push((0, url_1.fileURLToPath)(src));
28
+ }
29
+ }
30
+ if (!testFiles.some(f => files.includes(f)))
31
+ return false;
32
+ // if at least one of them are explicitly covered, then include it,
33
+ // otherwise omit if we explicitly listed
34
+ if (coveredFiles.length) {
35
+ return testFiles.some(f => coveredFiles.includes(f));
36
+ }
37
+ for (const f of testFiles) {
38
+ if (!exclude.test(f))
39
+ return true;
40
+ }
41
+ return false;
42
+ };
17
43
  // C8 can't see that this function runs, best theory is that it
18
44
  // collides with what it's doing with the coverage it's collecting
19
45
  // This ignore can possibly be removed once this is being tested
@@ -71,11 +97,11 @@ const coverageOnProcessEnd = (cwd, processInfo) => {
71
97
  return false;
72
98
  }
73
99
  const f = (0, url_1.fileURLToPath)(obj.url);
74
- if (!processInfo.files.includes(f) || exclude.test(f)) {
75
- return false;
76
- }
77
100
  // see if it has a source map
78
101
  const s = (0, module_1.findSourceMap)(f);
102
+ if (!fileCovered(f, s?.payload, processInfo.files)) {
103
+ return false;
104
+ }
79
105
  if (s) {
80
106
  const { payload } = s;
81
107
  sourceMapCache[obj.url] = Object.assign(Object.create(null), {
@@ -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,+DAA+D;AAC/D,kEAAkE;AAClE,gEAAgE;AAChE,kEAAkE;AAClE,yCAAyC;AACzC,mEAAmE;AACnE,sEAAsE;AACtE,qBAAqB;AACd,MAAM,QAAQ,GAAG,GAAG,EAAE;IAC3B,IAAI,CAAC,OAAO;QAAE,OAAM;IACpB,OAAO,CAAC,GAAG,CAAC,4BAA4B,GAAG,GAAG,CAAA;IAE9C,eAAO,GAAG,IAAI,mBAAO,EAAE,CAAA;IACvB,eAAO,CAAC,OAAO,EAAE,CAAA;IACjB,eAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;IAC/B,eAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAA;IAC9B,eAAO,CAAC,IAAI,CAAC,+BAA+B,EAAE;QAC5C,SAAS,EAAE,IAAI;QACf,QAAQ,EAAE,IAAI;KACf,CAAC,CAAA;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CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;gBAC3B,OAAO,KAAK,CAAA;aACb;YACD,MAAM,CAAC,GAAG,IAAA,mBAAa,EAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YAChC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;gBACrD,OAAO,KAAK,CAAA;aACb;YACD,6BAA6B;YAC7B,MAAM,CAAC,GAAG,IAAA,sBAAa,EAAC,CAAC,CAAC,CAAA;YAC1B,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,EAAE,OAAO,CAAC,cAAc,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;oBAC7D,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// 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// only read the file again if we don't already have the content\n// in the source map itself.\nconst lineLengths = (f: string, content?: string): number[] =>\n !content\n ? lineLengths(f, readFileSync(f, 'utf8'))\n : content.split(/\\n|\\u2028|\\u2029/).map(l => l.length)\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 if (!processInfo.files.includes(f) || exclude.test(f)) {\n return false\n }\n // see if it has a source map\n const s = findSourceMap(f)\n if (s) {\n const { payload } = s\n sourceMapCache[obj.url] = Object.assign(Object.create(null), {\n lineLengths: lineLengths(f, payload.sourcesContent?.join('')),\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"]}
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,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AACxE,MAAM,WAAW,GAAG,CAClB,CAAS,EACT,CAAoB,EACpB,QAAkB,EAAE,EACpB,EAAE;IACF,MAAM,SAAS,GAAG,CAAC,CAAC,CAAC,CAAA;IACrB,IAAI,CAAC,EAAE;QACL,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,OAAO,KAAK,CAAA;aACb;YACD,MAAM,CAAC,GAAG,IAAA,mBAAa,EAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YAChC,6BAA6B;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,EAAE,OAAO,CAAC,cAAc,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;oBAC7D,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// only read the file again if we don't already have the content\n// in the source map itself.\nconst lineLengths = (f: string, content?: string): number[] =>\n !content\n ? lineLengths(f, readFileSync(f, 'utf8'))\n : content.split(/\\n|\\u2028|\\u2029/).map(l => l.length)\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, payload.sourcesContent?.join('')),\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"]}
@@ -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;AAenD,eAAO,MAAM,QAAQ,YAYpB,CAAA;AAUD,eAAO,MAAM,oBAAoB,QAC1B,MAAM,eACE,mBAAmB,SAyDjC,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;AAUD,eAAO,MAAM,oBAAoB,QAC1B,MAAM,eACE,mBAAmB,SAyDjC,CAAA"}
@@ -11,6 +11,32 @@ export let SESSION = undefined;
11
11
  // exclusion. Only show coverage for a file we care
12
12
  // about at least somewhat, but coverage is a subset.
13
13
  const exclude = getExclude('_TAPJS_PROCESSINFO_COV_EXCLUDE_');
14
+ // This is a \n delimited list of files to show coverage for
15
+ // If not set, or empty, then coverage is included for all files
16
+ // that pass the exclusion RegExp filter. If included in this list,
17
+ // then coverage will be recorded, even if it matches exclude.
18
+ const cfEnv = process.env._TAPJS_PROCESSINFO_COV_FILES_ || '';
19
+ const coveredFiles = cfEnv.trim().split('\n').filter(f => !!f);
20
+ const fileCovered = (f, s, files = []) => {
21
+ const testFiles = [f];
22
+ if (s) {
23
+ for (const src of s.sources || []) {
24
+ testFiles.push(fileURLToPath(src));
25
+ }
26
+ }
27
+ if (!testFiles.some(f => files.includes(f)))
28
+ return false;
29
+ // if at least one of them are explicitly covered, then include it,
30
+ // otherwise omit if we explicitly listed
31
+ if (coveredFiles.length) {
32
+ return testFiles.some(f => coveredFiles.includes(f));
33
+ }
34
+ for (const f of testFiles) {
35
+ if (!exclude.test(f))
36
+ return true;
37
+ }
38
+ return false;
39
+ };
14
40
  // C8 can't see that this function runs, best theory is that it
15
41
  // collides with what it's doing with the coverage it's collecting
16
42
  // This ignore can possibly be removed once this is being tested
@@ -67,11 +93,11 @@ export const coverageOnProcessEnd = (cwd, processInfo) => {
67
93
  return false;
68
94
  }
69
95
  const f = fileURLToPath(obj.url);
70
- if (!processInfo.files.includes(f) || exclude.test(f)) {
71
- return false;
72
- }
73
96
  // see if it has a source map
74
97
  const s = findSourceMap(f);
98
+ if (!fileCovered(f, s?.payload, processInfo.files)) {
99
+ return false;
100
+ }
75
101
  if (s) {
76
102
  const { payload } = s;
77
103
  sourceMapCache[obj.url] = Object.assign(Object.create(null), {
@@ -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,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,IAAI,CAAA;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,aAAa,EAAoB,MAAM,QAAQ,CAAA;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAA;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAG7C,MAAM,CAAC,IAAI,OAAO,GAAwB,SAAS,CAAA;AAEnD,uDAAuD;AACvD,oDAAoD;AACpD,qDAAqD;AACrD,MAAM,OAAO,GAAG,UAAU,CAAC,iCAAiC,CAAC,CAAA;AAE7D,+DAA+D;AAC/D,kEAAkE;AAClE,gEAAgE;AAChE,kEAAkE;AAClE,yCAAyC;AACzC,mEAAmE;AACnE,sEAAsE;AACtE,qBAAqB;AACrB,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAG,EAAE;IAC3B,IAAI,CAAC,OAAO;QAAE,OAAM;IACpB,OAAO,CAAC,GAAG,CAAC,4BAA4B,GAAG,GAAG,CAAA;IAE9C,OAAO,GAAG,IAAI,OAAO,EAAE,CAAA;IACvB,OAAO,CAAC,OAAO,EAAE,CAAA;IACjB,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;IAC/B,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAA;IAC9B,OAAO,CAAC,IAAI,CAAC,+BAA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CAAC,MAAM,CAAC,GAAG,CAAC,EAAE;YACnC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;gBAC3B,OAAO,KAAK,CAAA;aACb;YACD,MAAM,CAAC,GAAG,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YAChC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;gBACrD,OAAO,KAAK,CAAA;aACb;YACD,6BAA6B;YAC7B,MAAM,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAA;YAC1B,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,EAAE,OAAO,CAAC,cAAc,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;oBAC7D,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// 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// only read the file again if we don't already have the content\n// in the source map itself.\nconst lineLengths = (f: string, content?: string): number[] =>\n !content\n ? lineLengths(f, readFileSync(f, 'utf8'))\n : content.split(/\\n|\\u2028|\\u2029/).map(l => l.length)\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 if (!processInfo.files.includes(f) || exclude.test(f)) {\n return false\n }\n // see if it has a source map\n const s = findSourceMap(f)\n if (s) {\n const { payload } = s\n sourceMapCache[obj.url] = Object.assign(Object.create(null), {\n lineLengths: lineLengths(f, payload.sourcesContent?.join('')),\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"]}
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,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,IAAI,CAAA;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,aAAa,EAAoB,MAAM,QAAQ,CAAA;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAA;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAG7C,MAAM,CAAC,IAAI,OAAO,GAAwB,SAAS,CAAA;AAEnD,uDAAuD;AACvD,oDAAoD;AACpD,qDAAqD;AACrD,MAAM,OAAO,GAAG,UAAU,CAAC,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,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EA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,CAAA;QAEF,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE;YACnC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;gBAC3B,OAAO,KAAK,CAAA;aACb;YACD,MAAM,CAAC,GAAG,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YAChC,6BAA6B;YAC7B,MAAM,CAAC,GAAG,aAAa,CAAC,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,EAAE,OAAO,CAAC,cAAc,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;oBAC7D,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// only read the file again if we don't already have the content\n// in the source map itself.\nconst lineLengths = (f: string, content?: string): number[] =>\n !content\n ? lineLengths(f, readFileSync(f, 'utf8'))\n : content.split(/\\n|\\u2028|\\u2029/).map(l => l.length)\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, payload.sourcesContent?.join('')),\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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tapjs/processinfo",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "main": "./dist/cjs/index.js",
5
5
  "types": "./dist/cjs/index.d.ts",
6
6
  "module": "./dist/mjs/esm.mjs",
@@ -10,8 +10,8 @@
10
10
  "exports": {
11
11
  ".": {
12
12
  "import": {
13
- "types": "./dist/mjs/esm.d.ts",
14
- "default": "./dist/mjs/esm.js"
13
+ "types": "./dist/mjs/esm.d.mts",
14
+ "default": "./dist/mjs/esm.mjs"
15
15
  },
16
16
  "require": {
17
17
  "types": "./dist/cjs/index.d.ts",