| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 78743b1 commit ea9a675
18 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2267,6 +2267,9 @@ This option may be specified multiple times to exclude multiple glob patterns. | |||
| 2267 | 2267 | If both `--test-coverage-exclude` and `--test-coverage-include` are provided, | |
| 2268 | 2268 | files must meet **both** criteria to be included in the coverage report. | |
| 2269 | 2269 | ||
| 2270 | + By default all the matching test files are excluded from the coverage report. | ||
| 2271 | + Specifying this option will override the default behavior. | ||
| 2272 | + | ||
| 2270 | 2273 | ### `--test-coverage-functions=threshold` | |
| 2271 | 2274 | ||
| 2272 | 2275 | <!-- YAML | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -476,8 +476,10 @@ all tests have completed. If the [`NODE_V8_COVERAGE`][] environment variable is | |||
| 476 | 476 | used to specify a code coverage directory, the generated V8 coverage files are | |
| 477 | 477 | written to that directory. Node.js core modules and files within | |
| 478 | 478 | `node_modules/` directories are, by default, not included in the coverage report. | |
| 479 | - However, they can be explicitly included via the [`--test-coverage-include`][] flag. If | ||
| 480 | - coverage is enabled, the coverage report is sent to any [test reporters][] via | ||
| 479 | + However, they can be explicitly included via the [`--test-coverage-include`][] flag. | ||
| 480 | + By default all the matching test files are excluded from the coverage report. | ||
| 481 | + Exclusions can be overridden by using the [`--test-coverage-exclude`][] flag. | ||
| 482 | + If coverage is enabled, the coverage report is sent to any [test reporters][] via | ||
| 481 | 483 | the `'test:coverage'` event. | |
| 482 | 484 | ||
| 483 | 485 | Coverage can be disabled on a series of lines using the following | |
@@ -3592,6 +3594,7 @@ Can be used to abort test subtasks when the test has been aborted. | |||
| 3592 | 3594 | [`--experimental-test-module-mocks`]: cli.md#--experimental-test-module-mocks | |
| 3593 | 3595 | [`--import`]: cli.md#--importmodule | |
| 3594 | 3596 | [`--test-concurrency`]: cli.md#--test-concurrency | |
| 3597 | + [`--test-coverage-exclude`]: cli.md#--test-coverage-exclude | ||
| 3595 | 3598 | [`--test-coverage-include`]: cli.md#--test-coverage-include | |
| 3596 | 3599 | [`--test-name-pattern`]: cli.md#--test-name-pattern | |
| 3597 | 3600 | [`--test-only`]: cli.md#--test-only | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -650,7 +650,30 @@ class Glob { | |||
| 650 | 650 | } | |
| 651 | 651 | } | |
| 652 | 652 | ||
| 653 | + /** | ||
| 654 | + * Check if a path matches a glob pattern | ||
| 655 | + * @param {string} path the path to check | ||
| 656 | + * @param {string} pattern the glob pattern to match | ||
| 657 | + * @param {boolean} windows whether the path is on a Windows system, defaults to `isWindows` | ||
| 658 | + * @returns {boolean} | ||
| 659 | + */ | ||
| 660 | + function matchGlobPattern(path, pattern, windows = isWindows) { | ||
| 661 | + validateString(path, 'path'); | ||
| 662 | + validateString(pattern, 'pattern'); | ||
| 663 | + return lazyMinimatch().minimatch(path, pattern, { | ||
| 664 | + kEmptyObject, | ||
| 665 | + nocase: isMacOS || isWindows, | ||
| 666 | + windowsPathsNoEscape: true, | ||
| 667 | + nonegate: true, | ||
| 668 | + nocomment: true, | ||
| 669 | + optimizationLevel: 2, | ||
| 670 | + platform: windows ? 'win32' : 'posix', | ||
| 671 | + nocaseMagicOnly: true, | ||
| 672 | + }); | ||
| 673 | + } | ||
| 674 | + | ||
| 653 | 675 | module.exports = { | |
| 654 | 676 | __proto__: null, | |
| 655 | 677 | Glob, | |
| 678 | + matchGlobPattern, | ||
| 656 | 679 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,7 +27,7 @@ const { | |||
| 27 | 27 | } = require('fs'); | |
| 28 | 28 | const { setupCoverageHooks } = require('internal/util'); | |
| 29 | 29 | const { tmpdir } = require('os'); | |
| 30 | - const { join, resolve, relative, matchesGlob } = require('path'); | ||
| 30 | + const { join, resolve, relative } = require('path'); | ||
| 31 | 31 | const { fileURLToPath } = require('internal/url'); | |
| 32 | 32 | const { kMappings, SourceMap } = require('internal/source_map/source_map'); | |
| 33 | 33 | const { | |
@@ -36,6 +36,8 @@ const { | |||
| 36 | 36 | ERR_SOURCE_MAP_MISSING_SOURCE, | |
| 37 | 37 | }, | |
| 38 | 38 | } = require('internal/errors'); | |
| 39 | + const { matchGlobPattern } = require('internal/fs/glob'); | ||
| 40 | + | ||
| 39 | 41 | const kCoverageFileRegex = /^coverage-(\d+)-(\d{13})-(\d+)\.json$/; | |
| 40 | 42 | const kIgnoreRegex = /\/\* node:coverage ignore next (?<count>\d+ )?\*\//; | |
| 41 | 43 | const kLineEndingRegex = /\r?\n$/u; | |
@@ -464,19 +466,24 @@ class TestCoverage { | |||
| 464 | 466 | coverageExcludeGlobs: excludeGlobs, | |
| 465 | 467 | coverageIncludeGlobs: includeGlobs, | |
| 466 | 468 | } = this.options; | |
| 469 | + | ||
| 467 | 470 | // This check filters out files that match the exclude globs. | |
| 468 | 471 | if (excludeGlobs?.length > 0) { | |
| 469 | 472 | for (let i = 0; i < excludeGlobs.length; ++i) { | |
| 470 | - if (matchesGlob(relativePath, excludeGlobs[i]) || | ||
| 471 | - matchesGlob(absolutePath, excludeGlobs[i])) return true; | ||
| 473 | + if ( | ||
| 474 | + matchGlobPattern(relativePath, excludeGlobs[i]) || | ||
| 475 | + matchGlobPattern(absolutePath, excludeGlobs[i]) | ||
| 476 | + ) return true; | ||
| 472 | 477 | } | |
| 473 | 478 | } | |
| 474 | 479 | ||
| 475 | 480 | // This check filters out files that do not match the include globs. | |
| 476 | 481 | if (includeGlobs?.length > 0) { | |
| 477 | 482 | for (let i = 0; i < includeGlobs.length; ++i) { | |
| 478 | - if (matchesGlob(relativePath, includeGlobs[i]) || | ||
| 479 | - matchesGlob(absolutePath, includeGlobs[i])) return false; | ||
| 483 | + if ( | ||
| 484 | + matchGlobPattern(relativePath, includeGlobs[i]) || | ||
| 485 | + matchGlobPattern(absolutePath, includeGlobs[i]) | ||
| 486 | + ) return false; | ||
| 480 | 487 | } | |
| 481 | 488 | return true; | |
| 482 | 489 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -287,6 +287,11 @@ function parseCommandLine() { | |||
| 287 | 287 | ||
| 288 | 288 | if (coverage) { | |
| 289 | 289 | coverageExcludeGlobs = getOptionValue('--test-coverage-exclude'); | |
| 290 | + if (!coverageExcludeGlobs || coverageExcludeGlobs.length === 0) { | ||
| 291 | + // TODO(pmarchini): this default should follow something similar to c8 defaults | ||
| 292 | + // Default exclusions should be also exported to be used by other tools / users | ||
| 293 | + coverageExcludeGlobs = [kDefaultPattern]; | ||
| 294 | + } | ||
| 290 | 295 | coverageIncludeGlobs = getOptionValue('--test-coverage-include'); | |
| 291 | 296 | ||
| 292 | 297 | branchCoverage = getOptionValue('--test-coverage-branches'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -52,13 +52,12 @@ const { | |||
| 52 | 52 | } = require('internal/validators'); | |
| 53 | 53 | ||
| 54 | 54 | const { | |
| 55 | - getLazy, | ||
| 56 | 55 | emitExperimentalWarning, | |
| 57 | 56 | isWindows, | |
| 58 | - isMacOS, | ||
| 57 | + getLazy, | ||
| 59 | 58 | } = require('internal/util'); | |
| 60 | 59 | ||
| 61 | - const lazyMinimatch = getLazy(() => require('internal/deps/minimatch/index')); | ||
| 60 | + const lazyMatchGlobPattern = getLazy(() => require('internal/fs/glob').matchGlobPattern); | ||
| 62 | 61 | ||
| 63 | 62 | function isPathSeparator(code) { | |
| 64 | 63 | return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH; | |
@@ -164,22 +163,6 @@ function _format(sep, pathObject) { | |||
| 164 | 163 | return dir === pathObject.root ? `${dir}${base}` : `${dir}${sep}${base}`; | |
| 165 | 164 | } | |
| 166 | 165 | ||
| 167 | - function glob(path, pattern, windows) { | ||
| 168 | - emitExperimentalWarning('glob'); | ||
| 169 | - validateString(path, 'path'); | ||
| 170 | - validateString(pattern, 'pattern'); | ||
| 171 | - return lazyMinimatch().minimatch(path, pattern, { | ||
| 172 | - __proto__: null, | ||
| 173 | - nocase: isMacOS || isWindows, | ||
| 174 | - windowsPathsNoEscape: true, | ||
| 175 | - nonegate: true, | ||
| 176 | - nocomment: true, | ||
| 177 | - optimizationLevel: 2, | ||
| 178 | - platform: windows ? 'win32' : 'posix', | ||
| 179 | - nocaseMagicOnly: true, | ||
| 180 | - }); | ||
| 181 | - } | ||
| 182 | - | ||
| 183 | 166 | const win32 = { | |
| 184 | 167 | /** | |
| 185 | 168 | * path.resolve([from ...], to) | |
@@ -1140,7 +1123,8 @@ const win32 = { | |||
| 1140 | 1123 | }, | |
| 1141 | 1124 | ||
| 1142 | 1125 | matchesGlob(path, pattern) { | |
| 1143 | - return glob(path, pattern, true); | ||
| 1126 | + emitExperimentalWarning('glob'); | ||
| 1127 | + return lazyMatchGlobPattern()(path, pattern, true); | ||
| 1144 | 1128 | }, | |
| 1145 | 1129 | ||
| 1146 | 1130 | sep: '\\', | |
@@ -1616,7 +1600,8 @@ const posix = { | |||
| 1616 | 1600 | }, | |
| 1617 | 1601 | ||
| 1618 | 1602 | matchesGlob(path, pattern) { | |
| 1619 | - return glob(path, pattern, false); | ||
| 1603 | + emitExperimentalWarning('glob'); | ||
| 1604 | + return lazyMatchGlobPattern()(path, pattern, false); | ||
| 1620 | 1605 | }, | |
| 1621 | 1606 | ||
| 1622 | 1607 | sep: '/', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,7 @@ | |||
| 1 | + const test = require('node:test'); | ||
| 2 | + const assert = require('node:assert'); | ||
| 3 | + const { foo } = require('./logic-file'); | ||
| 4 | + | ||
| 5 | + test('foo returns 1', () => { | ||
| 6 | + assert.strictEqual(foo(), 1); | ||
| 7 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,7 @@ | |||
| 1 | + import test from 'node:test'; | ||
| 2 | + import assert from 'node:assert'; | ||
| 3 | + import { foo } from './logic-file.js'; | ||
| 4 | + | ||
| 5 | + test('foo returns 1', () => { | ||
| 6 | + assert.strictEqual(foo(), 1); | ||
| 7 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,7 @@ | |||
| 1 | + import test from 'node:test'; | ||
| 2 | + import assert from 'node:assert'; | ||
| 3 | + import { foo } from './logic-file.js'; | ||
| 4 | + | ||
| 5 | + test('foo returns 1', () => { | ||
| 6 | + assert.strictEqual(foo(), 1); | ||
| 7 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,9 @@ | |||
| 1 | + function foo() { | ||
| 2 | + return 1; | ||
| 3 | + } | ||
| 4 | + | ||
| 5 | + function bar() { | ||
| 6 | + return 'bar'; | ||
| 7 | + } | ||
| 8 | + | ||
| 9 | + module.exports = { foo, bar }; | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments