Skip to content

Commit

Permalink
[Fix] nvm exec: Do a version check on nvm-exec
Browse files Browse the repository at this point in the history
This check would display a message in case the `.nvmrc` version is not installed, and would not alter the output otherwise.
  • Loading branch information
userwiths authored and ljharb committed Mar 6, 2024
1 parent 24deac7 commit 50480e4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions nvm-exec
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ unset NVM_CD_FLAGS
# shellcheck disable=SC1090,SC1091
\. "$DIR/nvm.sh" --no-use

nvm_rc_version > /dev/null && nvm_ensure_version_installed "$NVM_RC_VERSION";
if [ -n "$NODE_VERSION" ]; then
nvm use "$NODE_VERSION" > /dev/null || exit 127
elif ! nvm use >/dev/null 2>&1; then
Expand Down
18 changes: 18 additions & 0 deletions test/fast/Running 'nvm-exec' should display required node version
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

set -x
\. ../../nvm.sh

NVM_TEST_VERSION=v0.42

# Write it to nvmrc
echo "$NVM_TEST_VERSION" > .nvmrc

OUTPUT="$(../../nvm-exec 2>&1)";
EXPECTED="N/A: version \`${NVM_TEST_VERSION}\` is not yet installed.
You need to run \`nvm install ${NVM_TEST_VERSION}\` to install and use it.
No NODE_VERSION provided; no .nvmrc file found";

# Skip install, we want to test the error message
diff <(echo "${EXPECTED}") <(echo "${OUTPUT}")

0 comments on commit 50480e4

Please sign in to comment.