| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -246,16 +246,11 @@ class Test extends AsyncResource { | |||
| 246 | 246 | this.timeout = timeout; | |
| 247 | 247 | } | |
| 248 | 248 | ||
| 249 | - if (testNamePatterns !== null) { | ||
| 250 | - // eslint-disable-next-line no-use-before-define | ||
| 251 | - const match = this instanceof TestHook || ArrayPrototypeSome( | ||
| 252 | - testNamePatterns, | ||
| 253 | - (re) => RegExpPrototypeExec(re, name) !== null, | ||
| 254 | - ); | ||
| 249 | + this.name = name; | ||
| 250 | + this.parent = parent; | ||
| 255 | 251 | ||
| 256 | - if (!match) { | ||
| 257 | - skip = 'test name does not match pattern'; | ||
| 258 | - } | ||
| 252 | + if (testNamePatterns !== null && !this.matchesTestNamePatterns()) { | ||
| 253 | + skip = 'test name does not match pattern'; | ||
| 259 | 254 | } | |
| 260 | 255 | ||
| 261 | 256 | if (testOnlyFlag && !this.only) { | |
@@ -276,8 +271,6 @@ class Test extends AsyncResource { | |||
| 276 | 271 | this.fn = fn; | |
| 277 | 272 | this.harness = null; // Configured on the root test by the test harness. | |
| 278 | 273 | this.mock = null; | |
| 279 | - this.name = name; | ||
| 280 | - this.parent = parent; | ||
| 281 | 274 | this.cancelled = false; | |
| 282 | 275 | this.skipped = !!skip; | |
| 283 | 276 | this.isTodo = !!todo; | |
@@ -302,6 +295,11 @@ class Test extends AsyncResource { | |||
| 302 | 295 | } | |
| 303 | 296 | } | |
| 304 | 297 | ||
| 298 | + matchesTestNamePatterns() { | ||
| 299 | + return ArrayPrototypeSome(testNamePatterns, (re) => RegExpPrototypeExec(re, this.name) !== null) || | ||
| 300 | + this.parent?.matchesTestNamePatterns(); | ||
| 301 | + } | ||
| 302 | + | ||
| 305 | 303 | hasConcurrency() { | |
| 306 | 304 | return this.concurrency > this.activeSubtests; | |
| 307 | 305 | } | |
@@ -754,6 +752,9 @@ class TestHook extends Test { | |||
| 754 | 752 | getRunArgs() { | |
| 755 | 753 | return this.#args; | |
| 756 | 754 | } | |
| 755 | + matchesTestNamePatterns() { | ||
| 756 | + return true; | ||
| 757 | + } | ||
| 757 | 758 | postRun() { | |
| 758 | 759 | } | |
| 759 | 760 | } | |
@@ -763,6 +764,10 @@ class Suite extends Test { | |||
| 763 | 764 | constructor(options) { | |
| 764 | 765 | super(options); | |
| 765 | 766 | ||
| 767 | + if (testNamePatterns !== null && !options.skip && !options.todo) { | ||
| 768 | + this.fn = options.fn || this.fn; | ||
| 769 | + this.skipped = false; | ||
| 770 | + } | ||
| 766 | 771 | this.runOnlySubtests = testOnlyFlag; | |
| 767 | 772 | ||
| 768 | 773 | try { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,4 @@ | |||
| 1 | - // Flags: --no-warnings --test-name-pattern=enabled --test-name-pattern=/pattern/i | ||
| 1 | + // Flags: --no-warnings --test-name-pattern=enabled --test-name-pattern=yes --test-name-pattern=/pattern/i | ||
| 2 | 2 | 'use strict'; | |
| 3 | 3 | const common = require('../../../common'); | |
| 4 | 4 | const { | |
@@ -18,7 +18,7 @@ it('top level it enabled', common.mustCall()); | |||
| 18 | 18 | it('top level it disabled', common.mustNotCall()); | |
| 19 | 19 | it.skip('top level skipped it disabled', common.mustNotCall()); | |
| 20 | 20 | it.skip('top level skipped it enabled', common.mustNotCall()); | |
| 21 | - describe('top level describe disabled', common.mustNotCall()); | ||
| 21 | + describe('top level describe never disabled', common.mustCall()); | ||
| 22 | 22 | describe.skip('top level skipped describe disabled', common.mustNotCall()); | |
| 23 | 23 | describe.skip('top level skipped describe enabled', common.mustNotCall()); | |
| 24 | 24 | test('top level runs because name includes PaTtErN', common.mustCall()); | |
@@ -38,10 +38,30 @@ describe('top level describe enabled', () => { | |||
| 38 | 38 | afterEach(common.mustCall(3)); | |
| 39 | 39 | after(common.mustCall()); | |
| 40 | 40 | ||
| 41 | - it('nested it disabled', common.mustNotCall()); | ||
| 41 | + it('nested it not disabled', common.mustCall()); | ||
| 42 | 42 | it('nested it enabled', common.mustCall()); | |
| 43 | - describe('nested describe disabled', common.mustNotCall()); | ||
| 43 | + describe('nested describe not disabled', common.mustCall()); | ||
| 44 | 44 | describe('nested describe enabled', common.mustCall(() => { | |
| 45 | 45 | it('is enabled', common.mustCall()); | |
| 46 | 46 | })); | |
| 47 | 47 | }); | |
| 48 | + | ||
| 49 | + describe('yes', function() { | ||
| 50 | + it('no', () => {}); | ||
| 51 | + it('yes', () => {}); | ||
| 52 | + | ||
| 53 | + describe('maybe', function() { | ||
| 54 | + it('no', () => {}); | ||
| 55 | + it('yes', () => {}); | ||
| 56 | + }); | ||
| 57 | + }); | ||
| 58 | + | ||
| 59 | + describe('no', function() { | ||
| 60 | + it('no', () => {}); | ||
| 61 | + it('yes', () => {}); | ||
| 62 | + | ||
| 63 | + describe('maybe', function() { | ||
| 64 | + it('no', () => {}); | ||
| 65 | + it('yes', () => {}); | ||
| 66 | + }); | ||
| 67 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,8 +34,8 @@ ok 7 - top level skipped it enabled # SKIP | |||
| 34 | 34 | --- | |
| 35 | 35 | duration_ms: * | |
| 36 | 36 | ... | |
| 37 | - # Subtest: top level describe disabled | ||
| 38 | - ok 8 - top level describe disabled # SKIP test name does not match pattern | ||
| 37 | + # Subtest: top level describe never disabled | ||
| 38 | + ok 8 - top level describe never disabled | ||
| 39 | 39 | --- | |
| 40 | 40 | duration_ms: * | |
| 41 | 41 | type: 'suite' | |
@@ -69,8 +69,8 @@ ok 12 - top level test enabled | |||
| 69 | 69 | duration_ms: * | |
| 70 | 70 | ... | |
| 71 | 71 | # Subtest: top level describe enabled | |
| 72 | - # Subtest: nested it disabled | ||
| 73 | - ok 1 - nested it disabled # SKIP test name does not match pattern | ||
| 72 | + # Subtest: nested it not disabled | ||
| 73 | + ok 1 - nested it not disabled | ||
| 74 | 74 | --- | |
| 75 | 75 | duration_ms: * | |
| 76 | 76 | ... | |
@@ -79,8 +79,8 @@ ok 12 - top level test enabled | |||
| 79 | 79 | --- | |
| 80 | 80 | duration_ms: * | |
| 81 | 81 | ... | |
| 82 | - # Subtest: nested describe disabled | ||
| 83 | - ok 3 - nested describe disabled # SKIP test name does not match pattern | ||
| 82 | + # Subtest: nested describe not disabled | ||
| 83 | + ok 3 - nested describe not disabled | ||
| 84 | 84 | --- | |
| 85 | 85 | duration_ms: * | |
| 86 | 86 | type: 'suite' | |
@@ -103,12 +103,80 @@ ok 13 - top level describe enabled | |||
| 103 | 103 | duration_ms: * | |
| 104 | 104 | type: 'suite' | |
| 105 | 105 | ... | |
| 106 | - 1..13 | ||
| 107 | - # tests 13 | ||
| 108 | - # suites 6 | ||
| 109 | - # pass 6 | ||
| 106 | + # Subtest: yes | ||
| 107 | + # Subtest: no | ||
| 108 | + ok 1 - no | ||
| 109 | + --- | ||
| 110 | + duration_ms: * | ||
| 111 | + ... | ||
| 112 | + # Subtest: yes | ||
| 113 | + ok 2 - yes | ||
| 114 | + --- | ||
| 115 | + duration_ms: * | ||
| 116 | + ... | ||
| 117 | + # Subtest: maybe | ||
| 118 | + # Subtest: no | ||
| 119 | + ok 1 - no | ||
| 120 | + --- | ||
| 121 | + duration_ms: * | ||
| 122 | + ... | ||
| 123 | + # Subtest: yes | ||
| 124 | + ok 2 - yes | ||
| 125 | + --- | ||
| 126 | + duration_ms: * | ||
| 127 | + ... | ||
| 128 | + 1..2 | ||
| 129 | + ok 3 - maybe | ||
| 130 | + --- | ||
| 131 | + duration_ms: * | ||
| 132 | + type: 'suite' | ||
| 133 | + ... | ||
| 134 | + 1..3 | ||
| 135 | + ok 14 - yes | ||
| 136 | + --- | ||
| 137 | + duration_ms: * | ||
| 138 | + type: 'suite' | ||
| 139 | + ... | ||
| 140 | + # Subtest: no | ||
| 141 | + # Subtest: no | ||
| 142 | + ok 1 - no # SKIP test name does not match pattern | ||
| 143 | + --- | ||
| 144 | + duration_ms: * | ||
| 145 | + ... | ||
| 146 | + # Subtest: yes | ||
| 147 | + ok 2 - yes | ||
| 148 | + --- | ||
| 149 | + duration_ms: * | ||
| 150 | + ... | ||
| 151 | + # Subtest: maybe | ||
| 152 | + # Subtest: no | ||
| 153 | + ok 1 - no # SKIP test name does not match pattern | ||
| 154 | + --- | ||
| 155 | + duration_ms: * | ||
| 156 | + ... | ||
| 157 | + # Subtest: yes | ||
| 158 | + ok 2 - yes | ||
| 159 | + --- | ||
| 160 | + duration_ms: * | ||
| 161 | + ... | ||
| 162 | + 1..2 | ||
| 163 | + ok 3 - maybe | ||
| 164 | + --- | ||
| 165 | + duration_ms: * | ||
| 166 | + type: 'suite' | ||
| 167 | + ... | ||
| 168 | + 1..3 | ||
| 169 | + ok 15 - no | ||
| 170 | + --- | ||
| 171 | + duration_ms: * | ||
| 172 | + type: 'suite' | ||
| 173 | + ... | ||
| 174 | + 1..15 | ||
| 175 | + # tests 21 | ||
| 176 | + # suites 10 | ||
| 177 | + # pass 13 | ||
| 110 | 178 | # fail 0 | |
| 111 | 179 | # cancelled 0 | |
| 112 | - # skipped 7 | ||
| 180 | + # skipped 8 | ||
| 113 | 181 | # todo 0 | |
| 114 | 182 | # duration_ms * | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,7 @@ const { test } = require('node:test'); | |||
| 5 | 5 | ||
| 6 | 6 | test('enabled and only', { only: true }, common.mustCall(async (t) => { | |
| 7 | 7 | await t.test('enabled', common.mustCall()); | |
| 8 | - await t.test('disabled', common.mustNotCall()); | ||
| 8 | + await t.test('disabled but parent not', common.mustCall()); | ||
| 9 | 9 | })); | |
| 10 | 10 | ||
| 11 | 11 | test('enabled but not only', common.mustNotCall()); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,8 +5,8 @@ TAP version 13 | |||
| 5 | 5 | --- | |
| 6 | 6 | duration_ms: * | |
| 7 | 7 | ... | |
| 8 | - # Subtest: disabled | ||
| 9 | - ok 2 - disabled # SKIP test name does not match pattern | ||
| 8 | + # Subtest: disabled but parent not | ||
| 9 | + ok 2 - disabled but parent not | ||
| 10 | 10 | --- | |
| 11 | 11 | duration_ms: * | |
| 12 | 12 | ... | |
@@ -33,9 +33,9 @@ ok 4 - not only and does not match pattern # SKIP 'only' option not set | |||
| 33 | 33 | 1..4 | |
| 34 | 34 | # tests 6 | |
| 35 | 35 | # suites 0 | |
| 36 | - # pass 2 | ||
| 36 | + # pass 3 | ||
| 37 | 37 | # fail 0 | |
| 38 | 38 | # cancelled 0 | |
| 39 | - # skipped 4 | ||
| 39 | + # skipped 3 | ||
| 40 | 40 | # todo 0 | |
| 41 | 41 | # duration_ms * | |
| Back | FazBrowse Home | New Git URL |
0 commit comments