@plugjs/cov8 0.7.13 → 0.7.15

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/src/coverage.ts CHANGED
@@ -10,10 +10,32 @@ import { walk } from '@plugjs/plug/utils'
10
10
  import { createAnalyser } from './analysis.ts'
11
11
  import { coverageReport } from './report.ts'
12
12
 
13
+ import type { Report, ReportLevel } from '@plugjs/plug/logging'
13
14
  import type { AbsolutePath } from '@plugjs/plug/paths'
14
15
  import type { Context, PipeParameters, Plug } from '@plugjs/plug/pipe'
15
16
  import type { CoverageReportOptions } from './index.ts'
16
- import type { CoverageResult } from './report.ts'
17
+ import type { CoverageReport, CoverageResult } from './report.ts'
18
+
19
+ function reportUncovered(
20
+ report: Report,
21
+ level: ReportLevel,
22
+ file: AbsolutePath,
23
+ lines: number[],
24
+ ): void {
25
+ if (! lines.length) return
26
+
27
+ const ranges: string[] = []
28
+ for (let i = 0; i < lines.length; i++) {
29
+ const start = lines[i]!
30
+ let end = start
31
+ while (lines[i + 1] === end + 1) {
32
+ end = lines[++i]!
33
+ }
34
+ ranges.push(start === end ? `${start}` : `${start}\u2026${end}`)
35
+ }
36
+
37
+ report.add({ level, file, message: `Uncovered lines ${ranges.join(', ')}` })
38
+ }
17
39
 
18
40
  export class Coverage implements Plug<Files | undefined> {
19
41
  constructor(...args: PipeParameters<'coverage'>)
@@ -42,46 +64,43 @@ export class Coverage implements Plug<Files | undefined> {
42
64
  context.log.info('Parsed', coverageFiles.length, 'coverage files', $ms(Date.now() - ms1))
43
65
 
44
66
  const ms2 = Date.now()
45
- const report = await coverageReport(analyser, sourceFiles, context.log)
67
+ let report: CoverageReport
68
+ try {
69
+ report = await coverageReport(analyser, sourceFiles, context.log)
70
+ } finally {
71
+ analyser.destroy()
72
+ }
46
73
  context.log.info('Analysed', sourceFiles.length, 'source files', $ms(Date.now() - ms2))
47
74
 
48
- analyser.destroy()
49
-
50
75
  const {
51
76
  minimumCoverage = 50,
52
77
  minimumFileCoverage = minimumCoverage,
53
78
  optimalCoverage = Math.round((100 + minimumCoverage) / 2),
54
79
  optimalFileCoverage = Math.round((100 + minimumFileCoverage) / 2),
80
+ reportUncoveredLines = false,
55
81
  } = this._options
56
82
 
57
- let max = 0
58
- for (const file in report) {
59
- if (file.length > max) max = file.length
60
- }
61
-
62
- let maxLength = 0
63
- for (const file in report.results) {
64
- if (file.length > maxLength) maxLength = file.length
65
- }
66
-
67
83
  let fileErrors = 0
68
84
  let fileWarnings = 0
69
85
  const _report = context.log.report('Coverage report')
70
86
 
71
87
  for (const [ _file, result ] of Object.entries(report.results)) {
72
- const { coverage } = result.nodeCoverage
88
+ const { nodeCoverage: { coverage }, uncoveredLines } = result
73
89
  const file = _file as AbsolutePath
74
90
 
75
91
  if (coverage == null) {
76
92
  _report.annotate(NOTICE, file, 'n/a')
77
93
  } else if (coverage < minimumFileCoverage) {
78
94
  _report.annotate(ERROR, file, `${coverage} %`)
95
+ if (reportUncoveredLines) reportUncovered(_report, ERROR, file, uncoveredLines)
79
96
  fileErrors ++
80
97
  } else if (coverage < optimalFileCoverage) {
81
98
  _report.annotate(WARN, file, `${coverage} %`)
99
+ if (reportUncoveredLines) reportUncovered(_report, WARN, file, uncoveredLines)
82
100
  fileWarnings ++
83
101
  } else {
84
102
  _report.annotate(NOTICE, file, `${coverage} %`)
103
+ if (reportUncoveredLines) reportUncovered(_report, NOTICE, file, uncoveredLines)
85
104
  }
86
105
  }
87
106
 
@@ -110,14 +129,17 @@ export class Coverage implements Plug<Files | undefined> {
110
129
  _report.add({ level: WARN, message })
111
130
  }
112
131
 
113
- /* If we don't have to write a report, pass-through the coverage files */
114
- if (this._options.reportDir == null) return _report.done(false) as any
132
+ /* Finish console reporting when no report files were requested */
133
+ if (this._options.reportDir == null) {
134
+ _report.done(false)
135
+ return
136
+ }
115
137
 
116
138
  /* Create a builder to emit our reports */
117
139
  const reportDir = context.resolve(this._options.reportDir)
118
140
  const builder = Files.builder(reportDir)
119
141
 
120
- /* Thresholds to inject in the report */
142
+ /* Thresholds to include in the report */
121
143
  const date = new Date().toISOString()
122
144
  const thresholds = {
123
145
  minimumCoverage,
@@ -132,20 +154,20 @@ export class Coverage implements Plug<Files | undefined> {
132
154
  /* The HTML file rendering our report */
133
155
  await builder.write('index.html', html)
134
156
 
135
- /* The JSONP file (for our HTML report) has relative files and a tree */
157
+ /* The HTML report data uses paths relative to the input file set and a directory tree */
136
158
  const results: Record<string, CoverageResult> = {}
137
159
  for (const [ rel, abs ] of files.pathMappings()) {
138
160
  results[rel] = report.results[abs]!
139
161
  }
140
162
 
141
- const tree: Record<string, any> = {}
163
+ const tree: Record<string, any> = Object.create(null)
142
164
  for (const relative of Object.keys(results)) {
143
165
  const directories = relative.split(sep)
144
166
  const file = directories.pop()!
145
167
 
146
168
  let node = tree
147
169
  for (const dir of directories) {
148
- node = node[dir] = node[dir] || {}
170
+ node = node[dir] = node[dir] || Object.create(null)
149
171
  }
150
172
 
151
173
  node[file] = relative
@@ -158,6 +180,6 @@ export class Coverage implements Plug<Files | undefined> {
158
180
  _report.done(false)
159
181
 
160
182
  /* Return emitted files */
161
- return builder.build() as any
183
+ return builder.build()
162
184
  }
163
185
  }
package/src/index.ts CHANGED
@@ -4,54 +4,54 @@ import { Coverage } from './coverage.ts'
4
4
 
5
5
  import type { SourceMapBias } from './analysis.ts'
6
6
 
7
- /** Options to analyse coverage reports */
7
+ /** Options for analysing coverage and checking node coverage thresholds. */
8
8
  export interface CoverageOptions {
9
- /** The bias for source map analisys (defaults to `greatest_lower_bound`) */
9
+ /** The bias for source map analysis (defaults to `least_upper_bound`). */
10
10
  sourceMapBias?: SourceMapBias
11
- /** Minimum _overall_ coverage (as a percentage, defaults to 50) */
11
+ /** Minimum _overall_ coverage (as a percentage, defaults to 50). */
12
12
  minimumCoverage?: number,
13
- /** Optimal _overall_ coverage (as a percentage, defaults to 50) */
13
+ /** Optimal _overall_ coverage (defaults to the rounded midpoint of minimumCoverage and 100: 75). */
14
14
  optimalCoverage?: number,
15
- /** Minimum _per-file_ coverage (as a percentage, defaults to 75) */
15
+ /** Minimum _per-file_ coverage (defaults to minimumCoverage: 50). */
16
16
  minimumFileCoverage?: number,
17
- /** Optimal _per-file_ coverage (as a percentage, defaults to 75) */
17
+ /** Optimal _per-file_ coverage (defaults to the rounded midpoint of minimumFileCoverage and 100: 75). */
18
18
  optimalFileCoverage?: number,
19
+ /** Include uncovered line ranges in console reports (defaults to `false`). */
20
+ reportUncoveredLines?: boolean
19
21
  }
20
22
 
21
23
  export interface CoverageReportOptions extends CoverageOptions {
22
- /** If specified, a JSON and HTML report will be written to this directory */
24
+ /** Directory for report.json, index.html, and the report.js data file. */
23
25
  reportDir: string,
24
26
  }
25
27
 
26
28
  declare module '@plugjs/plug' {
27
29
  export interface Pipe {
28
30
  /**
29
- * Analyse coverage using files generated by V8/NodeJS.
31
+ * Analyse coverage using files generated by V8/Node.js.
30
32
  *
31
33
  * @param coverageDir The directory where the `coverage-XXX.json` files
32
- * generated by V8/NodeJS can be found.
34
+ * generated by V8/Node.js can be found.
33
35
  */
34
36
  coverage(coverageDir: string): Promise<undefined>
35
37
  /**
36
- * Analyse coverage using files generated by V8/NodeJS.
38
+ * Analyse coverage using files generated by V8/Node.js and produce an HTML
39
+ * report in the directory specified in `options`.
37
40
  *
38
41
  * @param coverageDir The directory where the `coverage-XXX.json` files
39
- * generated by V8/NodeJS can be found.
40
- * @param options Extra {@link CoverageOptions | options} allowing to
41
- * specify coverage thresholds.
42
+ * generated by V8/Node.js can be found.
43
+ * @param options Coverage thresholds and the report output directory.
44
+ * @returns A pipe containing the generated report files.
42
45
  */
43
- coverage(coverageDir: string, options: CoverageOptions): Promise<undefined>
46
+ coverage(coverageDir: string, options: CoverageReportOptions): Pipe
44
47
  /**
45
- * Analyse coverage using files generated by V8/NodeJS and produce an HTML
46
- * report in the directory specified in `options`.
48
+ * Analyse coverage using files generated by V8/Node.js.
47
49
  *
48
50
  * @param coverageDir The directory where the `coverage-XXX.json` files
49
- * generated by V8/NodeJS can be found.
50
- * @param options Extra {@link CoverageOptions | options} allowing to
51
- * specify coverage thresholds where the HTML report should
52
- * be written to.
51
+ * generated by V8/Node.js can be found.
52
+ * @param options Coverage thresholds and console reporting options.
53
53
  */
54
- coverage(coverageDir: string, options: CoverageReportOptions): Pipe
54
+ coverage(coverageDir: string, options: CoverageOptions): Promise<undefined>
55
55
  }
56
56
  }
57
57
 
package/src/report.ts CHANGED
@@ -4,12 +4,16 @@ import { parse } from '@babel/parser'
4
4
  import {
5
5
  isDeclaration,
6
6
  isExportDeclaration,
7
+ isExportNamedDeclaration,
7
8
  isFile,
8
9
  isIfStatement,
9
10
  isImportDeclaration,
10
11
  isProgram,
11
12
  isTryStatement,
12
13
  isTSDeclareMethod,
14
+ isTSEnumDeclaration,
15
+ isTSEnumMember,
16
+ isTSModuleDeclaration,
13
17
  isTSTypeReference,
14
18
  isTypeScript,
15
19
  VISITOR_KEYS,
@@ -28,79 +32,81 @@ import type { CoverageAnalyser } from './analysis.ts'
28
32
  * ========================================================================== */
29
33
 
30
34
  /**
31
- * A constant indicating that coverage was skipped (is irrelevant, for e.g.
32
- * comment or typescript definition nodes)
35
+ * Coverage is not applicable, for example to comments or erased TypeScript
36
+ * syntax. Skipped nodes do not contribute to coverage totals.
33
37
  */
34
38
  export const COVERAGE_SKIPPED = -2
35
39
 
36
40
  /**
37
- * A constant indicating that coverage was intentionally ignored because of a
38
- * specific "coverage ignore ..." comment
41
+ * Coverage was explicitly ignored by a `coverage ignore ...` or
42
+ * `istanbul ignore ...` comment.
39
43
  */
40
44
  export const COVERAGE_IGNORED = -1
41
45
 
42
- /** Node coverage summary */
46
+ /** Node coverage summary. */
43
47
  export interface NodeCoverageResult {
44
- /** Number of _covered_ nodes (good!) */
48
+ /** Number of nodes with a positive execution count. */
45
49
  coveredNodes: number,
46
- /** Number of nodes with _no coverage_ (bad!) */
50
+ /** Number of nodes with a zero execution count. */
47
51
  missingNodes: number,
48
- /** Number of nodes ignored by comments like `coverage ignore xxx` */
52
+ /** Number of nodes ignored by comments like `coverage ignore xxx`. */
49
53
  ignoredNodes: number,
50
- /** Total number of nodes (sum of `covered`, `missing` and `ignored`) */
54
+ /** Sum of coveredNodes, missingNodes, and ignoredNodes; excludes skipped nodes. */
51
55
  totalNodes: number,
52
56
  /**
53
- * Percentage of code coverage (covered as a % of total - ignored nodes)
57
+ * Node coverage percentage, rounded down: 100 * coveredNodes /
58
+ * (coveredNodes + missingNodes).
54
59
  *
55
- * A `null` value for this field indicates that no coverage data was generated
56
- * either because the source was all ignored or skipped (e.g. when using
57
- * `coverage ignore file` or when covering a TS source only with types).
60
+ * Null when no nodes remain after excluding ignored and skipped nodes,
61
+ * including empty files, ignored files, and files containing only types.
58
62
  */
59
63
  coverage: number | null,
60
64
  }
61
65
 
62
- /** Per-file coverage result */
66
+ /** Per-file coverage result. */
63
67
  export interface CoverageResult {
64
- /** The actual code this coverage is for */
68
+ /** The original source text. */
65
69
  code: string,
66
70
  /**
67
- * Per _character_ coverage report:
68
- * - `-2`: coverage skipped (comments, typescript declarations, ...)
71
+ * Coverage for each UTF-16 code unit in the source, derived from AST node spans:
72
+ * - `-2`: coverage skipped (comments, erased TypeScript syntax, etc.)
69
73
  * - `-1`: coverage ignored (when using `coverage ignore xxx`)
70
- * - `0`: no coverage collected for this character
71
- * - _any number greater than zero_: number of times this was covered
74
+ * - `0`: uncovered code
75
+ * - positive values: execution counts assigned from the corresponding AST nodes
72
76
  */
73
77
  codeCoverage: number[],
74
- /** Node coverage summary */
78
+ /** Unique one-based line numbers containing any uncovered code, in ascending order. */
79
+ uncoveredLines: number[],
80
+ /** Node coverage summary. */
75
81
  nodeCoverage: NodeCoverageResult,
76
82
  }
77
83
 
78
- /** Aggregation of {@link CoverageResult} over all files */
84
+ /** Aggregation of {@link CoverageResult} over all files. */
79
85
  export type CoverageResults = Record<AbsolutePath, CoverageResult>
80
86
 
81
- /** Our coverage report, per file */
87
+ /** Per-file results and the aggregate node coverage summary. */
82
88
  export interface CoverageReport {
83
89
  results: CoverageResults,
84
90
  nodes: NodeCoverageResult,
85
91
  }
86
92
 
87
93
  /* ========================================================================== *
88
- * EXPORTED CONSTANTS AND TYPES *
94
+ * IGNORE DIRECTIVES *
89
95
  * ========================================================================== */
90
96
 
91
- /** Tokens for `coverage ignore xxx`, this should be self-explanatory */
97
+ /** Supported targets for coverage-ignore comments. */
92
98
  type IgnoreCoverage = 'test' | 'if' | 'else' | 'try' | 'catch' | 'finally' | 'next' | 'prev' | 'file'
93
99
 
94
- /** Regular expression matching strings like `coverage ignore xxx` */
100
+ /** Match a leading `coverage ignore` or `istanbul ignore` directive in a comment. */
95
101
  const ignoreRegexp = /^\s+(coverage|istanbul)\s+ignore\s+(test|if|else|try|catch|finally|next|prev|file)(\s|$)/g
96
102
 
97
103
  /* ========================================================================== *
98
- * EXPORTED CONSTANTS AND TYPES *
104
+ * REPORT GENERATION *
99
105
  * ========================================================================== */
100
106
 
101
107
  /**
102
- * Analyse coverage for the specified source files, using the data from the
103
- * specified coverage files and produce a {@link CoverageReport}.
108
+ * Analyse the original source files with the supplied coverage analyser and
109
+ * return character-level coverage and AST node summaries.
104
110
  */
105
111
  export async function coverageReport(
106
112
  analyser: CoverageAnalyser,
@@ -118,17 +124,16 @@ export async function coverageReport(
118
124
  }
119
125
 
120
126
  /*
121
- * Here comes the interesting part: we need to parse the original soruces,
122
- * walk their ASTs and see whether each node has been covered or not.
123
- * We look up every node's position, (for sitemaps, map this to the position
124
- * in the resulting file) then look at the coverage.
125
- */
127
+ * Parse each original source and query coverage at each counted node's start.
128
+ * The analyser handles any mapping from original to generated positions.
129
+ */
126
130
  for (const file of sourceFiles) {
127
- /* Read up the file and parse the tree in the most liberal way possible */
131
+ /* Read the source and parse it with permissive JavaScript and TypeScript options */
128
132
  const url = pathToFileURL(file).toString()
129
133
  const code = await readFile(file, 'utf-8')
130
134
 
131
135
  let tree: ParseResult<File>
136
+ /* coverage ignore catch */
132
137
  try {
133
138
  tree = parse(code, {
134
139
  allowImportExportEverywhere: true,
@@ -233,16 +238,16 @@ export async function coverageReport(
233
238
 
234
239
  /* Visit a node and evaluate its coverage */
235
240
  const visitNode = (node: Node, depth: number): void => {
236
- /* See what we're doing here... */
241
+ /* Trace the node type and source position */
237
242
  log.trace('-'.padStart((depth * 2) + 1, ' '), node.type, `${node.loc?.start.line}:${node.loc?.start.column}`)
238
243
 
239
244
  /* Root nodes (file and program) simply go to their children */
240
- // coverage ignore if / we start visiting at file.program.body!
245
+ // coverage ignore if / traversal starts with the children of tree.program
241
246
  if (isFile(node)) return visitChildren(node, depth)
242
- // coverage ignore if / we start visiting at file.program.body!
247
+ // coverage ignore if / traversal starts with the children of tree.program
243
248
  if (isProgram(node)) return visitChildren(node, depth)
244
249
 
245
- /* Figure out if we have some "coverage ignore xxxx" in comments */
250
+ /* Read ignore directives from comments attached to this node */
246
251
  const ignores: IgnoreCoverage[] = []
247
252
  for (const comment of node.leadingComments || []) {
248
253
  for (const match of comment.value.matchAll(ignoreRegexp)) {
@@ -255,19 +260,45 @@ export async function coverageReport(
255
260
  }
256
261
  }
257
262
 
258
- /* Skip this node if we have a "coverage ignore next" comment */
263
+ /* Ignore this subtree when a next or prev directive applies */
259
264
  if (ignores.includes('next')) return setCodeCoverage(node, COVERAGE_IGNORED, true)
260
265
  if (ignores.includes('prev')) return setCodeCoverage(node, COVERAGE_IGNORED, true)
261
266
 
262
- /* Typescript nodes are skipped, but children aren't in some cases */
263
- if (isTypeScript(node)) {
264
- /* Functions/constructors overloads */
267
+ /* An enum's export wrapper must not count when the enum itself is erased */
268
+ if (isExportNamedDeclaration(node) && isTSEnumDeclaration(node.declaration)) {
269
+ setCodeCoverage(node, COVERAGE_SKIPPED, false)
270
+ return visitNode(node.declaration, depth + 1)
271
+ }
272
+
273
+ /* Namespace syntax is skipped, but non-ambient bodies execute */
274
+ if (isTSModuleDeclaration(node)) {
275
+ setCodeCoverage(node, COVERAGE_SKIPPED, true)
276
+ if (node.declare || node.kind === 'global' || node.id.type === 'StringLiteral') return
277
+ return visitNode(node.body, depth + 1)
278
+ }
279
+
280
+ /* Enum members execute; the declaration wrapper and name do not */
281
+ if (isTSEnumDeclaration(node)) {
282
+ setCodeCoverage(node, COVERAGE_SKIPPED, true)
283
+ if (node.declare) return
284
+ /* Const enums can be erased: only count them when members have generated code */
285
+ if (node.const && ! node.body.members.some((member) => {
286
+ const start = member.loc?.start
287
+ return start && analyser.hasMapping(url, start.line, start.column)
288
+ })) return
289
+ for (const member of node.body.members) visitNode(member, depth + 1)
290
+ return
291
+ }
292
+
293
+ /* Skip TypeScript syntax while visiting runtime children where applicable */
294
+ if (isTypeScript(node) && ! isTSEnumMember(node)) {
295
+ /* Method and constructor overload signatures */
265
296
  if (isTSDeclareMethod(node)) return setCodeCoverage(node, COVERAGE_SKIPPED, true)
266
297
 
267
- /* References to imported types */
298
+ /* Type references and their type arguments */
268
299
  if (isTSTypeReference(node)) return setCodeCoverage(node, COVERAGE_SKIPPED, true)
269
300
 
270
- /* Generic typescript declarations */
301
+ /* Skip remaining TypeScript declarations */
271
302
  if (isDeclaration(node)) return setCodeCoverage(node, COVERAGE_SKIPPED, true)
272
303
 
273
304
  /* For things like "X as Y": the "as" node wraps the expression */
@@ -275,7 +306,7 @@ export async function coverageReport(
275
306
  return visitChildren(node, depth) // visit all children normally...
276
307
  }
277
308
 
278
- // Typescript "import type" or "export type" get skipped all together
309
+ // Skip declarations marked as "import type" or "export type".
279
310
  if (isExportDeclaration(node) && (node.exportKind === 'type')) {
280
311
  return setCodeCoverage(node, COVERAGE_SKIPPED, true)
281
312
  }
@@ -300,6 +331,12 @@ export async function coverageReport(
300
331
  /* Record the code coverage, and set up our variables */
301
332
  setCodeCoverage(node, coverage, false)
302
333
 
334
+ /* Count each enum member once, then analyse any initializer expression */
335
+ if (isTSEnumMember(node)) {
336
+ if (node.initializer) visitNode(node.initializer, depth + 1)
337
+ return
338
+ }
339
+
303
340
  /* The "if" node might have some ignores... */
304
341
  if (isIfStatement(node)) {
305
342
  maybeIgnoreNode(ignores.includes('test'), node.test, depth + 1)
@@ -316,7 +353,7 @@ export async function coverageReport(
316
353
  return
317
354
  }
318
355
 
319
- /* All other nodes simply gets visited recursively*/
356
+ /* Visit the children of all other nodes recursively*/
320
357
  visitChildren(node, depth)
321
358
  }
322
359
 
@@ -325,14 +362,15 @@ export async function coverageReport(
325
362
  setCodeCoverage(tree.program.directives, 0, true) // directives must be covered
326
363
  setCodeCoverage(tree.program.body, 0, true) // program body must be covered
327
364
 
328
- /* Cleanup our node statistics */
365
+ /* Reset the counters accumulated while initializing character coverage. */
329
366
  nodeCoverage.coveredNodes = 0
330
367
  nodeCoverage.missingNodes = 0
331
368
  nodeCoverage.ignoredNodes = 0
332
369
 
333
- /* Check if one of the first comments is "coverage ignore file" */
370
+ /* Check leading comments on the first directive or body statement for a file ignore. */
334
371
  let ignoreFileCoverage = false
335
- for (const comment of tree.program.body[0]?.leadingComments || []) {
372
+ const firstNode = tree.program.directives[0] ?? tree.program.body[0]
373
+ for (const comment of firstNode?.leadingComments || []) {
336
374
  for (const match of comment.value.matchAll(ignoreRegexp)) {
337
375
  if (match[2] === 'file') {
338
376
  ignoreFileCoverage = true
@@ -351,13 +389,23 @@ export async function coverageReport(
351
389
  }
352
390
 
353
391
  /*
354
- * As comments are mixed within codes (and do not get visited in the
355
- * tree) we force-skip them _AFTER_ the tree is visited, otherwise (for
356
- * example) a comment within a block will be shown with the coverage of
357
- * the block itself.
392
+ * Comments are not visited through VISITOR_KEYS. Mark them as skipped after
393
+ * traversing the AST so they do not retain coverage from enclosing nodes.
358
394
  */
359
395
  setCodeCoverage(tree.comments, COVERAGE_SKIPPED, false)
360
396
 
397
+ /* Collect uncovered lines after children and comments have finalized coverage */
398
+ const uncoveredLinesSet = new Set<number>()
399
+ let line = 1
400
+ for (let i = 0; i < code.length; i++) {
401
+ if (code[i] === '\n') {
402
+ line++
403
+ } else if (code[i] !== '\r' && codeCoverage[i] === 0) {
404
+ uncoveredLinesSet.add(line)
405
+ }
406
+ }
407
+ const uncoveredLines = [ ...uncoveredLinesSet ]
408
+
361
409
  /* Update nodes coverage results */
362
410
  updateNodeCoverageResult(nodeCoverage)
363
411
 
@@ -367,7 +415,7 @@ export async function coverageReport(
367
415
  nodes.totalNodes += nodeCoverage.totalNodes
368
416
 
369
417
  /* This file is done, add it to the report */
370
- results[file] = { code, codeCoverage, nodeCoverage }
418
+ results[file] = { code, codeCoverage, uncoveredLines, nodeCoverage }
371
419
  }
372
420
 
373
421
  /* All done, return the report */
@@ -379,7 +427,7 @@ function updateNodeCoverageResult(result: NodeCoverageResult): void {
379
427
  const { coveredNodes, missingNodes, ignoredNodes } = result
380
428
  const totalNodes = result.totalNodes = coveredNodes + missingNodes + ignoredNodes
381
429
  if (totalNodes === 0) {
382
- result.coverage = null // No "total" nodes, means all ignored
430
+ result.coverage = null // No counted nodes: the source is empty or entirely skipped.
383
431
  } else if (totalNodes === ignoredNodes) {
384
432
  result.coverage = null // All nodes were ignored (e.g. coverage ignore file)
385
433
  } else {