| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e024712 commit dccee04
15 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2867,6 +2867,21 @@ This option may be specified multiple times to include multiple glob patterns. | |||
| 2867 | 2867 | If both `--test-coverage-exclude` and `--test-coverage-include` are provided, | |
| 2868 | 2868 | files must meet **both** criteria to be included in the coverage report. | |
| 2869 | 2869 | ||
| 2870 | + ### `--test-coverage-include-all` | ||
| 2871 | + | ||
| 2872 | + <!-- YAML | ||
| 2873 | + added: REPLACEME | ||
| 2874 | + --> | ||
| 2875 | + | ||
| 2876 | + > Stability: 1 - Experimental | ||
| 2877 | + | ||
| 2878 | + Includes source files that were never loaded by the test run in the coverage | ||
| 2879 | + report, where they are reported as having zero coverage. | ||
| 2880 | + | ||
| 2881 | + Candidate files are searched for in the current working directory, and are | ||
| 2882 | + subject to the same `--test-coverage-include` and `--test-coverage-exclude` | ||
| 2883 | + filtering as the rest of the report. | ||
| 2884 | + | ||
| 2870 | 2885 | ### `--test-coverage-lines=threshold` | |
| 2871 | 2886 | ||
| 2872 | 2887 | <!-- YAML | |
@@ -3904,6 +3919,7 @@ one is included in the list below. | |||
| 3904 | 3919 | * `--test-coverage-branches` | |
| 3905 | 3920 | * `--test-coverage-exclude` | |
| 3906 | 3921 | * `--test-coverage-functions` | |
| 3922 | + * `--test-coverage-include-all` | ||
| 3907 | 3923 | * `--test-coverage-include` | |
| 3908 | 3924 | * `--test-coverage-lines` | |
| 3909 | 3925 | * `--test-global-setup` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1780,6 +1780,13 @@ changes: | |||
| 1780 | 1780 | If both `coverageExcludeGlobs` and `coverageIncludeGlobs` are provided, | |
| 1781 | 1781 | files must meet **both** criteria to be included in the coverage report. | |
| 1782 | 1782 | **Default:** `undefined`. | |
| 1783 | + * `coverageIncludeAll` {boolean} Includes source files that were never loaded by | ||
| 1784 | + the test run in the coverage report, where they are reported as having zero | ||
| 1785 | + coverage. Candidate files are searched for in `cwd`, and are subject to the | ||
| 1786 | + same `coverageIncludeGlobs` and `coverageExcludeGlobs` filtering as the rest | ||
| 1787 | + of the report. This property is only applicable when `coverage` was set to | ||
| 1788 | + `true`. | ||
| 1789 | + **Default:** `false`. | ||
| 1783 | 1790 | * `lineCoverage` {number} Require a minimum percent of covered lines. If code | |
| 1784 | 1791 | coverage does not reach the threshold specified, the process will exit with code `1`. | |
| 1785 | 1792 | **Default:** `0`. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1410,6 +1410,13 @@ This option may be specified multiple times to include multiple glob patterns. | |||
| 1410 | 1410 | If both \fB--test-coverage-exclude\fR and \fB--test-coverage-include\fR are provided, | |
| 1411 | 1411 | files must meet \fBboth\fR criteria to be included in the coverage report. | |
| 1412 | 1412 | . | |
| 1413 | + .It Fl -test-coverage-include-all | ||
| 1414 | + Includes source files that were never loaded by the test run in the coverage | ||
| 1415 | + report, where they are reported as having zero coverage. | ||
| 1416 | + Candidate files are searched for in the current working directory, and are | ||
| 1417 | + subject to the same \fB--test-coverage-include\fR and \fB--test-coverage-exclude\fR | ||
| 1418 | + filtering as the rest of the report. | ||
| 1419 | + . | ||
| 1413 | 1420 | .It Fl -test-coverage-lines Ns = Ns Ar threshold | |
| 1414 | 1421 | Require a minimum percent of covered lines. If code coverage does not reach | |
| 1415 | 1422 | the threshold specified, the process will exit with code \fB1\fR. | |
@@ -2135,6 +2142,8 @@ one is included in the list below. | |||
| 2135 | 2142 | .It | |
| 2136 | 2143 | \fB--test-coverage-functions\fR | |
| 2137 | 2144 | .It | |
| 2145 | + \fB--test-coverage-include-all\fR | ||
| 2146 | + .It | ||
| 2138 | 2147 | \fB--test-coverage-include\fR | |
| 2139 | 2148 | .It | |
| 2140 | 2149 | \fB--test-coverage-lines\fR | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,6 +20,7 @@ const { | |||
| 20 | 20 | } = primordials; | |
| 21 | 21 | const { | |
| 22 | 22 | copyFileSync, | |
| 23 | + globSync, | ||
| 23 | 24 | mkdirSync, | |
| 24 | 25 | mkdtempSync, | |
| 25 | 26 | opendirSync, | |
@@ -29,7 +30,7 @@ const { | |||
| 29 | 30 | const { setupCoverageHooks } = require('internal/util'); | |
| 30 | 31 | const { tmpdir } = require('os'); | |
| 31 | 32 | const { join, resolve, relative } = require('path'); | |
| 32 | - const { fileURLToPath, URL } = require('internal/url'); | ||
| 33 | + const { fileURLToPath, pathToFileURL, URL } = require('internal/url'); | ||
| 33 | 34 | const { kMappings, SourceMap } = require('internal/source_map/source_map'); | |
| 34 | 35 | const { | |
| 35 | 36 | codes: { | |
@@ -48,6 +49,7 @@ const kLineSplitRegex = /(?<=\r?\n)/u; | |||
| 48 | 49 | const kStatusRegex = /\/\* node:coverage (?<status>enable|disable) \*\//; | |
| 49 | 50 | const kTypeOnlyImportRegex = /^\s*import\s+type\b/u; | |
| 50 | 51 | const kTypeScriptSourceRegex = /\.(?:cts|mts|ts)$/u; | |
| 52 | + const kSourceFileGlob = '**/*.{cjs,cts,js,mjs,mts,ts}'; | ||
| 51 | 53 | ||
| 52 | 54 | let stripTypeScriptTypesForCoverage; | |
| 53 | 55 | ||
@@ -407,6 +409,10 @@ class TestCoverage { | |||
| 407 | 409 | this.mergeCoverage(result, this.mapCoverageWithSourceMap(coverage)); | |
| 408 | 410 | } | |
| 409 | 411 | ||
| 412 | + if (this.options.coverageIncludeAll) { | ||
| 413 | + this.#addUntestedFileCoverage(result); | ||
| 414 | + } | ||
| 415 | + | ||
| 410 | 416 | return ArrayFrom(result.values()); | |
| 411 | 417 | } finally { | |
| 412 | 418 | if (dir) { | |
@@ -415,6 +421,48 @@ class TestCoverage { | |||
| 415 | 421 | } | |
| 416 | 422 | } | |
| 417 | 423 | ||
| 424 | + #addUntestedFileCoverage(merged) { | ||
| 425 | + const files = globSync(kSourceFileGlob, { | ||
| 426 | + __proto__: null, | ||
| 427 | + cwd: this.options.cwd, | ||
| 428 | + // Skip node_modules/, since `shouldSkipFileCoverage` would skip it anyway | ||
| 429 | + exclude: (name) => name === 'node_modules', | ||
| 430 | + }); | ||
| 431 | + | ||
| 432 | + for (let i = 0; i < files.length; ++i) { | ||
| 433 | + const url = pathToFileURL(resolve(this.options.cwd, files[i])).href; | ||
| 434 | + | ||
| 435 | + if (merged.has(url) || this.shouldSkipFileCoverage(url)) { | ||
| 436 | + continue; | ||
| 437 | + } | ||
| 438 | + | ||
| 439 | + this.markTypeScriptOnlyLines(url); | ||
| 440 | + const lines = this.getLines(url); | ||
| 441 | + | ||
| 442 | + if (!lines || lines.length === 0) { | ||
| 443 | + continue; | ||
| 444 | + } | ||
| 445 | + | ||
| 446 | + const lastLine = lines[lines.length - 1]; | ||
| 447 | + | ||
| 448 | + merged.set(url, { | ||
| 449 | + __proto__: null, | ||
| 450 | + url, | ||
| 451 | + functions: [{ | ||
| 452 | + __proto__: null, | ||
| 453 | + functionName: '', | ||
| 454 | + isBlockCoverage: false, | ||
| 455 | + ranges: [{ | ||
| 456 | + __proto__: null, | ||
| 457 | + startOffset: 0, | ||
| 458 | + endOffset: lastLine.startOffset + lastLine.src.length, | ||
| 459 | + count: 0, | ||
| 460 | + }], | ||
| 461 | + }], | ||
| 462 | + }); | ||
| 463 | + } | ||
| 464 | + } | ||
| 465 | + | ||
| 418 | 466 | ||
| 419 | 467 | mapCoverageWithSourceMap(coverage) { | |
| 420 | 468 | const { result } = coverage; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -723,6 +723,7 @@ function run(options = kEmptyObject) { | |||
| 723 | 723 | only, | |
| 724 | 724 | globPatterns, | |
| 725 | 725 | coverage = false, | |
| 726 | + coverageIncludeAll = false, | ||
| 726 | 727 | lineCoverage = 0, | |
| 727 | 728 | branchCoverage = 0, | |
| 728 | 729 | functionCoverage = 0, | |
@@ -882,6 +883,7 @@ function run(options = kEmptyObject) { | |||
| 882 | 883 | ||
| 883 | 884 | validateOneOf(isolation, 'options.isolation', ['process', 'none']); | |
| 884 | 885 | validateBoolean(coverage, 'options.coverage'); | |
| 886 | + validateBoolean(coverageIncludeAll, 'options.coverageIncludeAll'); | ||
| 885 | 887 | if (coverageExcludeGlobs != null) { | |
| 886 | 888 | if (!ArrayIsArray(coverageExcludeGlobs)) { | |
| 887 | 889 | coverageExcludeGlobs = [coverageExcludeGlobs]; | |
@@ -923,6 +925,7 @@ function run(options = kEmptyObject) { | |||
| 923 | 925 | ...parseCommandLine(), | |
| 924 | 926 | setup, // This line can be removed when parseCommandLine() is removed here. | |
| 925 | 927 | coverage, | |
| 928 | + coverageIncludeAll, | ||
| 926 | 929 | coverageExcludeGlobs, | |
| 927 | 930 | coverageIncludeGlobs, | |
| 928 | 931 | rerunFailuresFilePath, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -245,6 +245,7 @@ function parseCommandLine() { | |||
| 245 | 245 | ||
| 246 | 246 | const isTestRunner = getOptionValue('--test'); | |
| 247 | 247 | const coverage = getOptionValue('--experimental-test-coverage'); | |
| 248 | + const coverageIncludeAll = getOptionValue('--test-coverage-include-all'); | ||
| 248 | 249 | const forceExit = getOptionValue('--test-force-exit'); | |
| 249 | 250 | const sourceMaps = getOptionValue('--enable-source-maps'); | |
| 250 | 251 | const updateSnapshots = getOptionValue('--test-update-snapshots'); | |
@@ -415,6 +416,7 @@ function parseCommandLine() { | |||
| 415 | 416 | isTestRunner, | |
| 416 | 417 | concurrency, | |
| 417 | 418 | coverage, | |
| 419 | + coverageIncludeAll, | ||
| 418 | 420 | coverageExcludeGlobs, | |
| 419 | 421 | coverageIncludeGlobs, | |
| 420 | 422 | destinations, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1025,6 +1025,13 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { | |||
| 1025 | 1025 | &EnvironmentOptions::coverage_include_pattern, | |
| 1026 | 1026 | kAllowedInEnvvar, | |
| 1027 | 1027 | OptionNamespaces::kTestRunnerNamespace); | |
| 1028 | + AddOption("--test-coverage-include-all", | ||
| 1029 | + "include source files that were never loaded in the coverage " | ||
| 1030 | + "report", | ||
| 1031 | + &EnvironmentOptions::coverage_include_all, | ||
| 1032 | + kAllowedInEnvvar, | ||
| 1033 | + false, | ||
| 1034 | + OptionNamespaces::kTestRunnerNamespace); | ||
| 1028 | 1035 | AddOption("--test-coverage-exclude", | |
| 1029 | 1036 | "exclude files from coverage report that match this glob pattern", | |
| 1030 | 1037 | &EnvironmentOptions::coverage_exclude_pattern, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -221,6 +221,7 @@ class EnvironmentOptions : public Options { | |||
| 221 | 221 | std::vector<std::string> test_skip_pattern; | |
| 222 | 222 | std::vector<std::string> experimental_test_tag_filter; | |
| 223 | 223 | std::vector<std::string> coverage_include_pattern; | |
| 224 | + bool coverage_include_all = false; | ||
| 224 | 225 | std::vector<std::string> coverage_exclude_pattern; | |
| 225 | 226 | bool throw_deprecation = false; | |
| 226 | 227 | bool trace_deprecation = false; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,5 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + module.exports = function covered() { | ||
| 4 | + return 'covered'; | ||
| 5 | + }; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + { | ||
| 2 | + "not": "a source file" | ||
| 3 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments