From bde6e003110d37f75576dc7c9dadffcf10c66676 Mon Sep 17 00:00:00 2001 From: Eric Wollesen Date: Mon, 6 May 2024 10:48:13 -0600 Subject: [PATCH] ignore hidden files 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. --- ginkgo/watch/package_hash.go | 9 +++++++++ integration/watch_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) 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() {