diff --git a/ginkgo/watch/package_hash.go b/ginkgo/watch/package_hash.go index 17d052bdc..0e6ae1f29 100644 --- a/ginkgo/watch/package_hash.go +++ b/ginkgo/watch/package_hash.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "regexp" + "strings" "time" ) @@ -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) { @@ -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()) } diff --git a/integration/watch_test.go b/integration/watch_test.go index a1e08ac0f..4d1ab71a8 100644 --- a/integration/watch_test.go +++ b/integration/watch_test.go @@ -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) @@ -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() {