node-reinstall icon indicating copy to clipboard operation
node-reinstall copied to clipboard

Add BATS regression test setup

Open absalonCRC opened this issue 6 months ago • 1 comments

Fixes #49.

This adds a BATS-based test setup for node-reinstall with CI wiring:

  • make test runs bash -n plus the BATS suite
  • .travis.yml installs bats-core and runs the test target, matching the original request
  • GitHub Actions runs the same suite on Ubuntu and macOS for current hosted CI coverage
  • Tests cover safe CLI exits plus --force reinstall flows through temporary stubs for sudo, rm, npm, curl, nvm, and nave

The BATS coverage also caught two small portability issues in the existing script:

  • grep -E "\d" does not portably match digits, so the nvm release regex now uses [0-9]
  • global module capture now runs basename once per path and drops only exact lib/npm entries

Local verification:

git clone --depth 1 https://github.com/bats-core/bats-core.git /tmp/bats-core-node-reinstall
PATH="/tmp/bats-core-node-reinstall/bin:$PATH" make test

Result: 8 tests passing.

For the issue bounty, PayPal payout can go to [email protected].

absalonCRC avatar May 24 '26 11:05 absalonCRC

Follow-up pushed: added a regression for --nvm-latest so it uses the master installer path without querying the latest release API, plus the matching one-line fix. Local validation now passes with PATH="/tmp/bats-core-node-reinstall/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Library/Frameworks/Python.framework/Versions/3.10/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/opt/pmk/env/global/bin:/Library/Apple/usr/bin:/Users/cultofrozen/.local/bin:/Users/cultofrozen/.codex/tmp/arg0/codex-arg0bpxqP6:/Users/cultofrozen/.opencode/bin:/Users/cultofrozen/.bun/bin:/Users/cultofrozen/.claude-view/bin:/Applications/Codex.app/Contents/Resources" make test (9 BATS tests).

absalonCRC avatar May 24 '26 11:05 absalonCRC