Skip to content

Commit

Permalink
fix: issue with marking non child tests as skipped
Browse files Browse the repository at this point in the history
  • Loading branch information
gkampitakis committed Apr 10, 2022
1 parent 0fbca5a commit 04d0d00
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
5 changes: 4 additions & 1 deletion snaps/skip.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ func testSkipped(testID, runOnly string) bool {
return true
}

// testID form: Test.*/runName - 1
testName := strings.Split(testID, " - ")[0]

for _, name := range skippedTests.values {
if strings.HasPrefix(testID, name) {
if testName == name || strings.HasPrefix(testName, name+"/") {
return true
}
}
Expand Down
22 changes: 22 additions & 0 deletions snaps/skip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,28 @@ func TestSkip(t *testing.T) {
},
)

t.Run("should not mark tests skipped if not not a child", func(t *testing.T) {
t.Cleanup(func() {
skippedTests = newSyncSlice()
})

runOnly := ""
mockT := MockTestingT{
mockSkipNow: func() {},
mockHelper: func() {},
mockName: func() string {
return "Test"
},
}
// This is for populating skippedTests.values and following the normal flow
SkipNow(mockT)

Equal(t, true, testSkipped("Test", runOnly))
Equal(t, true, testSkipped("Test/chid", runOnly))
Equal(t, false, testSkipped("TestMock", runOnly))
Equal(t, false, testSkipped("TestMock/child", runOnly))
})

t.Run("should use regex match for runOnly", func(t *testing.T) {
Equal(t, false, testSkipped("MyTest - 1", "Test"))
Equal(t, true, testSkipped("MyTest - 1", "^Test"))
Expand Down

0 comments on commit 04d0d00

Please sign in to comment.