Skip to content

Commit

Permalink
ignore hidden files
Browse files Browse the repository at this point in the history
Hidden files are defined here as those beginning with '.' or '_'.

This is a departure from previous behavior, where hidden source and test files
were evaluated via watch. Evaluating hidden files is undesirable because some
editors create hidden temporary files, and these files shouldn't trigger test
runs.

No flag is added to restore the original behavior at this time as the new
behavior is the same as "go test", and it is not expected that it will cause
problems. If this change affects you, consider opening a PR to add a CLI flag
to restore the previous behavior.
  • Loading branch information
ewollesen authored and onsi committed May 7, 2024
1 parent 7836496 commit bde6e00
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ginkgo/watch/package_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"regexp"
"strings"
"time"
)

Expand Down Expand Up @@ -79,6 +80,10 @@ func (p *PackageHash) computeHashes() (codeHash string, codeModifiedTime time.Ti
continue
}

if isHiddenFile(info) {
continue
}

if goTestRegExp.MatchString(info.Name()) {
testHash += p.hashForFileInfo(info)
if info.ModTime().After(testModifiedTime) {
Expand All @@ -103,6 +108,10 @@ func (p *PackageHash) computeHashes() (codeHash string, codeModifiedTime time.Ti
return
}

func isHiddenFile(info os.FileInfo) bool {
return strings.HasPrefix(info.Name(), ".") || strings.HasPrefix(info.Name(), "_")
}

func (p *PackageHash) hashForFileInfo(info os.FileInfo) string {
return fmt.Sprintf("%s_%d_%d", info.Name(), info.Size(), info.ModTime().UnixNano())
}
25 changes: 25 additions & 0 deletions integration/watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ var _ = Describe("Watch", Label("SLOW"), func() {
fm.MountFixture("watch", "C")
})

createFile := func(path string, contents []byte) {
time.Sleep(time.Second)
err := os.WriteFile(path, contents, 0666)
Ω(err).ShouldNot(HaveOccurred())
}

createHiddenTest := func(pkgToModify string) {
path := filepath.Join(pkgToModify, ".#"+pkgToModify+"_test.go")
fm.MkEmpty(filepath.Join("watch", pkgToModify))
createFile(fm.PathTo("watch", path), []byte("//"))
}

modifyFile := func(path string) {
time.Sleep(time.Second)
content, err := os.ReadFile(path)
Expand Down Expand Up @@ -185,6 +197,19 @@ var _ = Describe("Watch", Label("SLOW"), func() {
Eventually(session).Should(gbytes.Say("C Suite"))
Consistently(session).ShouldNot(gbytes.Say("A Suite|B Suite"))
})

Context("when a hidden test file is created", func() {
It("shouldn't trigger the test suite", func() {
session = startGinkgo(fm.PathTo("watch"), "watch", "-r")
Eventually(session).Should(gbytes.Say("Identified 3 test suites"))
Eventually(session).Should(gbytes.Say(`A \[`))
Eventually(session).Should(gbytes.Say(`B \[`))
Eventually(session).Should(gbytes.Say(`C \[`))

createHiddenTest("A")
Consistently(session).ShouldNot(gbytes.Say("Detected changes in"))
})
})
})

Describe("adjusting the watch regular expression", func() {
Expand Down

0 comments on commit bde6e00

Please sign in to comment.