also looking at this
Make watch mode rerun affected tests
#28
5 files
+621
-105
Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.
| @@ -882,6 +882,17 @@ The async, snapshot, progress, and timeout examples are compile-checked rather | ||
| 882 | 882 | than executed by this step because they intentionally demonstrate delays, |
| 883 | 883 | generated files, interactive output, or failure handling. |
| 884 | 884 | |
| 885 | ## Watch Mode | |
| 886 | ||
| 887 | ```bash | |
| 888 | zig-test --test-dir tests --watch | |
| 889 | ``` | |
| 890 | ||
| 891 | After the initial full run, watch mode reruns changed tests or tests affected by | |
| 892 | relative Zig imports. It falls back to the full suite when dependency data is | |
| 893 | incomplete. Type `r` and press Enter to force a full rerun. See | |
| 894 | [docs/watch-mode.md](docs/watch-mode.md) for selection and debounce behavior. | |
| 895 | ||
| 885 | 896 | ## Requirements |
| 886 | 897 | |
| 887 | 898 | - The exact Zig development build recorded in [`.zig-version`](.zig-version) |
| @@ -905,6 +916,7 @@ Comprehensive guides and API documentation: | ||
| 905 | 916 | - **[Mocking & Spying](docs/mocks.md)** - Complete Jest-compatible mocking API with 20+ methods |
| 906 | 917 | - **[Snapshot Testing](docs/snapshots.md)** - Multiple formats, named snapshots, and diff visualization |
| 907 | 918 | - **[Date & Time Mocking](docs/dates-and-times.md)** - Control time with `setSystemTime()` and Jest-compatible APIs |
| 919 | - **[Watch Mode](docs/watch-mode.md)** - Affected-test selection, safe fallbacks, and full reruns | |
| 908 | 920 | |
| 909 | 921 | ### Additional Resources |
| 910 | 922 | |
| @@ -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. | |