also looking at this
Make watch mode rerun affected tests
#28
5 files
+621
-105
| @@ -0,0 +1,45 @@ | ||
| 1 | # Watch mode | |
| 2 | ||
| 3 | Watch mode runs the full discovered suite once, then polls Zig source and test | |
| 4 | files after the configured debounce interval. Start it with a test directory: | |
| 5 | ||
| 6 | ```bash | |
| 7 | zig-test --test-dir tests --watch | |
| 8 | ``` | |
| 9 | ||
| 10 | Type `r` and press Enter at any time to request an explicit full-suite rerun. | |
| 11 | Ctrl-C stops the watcher and any UI server cleanly. | |
| 12 | ||
| 13 | ## Affected-test selection | |
| 14 | ||
| 15 | Each rerun prints both the selected test and the reason it was selected: | |
| 16 | ||
| 17 | ```text | |
| 18 | Watch selection: | |
| 19 | - math.test.zig (imports changed source: src/math.zig) | |
| 20 | ``` | |
| 21 | ||
| 22 | The selection rules are conservative: | |
| 23 | ||
| 24 | - A modified or newly added test file runs by itself. Multiple changed tests | |
| 25 | are batched by the debounce interval and run together. | |
| 26 | - For a source change, the watcher follows relative `.zig` imports from every | |
| 27 | discovered test, including transitive imports, and runs tests whose import | |
| 28 | graph contains the changed file. | |
| 29 | - Named module imports such as `` cannot be resolved from | |
| 30 | source text alone. If any test has unresolved imports, or a changed source | |
| 31 | file maps to no test, the watcher safely runs the full suite. | |
| 32 | - Deleting a test, or renaming one (observed as a delete plus an add), runs the | |
| 33 | full suite so reporters and the live UI receive the new test topology. | |
| 34 | - Deleting or renaming an imported source file also falls back to the full | |
| 35 | suite when its dependency graph can no longer be resolved. | |
| 36 | ||
| 37 | The watcher scans the project root for `.zig` changes while using `--test-dir`, | |
| 38 | `--pattern`, and recursive-discovery settings to decide which files are tests. | |
| 39 | It excludes Git metadata, Zig caches/output, `node_modules`, and `.codex`. | |
| 40 | ||
| 41 | ## Debouncing | |
| 42 | ||
| 43 | `--watch-debounce <ms>` controls the polling and batching interval. The default | |
| 44 | is 300 milliseconds. A test run is never interrupted: edits made while tests | |
| 45 | are running are detected on the next poll and cause another affected run. | |