| 9 | ) |
| 10 | |
| 11 | func TestWatcher_DetectsChanges(t *testing.T) { |
| 12 | dir := t.TempDir() |
| 13 | |
| 14 | // Create initial file |
| 15 | initial := filepath.Join(dir, "task.md") |
| 16 | os.WriteFile(initial, []byte("# initial"), 0644) |
| 17 | |
| 18 | var count atomic.Int32 |
| 19 | w := New(dir, func() { |
| 20 | count.Add(1) |
| 21 | }, 50*time.Millisecond) |
| 22 | |
| 23 | go func() { |
| 24 | if err := w.Start(); err != nil { |
| 25 | t.Logf("watcher error: %v", err) |
| 26 | } |
| 27 | }() |
| 28 | |
| 29 | // Wait for watcher to initialize |
| 30 | time.Sleep(100 * time.Millisecond) |
| 31 | |
| 32 | // Modify the file |
| 33 | os.WriteFile(initial, []byte("# modified"), 0644) |
| 34 | |
| 35 | // Wait for debounce |
| 36 | time.Sleep(200 * time.Millisecond) |
| 37 | |
| 38 | w.Stop() |
| 39 | |
| 40 | if count.Load() < 1 { |
| 41 | t.Fatal("expected onChange to be called at least once") |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | func TestWatcher_IgnoresNonMarkdown(t *testing.T) { |
| 46 | dir := t.TempDir() |