Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
language: bash

before_install:
- git clone --depth 1 https://github.com/bats-core/bats-core.git /tmp/bats-core
- sudo /tmp/bats-core/install.sh /usr/local

script:
- make test
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,14 @@ readme:
echo "## Commands" >> README.md
echo '' >> README.md
./node-reinstall -h | sed -n -e '/Commands:/,// p' | tail -n +3 >> README.md

test:
@if command -v bats >/dev/null 2>&1; then \
bats test/*.bats; \
elif [ -x test/bats/bin/bats ]; then \
test/bats/bin/bats test/*.bats; \
else \
echo "BATS is required to run the test suite." >&2; \
echo "Install bats-core or clone it to test/bats." >&2; \
exit 127; \
fi
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,13 @@ Whenever you feel like you need to completely re-install Node and NPM, simply ex
node-reinstall --nvm re-install using stable nvm - the default
node-reinstall --nvm-latest re-install using latest nvm - creationix/nvm:master
node-reinstall 5.0.0 specify a default node version

## Testing

The test suite uses [BATS](https://github.com/bats-core/bats-core) for non-destructive smoke tests. Install BATS locally, then run:

```
make test
```

The current tests only exercise safe paths such as help, version, and invalid option handling. They do not run the reinstall flow or delete local files.
30 changes: 30 additions & 0 deletions test/node-reinstall.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bats

setup() {
REPO_ROOT="$(cd "$BATS_TEST_DIRNAME/.." && pwd)"
SCRIPT="$REPO_ROOT/node-reinstall"
}

@test "help flag prints usage without running reinstall steps" {
run "$SCRIPT" --help

[ "$status" -eq 0 ]
[[ "$output" == *"Usage:"* ]]
[[ "$output" == *"--nvm-latest"* ]]
}

@test "version flag prints the script version" {
expected="$(grep '^VERSION=' "$SCRIPT" | sed -E 's/VERSION="([^"]+)"/\1/')"

run "$SCRIPT" --version

[ "$status" -eq 0 ]
[ "$output" = "$expected" ]
}

@test "unknown flags fail before destructive reinstall steps" {
run "$SCRIPT" --does-not-exist

[ "$status" -eq 1 ]
[[ "$output" == *"Unknown option"* ]]
}