|
1 | 1 | 'use strict'; |
2 | 2 | const { |
| 3 | + Array, |
| 4 | + ArrayPrototypeJoin, |
3 | 5 | ArrayPrototypePush, |
4 | 6 | ArrayPrototypePushApply, |
5 | 7 | ArrayPrototypeReduce, |
@@ -362,8 +364,37 @@ class Test extends AsyncResource { |
362 | 364 | } |
363 | 365 |
|
364 | 366 | matchesTestNamePatterns() { |
365 | | - return ArrayPrototypeSome(testNamePatterns, (re) => RegExpPrototypeExec(re, this.name) !== null) || |
366 | | - this.parent?.matchesTestNamePatterns(); |
| 367 | + const matchesByNameOrParent = ArrayPrototypeSome(testNamePatterns, (re) => |
| 368 | + RegExpPrototypeExec(re, this.name) !== null || |
| 369 | + this.parent?.matchesTestNamePatterns(), |
| 370 | + ); |
| 371 | + |
| 372 | + if (matchesByNameOrParent) return true; |
| 373 | + |
| 374 | + const testNameWithAncestors = this.getTestNameWithAncestors(); |
| 375 | + if (!testNameWithAncestors) return false; |
| 376 | + |
| 377 | + return ArrayPrototypeSome(testNamePatterns, (re) => RegExpPrototypeExec(re, testNameWithAncestors) !== null); |
| 378 | + } |
| 379 | + |
| 380 | + /** |
| 381 | + * Returns a name of the test prefixed by name of all its ancestors in ascending order, separated by a space |
| 382 | + * Ex."grandparent parent test" |
| 383 | + * |
| 384 | + * It's needed to match a single test with non-unique name by pattern |
| 385 | + */ |
| 386 | + getTestNameWithAncestors() { |
| 387 | + if (!this.nesting) return; |
| 388 | + |
| 389 | + const ancestorNames = Array(this.nesting); |
| 390 | + let parent = this.parent; |
| 391 | + |
| 392 | + for (let i = 0; i < this.nesting; i++) { |
| 393 | + ancestorNames[this.nesting - i - 1] = parent.name; |
| 394 | + parent = parent.parent; |
| 395 | + } |
| 396 | + |
| 397 | + return `${ArrayPrototypeJoin(ancestorNames, ' ')} ${this.name}`; |
367 | 398 | } |
368 | 399 |
|
369 | 400 | hasConcurrency() { |
|
0 commit comments