Skip to content

chore(test): discover Bats tests repo-wide, not just test/#132

Open
taminomara wants to merge 1 commit into
testdouble:mainfrom
taminomara:chore/bats-test-discovery
Open

chore(test): discover Bats tests repo-wide, not just test/#132
taminomara wants to merge 1 commit into
testdouble:mainfrom
taminomara:chore/bats-test-discovery

Conversation

@taminomara

Copy link
Copy Markdown
Contributor

What

Change the npm test script so Bats discovers every *.bats file in the repo (outside node_modules) instead of only recursing test/:

find . -name node_modules -prune -o -name '*.bats' -print0 | xargs -0 bats

This lets a script's tests sit next to the script they cover (e.g. scripts/foo.sh covered by scripts/foo.bats), while test/ stays home to harness-level checks like sanity.bats.

Why find, not a Bats flag

Bats has no built-in path or directory exclusion. Its --filter / --negative-filter / --filter-tags flags all match test names/tags, not file paths — and a filtered-out file is still loaded and its file-level code executed anyway. There is no .batsignore and no .gitignore awareness; file discovery is driven purely by the positional path arguments. So shaping the list with find is what keeps node_modules (and any nested node_modules) out. find also still runs not-yet-committed tests, which a git ls-files-based list would skip.

Sequencing

This is the config-only prerequisite. A follow-up MR relocates the existing review-skill-or-agent Bats tests next to their scripts and updates the sanity.bats comment. The CONTRIBUTING example it documents (scripts/detect-git-context.bats) only appears on main once that follow-up lands. Splitting them keeps this discovery change reviewable on its own.

Verification

The new pipeline discovers and runs test/sanity.bats green on this branch. A failing test propagates correctly (xargs exits 123, so CI fails).

🤖 Generated with Claude Code

https://claude.ai/code/session_01VxmMsZfzA4d37Uh1rTfEDG

Change the `npm test` script to find every `*.bats` file outside
node_modules and hand them to Bats, instead of recursing only `test/`.
This lets a script's tests sit next to the script they cover, while
`test/` stays home to harness-level checks.

Bats has no built-in path or directory exclusion (its `--filter` family
matches test names, not files, and there is no `.batsignore`), so a
`find ... -prune | xargs` pipeline shapes the file list. It also prunes
any nested node_modules and still runs not-yet-committed tests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VxmMsZfzA4d37Uh1rTfEDG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant