Skip to content

Commit bca7f06

Browse files
committed
First attempt at supporting matching by suite
- The jest of it is that we have a stricter matching mode, when a test location is passed: ```ts if (testLocations !== undefined && testLocations.length !== 0) { ``` We have three cases to deal with: 1. Parent did match via location filter, and as such this test is marked to run. No Questions asked. 2. This test / suite does match via location filter, and as such mark it to run, and do the same for its children. 3. No match. In this case I'd mark as skipped only it is a test. (if it's a suite, I still want to go through its children)
1 parent 3c18ecf commit bca7f06

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

packages/runner/src/utils/collect.ts

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function interpretTaskModes(
1515
): void {
1616
const matchedLocations: number[] = []
1717

18-
const traverseSuite = (suite: Suite, parentIsOnly?: boolean) => {
18+
const traverseSuite = (suite: Suite, parentIsOnly?: boolean, parentMatchedWithLocation?: boolean) => {
1919
const suiteIsOnly = parentIsOnly || suite.mode === 'only'
2020

2121
suite.tasks.forEach((t) => {
@@ -37,30 +37,38 @@ export function interpretTaskModes(
3737
t.mode = 'run'
3838
}
3939
}
40-
if (t.type === 'test') {
41-
if (namePattern && !getTaskFullName(t).match(namePattern)) {
42-
t.mode = 'skip'
43-
}
4440

45-
// Match test location against provided locations, only run if present
46-
// in `testLocations`. Note: if `includeTaskLocations` is not enabled,
47-
// all test will be skipped.
48-
if (testLocations !== undefined && testLocations.length !== 0) {
49-
if (t.location && testLocations?.includes(t.location.line)) {
50-
t.mode = 'run'
51-
matchedLocations.push(t.location.line)
52-
}
53-
else {
41+
let hasLocationMatch = parentMatchedWithLocation
42+
// Match test location against provided locations, only run if present
43+
// in `testLocations`. Note: if `includeTaskLocations` is not enabled,
44+
// all test will be skipped.
45+
if (testLocations !== undefined && testLocations.length !== 0) {
46+
if (t.location && testLocations?.includes(t.location.line)) {
47+
t.mode = 'run'
48+
matchedLocations.push(t.location.line)
49+
hasLocationMatch = true
50+
}
51+
else if (parentMatchedWithLocation) {
52+
t.mode = 'run'
53+
}
54+
else {
55+
if (t.type === 'test') {
5456
t.mode = 'skip'
5557
}
5658
}
5759
}
60+
61+
if (t.type === 'test') {
62+
if (namePattern && !getTaskFullName(t).match(namePattern)) {
63+
t.mode = 'skip'
64+
}
65+
}
5866
else if (t.type === 'suite') {
5967
if (t.mode === 'skip') {
6068
skipAllTasks(t)
6169
}
6270
else {
63-
traverseSuite(t, includeTask)
71+
traverseSuite(t, includeTask, hasLocationMatch)
6472
}
6573
}
6674
})
@@ -73,7 +81,7 @@ export function interpretTaskModes(
7381
}
7482
}
7583

76-
traverseSuite(file, parentIsOnly)
84+
traverseSuite(file, parentIsOnly, false)
7785

7886
const nonMatching = testLocations?.filter(loc => !matchedLocations.includes(loc))
7987
if (nonMatching && nonMatching.length !== 0) {

0 commit comments

Comments
 (0)