| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 27493a1 commit 29de7f8
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -233,7 +233,8 @@ If Node.js is started with the [`--test-only`][] command-line option, it is | |||
| 233 | 233 | possible to skip all top level tests except for a selected subset by passing | |
| 234 | 234 | the `only` option to the tests that should be run. When a test with the `only` | |
| 235 | 235 | option set is run, all subtests are also run. The test context's `runOnly()` | |
| 236 | - method can be used to implement the same behavior at the subtest level. | ||
| 236 | + method can be used to implement the same behavior at the subtest level. Tests | ||
| 237 | + that are not executed are omitted from the test runner output. | ||
| 237 | 238 | ||
| 238 | 239 | ```js | |
| 239 | 240 | // Assume Node.js is run with the --test-only command-line option. | |
@@ -270,7 +271,7 @@ whose name matches the provided pattern. Test name patterns are interpreted as | |||
| 270 | 271 | JavaScript regular expressions. The `--test-name-pattern` option can be | |
| 271 | 272 | specified multiple times in order to run nested tests. For each test that is | |
| 272 | 273 | executed, any corresponding test hooks, such as `beforeEach()`, are also | |
| 273 | - run. | ||
| 274 | + run. Tests that are not executed are omitted from the test runner output. | ||
| 274 | 275 | ||
| 275 | 276 | Given the following test file, starting Node.js with the | |
| 276 | 277 | `--test-name-pattern="test [1-3]"` option would cause the test runner to execute | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -86,6 +86,7 @@ const { | |||
| 86 | 86 | } = parseCommandLine(); | |
| 87 | 87 | let kResistStopPropagation; | |
| 88 | 88 | let findSourceMap; | |
| 89 | + let noopTestStream; | ||
| 89 | 90 | ||
| 90 | 91 | function lazyFindSourceMap(file) { | |
| 91 | 92 | if (findSourceMap === undefined) { | |
@@ -252,13 +253,20 @@ class Test extends AsyncResource { | |||
| 252 | 253 | parent = null; | |
| 253 | 254 | } | |
| 254 | 255 | ||
| 256 | + this.name = name; | ||
| 257 | + this.parent = parent; | ||
| 258 | + this.testNumber = 0; | ||
| 259 | + this.outputSubtestCount = 0; | ||
| 260 | + this.filteredSubtestCount = 0; | ||
| 261 | + this.filtered = false; | ||
| 262 | + | ||
| 255 | 263 | if (parent === null) { | |
| 256 | 264 | this.concurrency = 1; | |
| 257 | 265 | this.nesting = 0; | |
| 258 | 266 | this.only = testOnlyFlag; | |
| 259 | 267 | this.reporter = new TestsStream(); | |
| 260 | 268 | this.runOnlySubtests = this.only; | |
| 261 | - this.testNumber = 0; | ||
| 269 | + this.childNumber = 0; | ||
| 262 | 270 | this.timeout = kDefaultTimeout; | |
| 263 | 271 | this.root = this; | |
| 264 | 272 | this.hooks = { | |
@@ -277,7 +285,7 @@ class Test extends AsyncResource { | |||
| 277 | 285 | this.only = only ?? !parent.runOnlySubtests; | |
| 278 | 286 | this.reporter = parent.reporter; | |
| 279 | 287 | this.runOnlySubtests = !this.only; | |
| 280 | - this.testNumber = parent.subtests.length + 1; | ||
| 288 | + this.childNumber = parent.subtests.length + 1; | ||
| 281 | 289 | this.timeout = parent.timeout; | |
| 282 | 290 | this.root = parent.root; | |
| 283 | 291 | this.hooks = { | |
@@ -287,6 +295,13 @@ class Test extends AsyncResource { | |||
| 287 | 295 | beforeEach: ArrayPrototypeSlice(parent.hooks.beforeEach), | |
| 288 | 296 | afterEach: ArrayPrototypeSlice(parent.hooks.afterEach), | |
| 289 | 297 | }; | |
| 298 | + | ||
| 299 | + if ((testNamePatterns !== null && !this.matchesTestNamePatterns()) || | ||
| 300 | + (testOnlyFlag && !this.only)) { | ||
| 301 | + skip = true; | ||
| 302 | + this.filtered = true; | ||
| 303 | + this.parent.filteredSubtestCount++; | ||
| 304 | + } | ||
| 290 | 305 | } | |
| 291 | 306 | ||
| 292 | 307 | switch (typeof concurrency) { | |
@@ -314,17 +329,6 @@ class Test extends AsyncResource { | |||
| 314 | 329 | this.timeout = timeout; | |
| 315 | 330 | } | |
| 316 | 331 | ||
| 317 | - this.name = name; | ||
| 318 | - this.parent = parent; | ||
| 319 | - | ||
| 320 | - if (testNamePatterns !== null && !this.matchesTestNamePatterns()) { | ||
| 321 | - skip = 'test name does not match pattern'; | ||
| 322 | - } | ||
| 323 | - | ||
| 324 | - if (testOnlyFlag && !this.only) { | ||
| 325 | - skip = '\'only\' option not set'; | ||
| 326 | - } | ||
| 327 | - | ||
| 328 | 332 | if (skip) { | |
| 329 | 333 | fn = noop; | |
| 330 | 334 | } | |
@@ -435,14 +439,14 @@ class Test extends AsyncResource { | |||
| 435 | 439 | while (this.pendingSubtests.length > 0 && this.hasConcurrency()) { | |
| 436 | 440 | const deferred = ArrayPrototypeShift(this.pendingSubtests); | |
| 437 | 441 | const test = deferred.test; | |
| 438 | - this.reporter.dequeue(test.nesting, test.loc, test.name); | ||
| 442 | + test.reporter.dequeue(test.nesting, test.loc, test.name); | ||
| 439 | 443 | await test.run(); | |
| 440 | 444 | deferred.resolve(); | |
| 441 | 445 | } | |
| 442 | 446 | } | |
| 443 | 447 | ||
| 444 | 448 | addReadySubtest(subtest) { | |
| 445 | - this.readySubtests.set(subtest.testNumber, subtest); | ||
| 449 | + this.readySubtests.set(subtest.childNumber, subtest); | ||
| 446 | 450 | } | |
| 447 | 451 | ||
| 448 | 452 | processReadySubtestRange(canSend) { | |
@@ -503,7 +507,7 @@ class Test extends AsyncResource { | |||
| 503 | 507 | const test = new Factory({ __proto__: null, fn, name, parent, ...options, ...overrides }); | |
| 504 | 508 | ||
| 505 | 509 | if (parent.waitingOn === 0) { | |
| 506 | - parent.waitingOn = test.testNumber; | ||
| 510 | + parent.waitingOn = test.childNumber; | ||
| 507 | 511 | } | |
| 508 | 512 | ||
| 509 | 513 | if (preventAddingSubtests) { | |
@@ -591,6 +595,14 @@ class Test extends AsyncResource { | |||
| 591 | 595 | } | |
| 592 | 596 | ||
| 593 | 597 | start() { | |
| 598 | + if (this.filtered) { | ||
| 599 | + noopTestStream ??= new TestsStream(); | ||
| 600 | + this.reporter = noopTestStream; | ||
| 601 | + this.run = this.filteredRun; | ||
| 602 | + } else { | ||
| 603 | + this.testNumber = ++this.parent.outputSubtestCount; | ||
| 604 | + } | ||
| 605 | + | ||
| 594 | 606 | // If there is enough available concurrency to run the test now, then do | |
| 595 | 607 | // it. Otherwise, return a Promise to the caller and mark the test as | |
| 596 | 608 | // pending for later execution. | |
@@ -639,6 +651,13 @@ class Test extends AsyncResource { | |||
| 639 | 651 | } | |
| 640 | 652 | } | |
| 641 | 653 | ||
| 654 | + async filteredRun() { | ||
| 655 | + this.pass(); | ||
| 656 | + this.subtests = []; | ||
| 657 | + this.report = noop; | ||
| 658 | + this.postRun(); | ||
| 659 | + } | ||
| 660 | + | ||
| 642 | 661 | async run() { | |
| 643 | 662 | if (this.parent !== null) { | |
| 644 | 663 | this.parent.activeSubtests++; | |
@@ -784,11 +803,14 @@ class Test extends AsyncResource { | |||
| 784 | 803 | this.mock?.reset(); | |
| 785 | 804 | ||
| 786 | 805 | if (this.parent !== null) { | |
| 787 | - const report = this.getReportDetails(); | ||
| 788 | - report.details.passed = this.passed; | ||
| 789 | - this.reporter.complete(this.nesting, this.loc, this.testNumber, this.name, report.details, report.directive); | ||
| 806 | + if (!this.filtered) { | ||
| 807 | + const report = this.getReportDetails(); | ||
| 808 | + report.details.passed = this.passed; | ||
| 809 | + this.testNumber ||= ++this.parent.outputSubtestCount; | ||
| 810 | + this.reporter.complete(this.nesting, this.loc, this.testNumber, this.name, report.details, report.directive); | ||
| 811 | + this.parent.activeSubtests--; | ||
| 812 | + } | ||
| 790 | 813 | ||
| 791 | - this.parent.activeSubtests--; | ||
| 792 | 814 | this.parent.addReadySubtest(this); | |
| 793 | 815 | this.parent.processReadySubtestRange(false); | |
| 794 | 816 | this.parent.processPendingSubtests(); | |
@@ -846,7 +868,7 @@ class Test extends AsyncResource { | |||
| 846 | 868 | isClearToSend() { | |
| 847 | 869 | return this.parent === null || | |
| 848 | 870 | ( | |
| 849 | - this.parent.waitingOn === this.testNumber && this.parent.isClearToSend() | ||
| 871 | + this.parent.waitingOn === this.childNumber && this.parent.isClearToSend() | ||
| 850 | 872 | ); | |
| 851 | 873 | } | |
| 852 | 874 | ||
@@ -893,8 +915,8 @@ class Test extends AsyncResource { | |||
| 893 | 915 | ||
| 894 | 916 | report() { | |
| 895 | 917 | countCompletedTest(this); | |
| 896 | - if (this.subtests.length > 0) { | ||
| 897 | - this.reporter.plan(this.subtests[0].nesting, this.loc, this.subtests.length); | ||
| 918 | + if (this.outputSubtestCount > 0) { | ||
| 919 | + this.reporter.plan(this.subtests[0].nesting, this.loc, this.outputSubtestCount); | ||
| 898 | 920 | } else { | |
| 899 | 921 | this.reportStarted(); | |
| 900 | 922 | } | |
@@ -996,6 +1018,13 @@ class Suite extends Test { | |||
| 996 | 1018 | }), | |
| 997 | 1019 | () => { | |
| 998 | 1020 | this.buildPhaseFinished = true; | |
| 1021 | + | ||
| 1022 | + // A suite can transition from filtered to unfiltered based on the | ||
| 1023 | + // tests that it contains. | ||
| 1024 | + if (this.filtered && this.filteredSubtestCount !== this.subtests.length) { | ||
| 1025 | + this.filtered = false; | ||
| 1026 | + this.parent.filteredSubtestCount--; | ||
| 1027 | + } | ||
| 999 | 1028 | }, | |
| 1000 | 1029 | ); | |
| 1001 | 1030 | } catch (err) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments