c8 7.5.0 → 7.7.2

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/CHANGELOG.md CHANGED
@@ -2,6 +2,34 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [7.7.2](https://www.github.com/bcoe/c8/compare/v7.7.1...v7.7.2) (2021-05-02)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * address bugs with source remapping on Windows ([#301](https://www.github.com/bcoe/c8/issues/301)) ([c817902](https://www.github.com/bcoe/c8/commit/c81790262f843c01b3d14390fde81dbdbcf2226f))
11
+
12
+ ### [7.7.1](https://www.github.com/bcoe/c8/compare/v7.7.0...v7.7.1) (2021-04-07)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * **types:** add excludeAfterRemap and allowExternal ([#297](https://www.github.com/bcoe/c8/issues/297)) ([e32a53f](https://www.github.com/bcoe/c8/commit/e32a53ff050b5faf740da4e9c3fb08e70e29d60d))
18
+
19
+ ## [7.7.0](https://www.github.com/bcoe/c8/compare/v7.6.0...v7.7.0) (2021-03-30)
20
+
21
+
22
+ ### Features
23
+
24
+ * introduce --exclude-after-remap flag ([#293](https://www.github.com/bcoe/c8/issues/293)) ([53c4234](https://www.github.com/bcoe/c8/commit/53c42347e0ed4eb29e37b84d40768eed89bf9eb0)), closes [#224](https://www.github.com/bcoe/c8/issues/224)
25
+
26
+ ## [7.6.0](https://www.github.com/bcoe/c8/compare/v7.5.0...v7.6.0) (2021-02-17)
27
+
28
+
29
+ ### Features
30
+
31
+ * add --skip-full ([#287](https://www.github.com/bcoe/c8/issues/287)) ([8b01b63](https://www.github.com/bcoe/c8/commit/8b01b63740d7af75fe83d0164c0f18021592e1a6))
32
+
5
33
  ## [7.5.0](https://www.github.com/bcoe/c8/compare/v7.4.0...v7.5.0) (2021-02-01)
6
34
 
7
35
 
package/index.d.ts CHANGED
@@ -2,8 +2,9 @@ export type Watermark = [number, number];
2
2
 
3
3
  export declare class Report {
4
4
  constructor(opts: {
5
- exclude?: any[],
6
- include?: any[],
5
+ exclude?: string | string[],
6
+ excludeAfterRemap?: boolean,
7
+ include?: string | string[],
7
8
  reporter: string[],
8
9
  reportsDirectory?: string,
9
10
  tempDirectory?: string,
@@ -18,7 +19,7 @@ export declare class Report {
18
19
  resolve?: string,
19
20
  all?: boolean,
20
21
  src?: Array<string>,
21
- allowExternal: boolean
22
+ allowExternal?: boolean
22
23
  })
23
24
  run(): Promise<void>;
24
25
  }
@@ -13,6 +13,7 @@ exports.outputReport = async function (argv) {
13
13
  const report = Report({
14
14
  include: argv.include,
15
15
  exclude: argv.exclude,
16
+ excludeAfterRemap: argv.excludeAfterRemap,
16
17
  reporter: Array.isArray(argv.reporter) ? argv.reporter : [argv.reporter],
17
18
  reportsDirectory: argv['reports-dir'],
18
19
  tempDirectory: argv.tempDirectory,
@@ -22,7 +23,8 @@ exports.outputReport = async function (argv) {
22
23
  wrapperLength: argv.wrapperLength,
23
24
  all: argv.all,
24
25
  allowExternal: argv.allowExternal,
25
- src: argv.src
26
+ src: argv.src,
27
+ skipFull: argv.skipFull
26
28
  })
27
29
  await report.run()
28
30
  if (argv.checkCoverage) await checkCoverages(argv, report)
package/lib/parse-args.js CHANGED
@@ -26,6 +26,12 @@ function buildYargs (withCommands = false) {
26
26
  default: defaultExclude,
27
27
  describe: 'a list of specific files and directories that should be excluded from coverage (glob patterns are supported)'
28
28
  })
29
+ .option('exclude-after-remap', {
30
+ alias: 'a',
31
+ type: 'boolean',
32
+ default: false,
33
+ describe: 'apply exclude logic to files after they are remapped by a source-map'
34
+ })
29
35
  .option('include', {
30
36
  alias: 'n',
31
37
  default: [],
@@ -101,6 +107,11 @@ function buildYargs (withCommands = false) {
101
107
  describe: 'supplying --src will override cwd as the default location where --all looks for src files. --src can be ' +
102
108
  'supplied multiple times and each directory will be included. This allows for workspaces spanning multiple projects'
103
109
  })
110
+ .options('skip-full', {
111
+ default: false,
112
+ type: 'boolean',
113
+ describe: 'do not show files with 100% statement, branch, and function coverage'
114
+ })
104
115
  .pkgConf('c8')
105
116
  .config(config)
106
117
  .demandCommand(1)
package/lib/report.js CHANGED
@@ -1,10 +1,10 @@
1
1
  const Exclude = require('test-exclude')
2
- const furi = require('furi')
3
2
  const libCoverage = require('istanbul-lib-coverage')
4
3
  const libReport = require('istanbul-lib-report')
5
4
  const reports = require('istanbul-reports')
6
5
  const { readdirSync, readFileSync, statSync } = require('fs')
7
6
  const { isAbsolute, resolve, extname } = require('path')
7
+ const { pathToFileURL, fileURLToPath } = require('url')
8
8
  const getSourceMapFromFile = require('./source-map-from-file')
9
9
  // TODO: switch back to @c88/v8-coverage once patch is landed.
10
10
  const v8toIstanbul = require('v8-to-istanbul')
@@ -15,6 +15,7 @@ const debuglog = util.debuglog('c8')
15
15
  class Report {
16
16
  constructor ({
17
17
  exclude,
18
+ excludeAfterRemap,
18
19
  include,
19
20
  reporter,
20
21
  reportsDirectory,
@@ -25,7 +26,8 @@ class Report {
25
26
  resolve: resolvePaths,
26
27
  all,
27
28
  src,
28
- allowExternal = false
29
+ allowExternal = false,
30
+ skipFull
29
31
  }) {
30
32
  this.reporter = reporter
31
33
  this.reportsDirectory = reportsDirectory
@@ -37,11 +39,13 @@ class Report {
37
39
  include: include,
38
40
  relativePath: !allowExternal
39
41
  })
42
+ this.excludeAfterRemap = excludeAfterRemap
40
43
  this.omitRelative = omitRelative
41
44
  this.sourceMapCache = {}
42
45
  this.wrapperLength = wrapperLength
43
46
  this.all = all
44
47
  this.src = this._getSrc(src)
48
+ this.skipFull = skipFull
45
49
  }
46
50
 
47
51
  _getSrc (src) {
@@ -61,13 +65,13 @@ class Report {
61
65
  coverageMap: await this.getCoverageMapFromAllCoverageFiles()
62
66
  })
63
67
 
64
- this.reporter.forEach(function (_reporter) {
68
+ for (const _reporter of this.reporter) {
65
69
  reports.create(_reporter, {
66
70
  skipEmpty: false,
67
- skipFull: false,
71
+ skipFull: this.skipFull,
68
72
  maxCols: 100
69
73
  }).execute(context)
70
- })
74
+ }
71
75
  }
72
76
 
73
77
  async getCoverageMapFromAllCoverageFiles () {
@@ -86,7 +90,11 @@ class Report {
86
90
  try {
87
91
  const sources = this._getSourceMap(v8ScriptCov)
88
92
  const path = resolve(this.resolve, v8ScriptCov.url)
89
- const converter = v8toIstanbul(path, this.wrapperLength, sources)
93
+ const converter = v8toIstanbul(path, this.wrapperLength, sources, (path) => {
94
+ if (this.excludeAfterRemap) {
95
+ return !this.exclude.shouldInstrument(path)
96
+ }
97
+ })
90
98
  await converter.load()
91
99
 
92
100
  if (resultCountPerPath.has(path)) {
@@ -131,8 +139,8 @@ class Report {
131
139
  */
132
140
  _getSourceMap (v8ScriptCov) {
133
141
  const sources = {}
134
- if (this.sourceMapCache[`file://${v8ScriptCov.url}`]) {
135
- const sourceMapAndLineLengths = this.sourceMapCache[`file://${v8ScriptCov.url}`]
142
+ const sourceMapAndLineLengths = this.sourceMapCache[pathToFileURL(v8ScriptCov.url).href]
143
+ if (sourceMapAndLineLengths) {
136
144
  // See: https://github.com/nodejs/node/pull/34305
137
145
  if (!sourceMapAndLineLengths.data) return
138
146
  sources.sourceMap = {
@@ -165,7 +173,7 @@ class Report {
165
173
  for (const v8ProcessCov of this._loadReports()) {
166
174
  if (this._isCoverageObject(v8ProcessCov)) {
167
175
  if (v8ProcessCov['source-map-cache']) {
168
- Object.assign(this.sourceMapCache, v8ProcessCov['source-map-cache'])
176
+ Object.assign(this.sourceMapCache, this._normalizeSourceMapCache(v8ProcessCov['source-map-cache']))
169
177
  }
170
178
  v8ProcessCovs.push(this._normalizeProcessCov(v8ProcessCov, fileIndex))
171
179
  }
@@ -186,7 +194,7 @@ class Report {
186
194
  const stat = statSync(fullPath)
187
195
  const sourceMap = getSourceMapFromFile(fullPath)
188
196
  if (sourceMap) {
189
- this.sourceMapCache[`file://${fullPath}`] = { data: sourceMap }
197
+ this.sourceMapCache[pathToFileURL(fullPath)] = { data: sourceMap }
190
198
  }
191
199
  emptyReports.push({
192
200
  scriptId: 0,
@@ -267,20 +275,38 @@ class Report {
267
275
  }
268
276
  if (/^file:\/\//.test(v8ScriptCov.url)) {
269
277
  try {
270
- v8ScriptCov.url = furi.toSysPath(v8ScriptCov.url)
278
+ v8ScriptCov.url = fileURLToPath(v8ScriptCov.url)
271
279
  fileIndex.add(v8ScriptCov.url)
272
280
  } catch (err) {
273
281
  debuglog(`${err.stack}`)
274
282
  continue
275
283
  }
276
284
  }
277
- if (this.exclude.shouldInstrument(v8ScriptCov.url) &&
278
- (!this.omitRelative || isAbsolute(v8ScriptCov.url))) {
279
- result.push(v8ScriptCov)
285
+ if ((!this.omitRelative || isAbsolute(v8ScriptCov.url))) {
286
+ if (this.excludeAfterRemap || this.exclude.shouldInstrument(v8ScriptCov.url)) {
287
+ result.push(v8ScriptCov)
288
+ }
280
289
  }
281
290
  }
282
291
  return { result }
283
292
  }
293
+
294
+ /**
295
+ * Normalizes a V8 source map cache.
296
+ *
297
+ * This function normalizes file URLs to a system-independent format.
298
+ *
299
+ * @param v8SourceMapCache V8 source map cache to normalize.
300
+ * @return {v8SourceMapCache} Normalized V8 source map cache.
301
+ * @private
302
+ */
303
+ _normalizeSourceMapCache (v8SourceMapCache) {
304
+ const cache = {}
305
+ for (const fileURL of Object.keys(v8SourceMapCache)) {
306
+ cache[pathToFileURL(fileURLToPath(fileURL)).href] = v8SourceMapCache[fileURL]
307
+ }
308
+ return cache
309
+ }
284
310
  }
285
311
 
286
312
  module.exports = function (opts) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c8",
3
- "version": "7.5.0",
3
+ "version": "7.7.2",
4
4
  "description": "output coverage reports using Node.js' built in coverage",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",
@@ -37,15 +37,14 @@
37
37
  "@istanbuljs/schema": "^0.1.2",
38
38
  "find-up": "^5.0.0",
39
39
  "foreground-child": "^2.0.0",
40
- "furi": "^2.0.0",
41
40
  "istanbul-lib-coverage": "^3.0.0",
42
41
  "istanbul-lib-report": "^3.0.0",
43
42
  "istanbul-reports": "^3.0.2",
44
43
  "rimraf": "^3.0.0",
45
44
  "test-exclude": "^6.0.0",
46
45
  "v8-to-istanbul": "^7.1.0",
47
- "yargs": "^16.0.0",
48
- "yargs-parser": "^20.0.0"
46
+ "yargs": "^16.2.0",
47
+ "yargs-parser": "^20.2.7"
49
48
  },
50
49
  "devDependencies": {
51
50
  "chai": "^4.2.0",