Skip to content

feat: add watch mode subcommand#596

Open
SauronBot wants to merge 4 commits intoTypedDevs:mainfrom
SauronBot:feat/watch-mode
Open

feat: add watch mode subcommand#596
SauronBot wants to merge 4 commits intoTypedDevs:mainfrom
SauronBot:feat/watch-mode

Conversation

@SauronBot
Copy link

Summary

Adds bashunit watch [path] [options] — a new subcommand that watches .sh files for changes and automatically re-runs tests on save, enabling a fast TDD feedback loop without manual re-runs.

This was a frequently missing feature compared to test runners in other ecosystems (Jest --watch, PHPUnit with file watchers, etc.).

How it works

  1. Runs tests immediately on start
  2. Watches the given path for .sh file changes
  3. On change detected, re-runs the full test suite
  4. Loops until interrupted with Ctrl-C

Implementation

  • src/watch.sh — core watch loop, supports both inotifywait (Linux) and fswatch (macOS)
  • src/main.shcmd_watch() subcommand handler, forwards extra args to bashunit test
  • bashunit — sources watch.sh, registers watch in subcommand detection and router
  • src/console_header.sh — help text for watch --help, listed in main --help

Usage

bashunit watch                       # watch current directory
bashunit watch tests/                # watch specific path
bashunit watch tests/ --filter user  # watch and filter by test name
bashunit watch tests/ --simple       # minimal output

Requirements

Platform Tool Install
Linux inotifywait sudo apt install inotify-tools
macOS fswatch brew install fswatch

When neither tool is present, a clear error message with install instructions is shown.

Testing

All 603 existing unit tests pass with no changes (bashunit tests/unit/ --simple).

Manual testing:

  • Verified bashunit watch --help output
  • Verified bashunit --help lists the new command
  • Verified immediate test run on start
  • Verified re-run triggers on .sh file save (Linux with inotifywait)
  • Verified clean Ctrl-C exit

Adds `bashunit watch [path] [options]` — a new subcommand that watches
.sh files for changes and automatically re-runs tests, enabling a fast
TDD feedback loop without manual re-runs.

Implementation:
- src/watch.sh: core watch loop using inotifywait (Linux) or fswatch (macOS)
- src/main.sh: cmd_watch() subcommand handler
- bashunit: source watch.sh, register 'watch' in subcommand detection and router
- src/console_header.sh: help text for 'watch', added to main help listing

Features:
- Runs tests immediately on start, then watches for changes
- Supports inotifywait (Linux/inotify-tools) and fswatch (macOS)
- Forwards all standard 'bashunit test' options (--filter, --simple, etc.)
- Clear error message with install instructions when watcher tool is missing
- Watches only .sh files to avoid spurious re-runs

Usage:
  bashunit watch                      # watch current directory
  bashunit watch tests/               # watch specific path
  bashunit watch tests/ --filter user # watch + filter
  bashunit watch tests/ --simple      # watch with simple output
Tests cover:
- bashunit::watch::is_available: inotifywait, fswatch, and no-tool cases
- bashunit::watch::run: error exit, error message content, install hints
- bashunit::watch::wait_for_change: correct tool dispatch for linux/macos/unknown

Uses mocks and spies to avoid requiring inotifywait or fswatch on CI.
@Chemaclass Chemaclass added the enhancement New feature or request label Mar 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants