Compare commits

...

7 Commits

Author SHA1 Message Date
Cheerag Patel
9c9ff4bac0 [meta] Rename .github/ISSUE_TEMPLATE.md to .github/ISSUE_TEMPLATE/ISSUE_TEMPLATE.md
Moved issue template into ISSUE_TEMPLATE folder
2024-10-30 14:03:05 -07:00
Jordan Harband
51ea809d63 [Tests] ensure that unit tests use only mocked LTS names 2024-10-30 23:41:50 -07:00
Jordan Harband
6b70c40f15 [Fix] nvm_install_latest_npm: avoid unbound variable
Fixes #3447
2024-10-22 22:02:01 -07:00
Reetik Rajan
5dc31ac51b [patch] give a more helpful message when lts alias is mistakenly used 2024-10-05 09:21:42 +05:30
Jordan Harband
da2720a429 [Fix] nvm ls, nvm alias, nvm install: error when an LTS name is invalid 2024-09-04 13:55:11 -07:00
Jordan Harband
9fb9dec710 [Fix] nvm_normalize_lts: error when an LTS name is not lowercase
Fixes #3417
2024-09-04 13:54:41 -07:00
Jordan Harband
9a28dbd394 [actions] use node/install instead of node/run 2024-08-28 11:28:52 -07:00
11 changed files with 184 additions and 61 deletions

View File

@@ -58,12 +58,11 @@ jobs:
- run: sudo ${{ matrix.shell }} --version 2> /dev/null || dpkg -s ${{ matrix.shell }} 2> /dev/null || which ${{ matrix.shell }} - run: sudo ${{ matrix.shell }} --version 2> /dev/null || dpkg -s ${{ matrix.shell }} 2> /dev/null || which ${{ matrix.shell }}
- run: curl --version - run: curl --version
- run: wget --version - run: wget --version
- uses: ljharb/actions/node/run@main - uses: ljharb/actions/node/install@main
name: 'npm install && version checks' name: 'npm install && version checks'
with: with:
node-version: 'lts/*' node-version: 'lts/*'
skip-ls-check: true skip-ls-check: true
shell-command: echo installed
- run: npm ls urchin - run: npm ls urchin
- run: npx which urchin - run: npx which urchin
- run: env - run: env

36
nvm.sh
View File

@@ -196,6 +196,9 @@ nvm_install_latest_npm() {
nvm_echo 'Attempting to upgrade to the latest working version of npm...' nvm_echo 'Attempting to upgrade to the latest working version of npm...'
local NODE_VERSION local NODE_VERSION
NODE_VERSION="$(nvm_strip_iojs_prefix "$(nvm_ls_current)")" NODE_VERSION="$(nvm_strip_iojs_prefix "$(nvm_ls_current)")"
local NPM_VERSION
NPM_VERSION="$(npm --version 2>/dev/null)"
if [ "${NODE_VERSION}" = 'system' ]; then if [ "${NODE_VERSION}" = 'system' ]; then
NODE_VERSION="$(node --version)" NODE_VERSION="$(node --version)"
elif [ "${NODE_VERSION}" = 'none' ]; then elif [ "${NODE_VERSION}" = 'none' ]; then
@@ -206,8 +209,6 @@ nvm_install_latest_npm() {
nvm_err 'Unable to obtain node version.' nvm_err 'Unable to obtain node version.'
return 1 return 1
fi fi
local NPM_VERSION
NPM_VERSION="$(npm --version 2>/dev/null)"
if [ -z "${NPM_VERSION}" ]; then if [ -z "${NPM_VERSION}" ]; then
nvm_err 'Unable to obtain npm version.' nvm_err 'Unable to obtain npm version.'
return 2 return 2
@@ -700,10 +701,12 @@ nvm_ensure_version_installed() {
nvm_err "N/A: version \"${PREFIXED_VERSION:-$PROVIDED_VERSION}\" is not yet installed." nvm_err "N/A: version \"${PREFIXED_VERSION:-$PROVIDED_VERSION}\" is not yet installed."
fi fi
nvm_err "" nvm_err ""
if [ "${IS_VERSION_FROM_NVMRC}" != '1' ]; then if [ "${PROVIDED_VERSION}" = 'lts' ]; then
nvm_err "You need to run \`nvm install ${PROVIDED_VERSION}\` to install and use it." nvm_err '`lts` is not an alias - you may need to run `nvm install --lts` to install and `nvm use --lts` to use it.'
else elif [ "${IS_VERSION_FROM_NVMRC}" != '1' ]; then
nvm_err 'You need to run `nvm install` to install and use the node version specified in `.nvmrc`.' nvm_err "You need to run \`nvm install ${PROVIDED_VERSION}\` to install and use it."
else
nvm_err 'You need to run `nvm install` to install and use the node version specified in `.nvmrc`.'
fi fi
return 1 return 1
fi fi
@@ -891,6 +894,10 @@ nvm_normalize_lts() {
fi fi
;; ;;
*) *)
if [ "${LTS}" != "$(echo "${LTS}" | command tr '[:upper:]' '[:lower:]')" ]; then
nvm_err 'LTS names must be lowercase'
return 3
fi
nvm_echo "${LTS}" nvm_echo "${LTS}"
;; ;;
esac esac
@@ -1249,7 +1256,9 @@ nvm_alias() {
nvm_err 'An alias is required.' nvm_err 'An alias is required.'
return 1 return 1
fi fi
ALIAS="$(nvm_normalize_lts "${ALIAS}")" if ! ALIAS="$(nvm_normalize_lts "${ALIAS}")"; then
return $?
fi
if [ -z "${ALIAS}" ]; then if [ -z "${ALIAS}" ]; then
return 2 return 2
@@ -1652,7 +1661,9 @@ $VERSION_LIST
EOF EOF
if [ -n "${LTS-}" ]; then if [ -n "${LTS-}" ]; then
LTS="$(nvm_normalize_lts "lts/${LTS}")" if ! LTS="$(nvm_normalize_lts "lts/${LTS}")"; then
return $?
fi
LTS="${LTS#lts/}" LTS="${LTS#lts/}"
fi fi
@@ -3417,9 +3428,11 @@ nvm() {
;; ;;
esac esac
local EXIT_CODE
VERSION="$(NVM_VERSION_ONLY=true NVM_LTS="${LTS-}" nvm_remote_version "${provided_version}")" VERSION="$(NVM_VERSION_ONLY=true NVM_LTS="${LTS-}" nvm_remote_version "${provided_version}")"
EXIT_CODE="$?"
if [ "${VERSION}" = 'N/A' ]; then if [ "${VERSION}" = 'N/A' ] || [ $EXIT_CODE -ne 0 ]; then
local LTS_MSG local LTS_MSG
local REMOTE_CMD local REMOTE_CMD
if [ "${LTS-}" = '*' ]; then if [ "${LTS-}" = '*' ]; then
@@ -3428,6 +3441,10 @@ nvm() {
elif [ -n "${LTS-}" ]; then elif [ -n "${LTS-}" ]; then
LTS_MSG="(with LTS filter '${LTS}') " LTS_MSG="(with LTS filter '${LTS}') "
REMOTE_CMD="nvm ls-remote --lts=${LTS}" REMOTE_CMD="nvm ls-remote --lts=${LTS}"
if [ -z "${provided_version}" ]; then
nvm_err "Version with LTS filter '${LTS}' not found - try \`${REMOTE_CMD}\` to browse available versions."
return 3
fi
else else
REMOTE_CMD='nvm ls-remote' REMOTE_CMD='nvm ls-remote'
fi fi
@@ -3492,7 +3509,6 @@ nvm() {
FLAVOR="$(nvm_node_prefix)" FLAVOR="$(nvm_node_prefix)"
fi fi
local EXIT_CODE
EXIT_CODE=0 EXIT_CODE=0
if nvm_is_version_installed "${VERSION}"; then if nvm_is_version_installed "${VERSION}"; then

View File

@@ -0,0 +1,35 @@
#!/bin/sh
die () { echo "$@" ; exit 1; }
\. ../../../nvm.sh
REMOTE="${PWD}/mocks/nvm_ls_remote.txt"
REMOTE_IOJS="${PWD}/mocks/nvm_ls_remote_iojs.txt"
nvm_download() {
if [ "$*" = "-L -s $(nvm_get_mirror node std)/index.tab -o -" ]; then
cat "${REMOTE}"
elif [ "$*" = "-L -s $(nvm_get_mirror iojs)/index.tab -o -" ]; then
cat "${REMOTE_IOJS}"
else
nvm_err "unknown nvm_download call: $*"
return 42
fi
}
nvm_install_binary() {
return 42
}
nvm_install_source() {
return 42
}
ACTUAL="$(nvm install lts/ARGON 2>&1)"
EXIT_CODE=$?
[ $EXIT_CODE -eq 3 ] || die "Expected exit code of 3, got ${EXIT_CODE}"
EXPECTED="LTS names must be lowercase
Version with LTS filter 'ARGON' not found - try \`nvm ls-remote --lts=ARGON\` to browse available versions."
[ "${ACTUAL}" = "${EXPECTED}" ] || die "Expected >${EXPECTED}<, got >${ACTUAL}<"

View File

@@ -1,7 +1,5 @@
#!/bin/sh #!/bin/sh
set -e
die () { echo "$@" ; cleanup ; exit 1; } die () { echo "$@" ; cleanup ; exit 1; }
cleanup() { cleanup() {
@@ -10,6 +8,8 @@ cleanup() {
export NVM_COLORS=TEMP_NVM_COLORS export NVM_COLORS=TEMP_NVM_COLORS
fi fi
unset TEMP_NVM_COLORS unset TEMP_NVM_COLORS
rm -rf "${NVM_DIR}/alias/lts"
mv "${NVM_DIR}/alias/lts-backup" "${NVM_DIR}/alias/lts"
} }
\. ../../../nvm.sh \. ../../../nvm.sh
@@ -18,12 +18,24 @@ if [ -n "${NVM_COLORS-}" ]; then
unset NVM_COLORS unset NVM_COLORS
fi fi
MOCKS_DIR="../Unit tests/mocks"
LTS_NAMES_PATH="${MOCKS_DIR}/LTS_names.txt"
STAR="$(cat "${MOCKS_DIR}/lts-star.txt")"
mv "${NVM_DIR}/alias/lts" "${NVM_DIR}/alias/lts-backup" ||:
mkdir -p "${NVM_DIR}/alias/lts"
echo "${STAR}" > "${NVM_DIR}/alias/lts/\*"
printf '%s\n' "$(cat "${LTS_NAMES_PATH}" | tail -n +1)" | while IFS= read -r LTS; do
cp "${NVM_DIR}/alias/lts-backup/${LTS}" "${NVM_DIR}/alias/lts/"
done
nvm deactivate 2>/dev/null || die 'unable to deactivate' nvm deactivate 2>/dev/null || die 'unable to deactivate'
\. ../../common.sh \. ../../common.sh
MOCKS_DIR="${PWD}/mocks"
nvm_download() { nvm_download() {
if [ "$*" = "-L -s $(nvm_get_mirror node std)/index.tab -o -" ]; then if [ "$*" = "-L -s $(nvm_get_mirror node std)/index.tab -o -" ]; then
cat "${MOCKS_DIR}/nodejs.org-dist-index.tab" cat "${MOCKS_DIR}/nodejs.org-dist-index.tab"
@@ -42,8 +54,6 @@ OUTPUT="$(nvm ls-remote "lts/*" | sed 's/[ \t]*$//')"
EXPECTED_OUTPUT="$(cat "${EXPECTED_OUTPUT_PATH}" | sed 's/[ \t]*$//' )" EXPECTED_OUTPUT="$(cat "${EXPECTED_OUTPUT_PATH}" | sed 's/[ \t]*$//' )"
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] || die "nvm ls-remote lts/* did not output expected sorted versions; got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<" [ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] || die "nvm ls-remote lts/* did not output expected sorted versions; got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<"
MOCKS_DIR="${PWD}/mocks"
LTS_NAMES_PATH="${MOCKS_DIR}/LTS_names.txt"
LTS_LIST="$(cat "${LTS_NAMES_PATH}" | tail -n +2)" LTS_LIST="$(cat "${LTS_NAMES_PATH}" | tail -n +2)"
INDEX=1 INDEX=1
@@ -56,6 +66,14 @@ printf '%s\n' "${LTS_LIST}" | while IFS= read -r LTS; do
INDEX=$(($INDEX + 1)) INDEX=$(($INDEX + 1))
done done
OUTPUT="$(nvm ls-remote lts/ARGON 2>&1)"
EXIT_CODE=$?
[ $EXIT_CODE -eq 3 ] || die "nvm ls-remote lts/ARGON did not exit 3, got '${EXIT_CODE}'"
EXPECTED_OUTPUT="LTS names must be lowercase
N/A"
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] || die "nvm ls-remote lts/ARGON did not output expected error message; got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<"
REMOTE="${PWD}/mocks/nvm_ls_remote.txt" REMOTE="${PWD}/mocks/nvm_ls_remote.txt"
nvm_ls_remote() { nvm_ls_remote() {
cat "${REMOTE}" cat "${REMOTE}"

View File

@@ -5,14 +5,26 @@ die () { echo "$@" ; cleanup ; exit 1; }
cleanup() { cleanup() {
unset -f nvm_download unset -f nvm_download
rm -rf "${NVM_DIR}/alias/lts"
mv "${NVM_DIR}/alias/lts-backup" "${NVM_DIR}/alias/lts"
} }
\. ../../../nvm.sh \. ../../../nvm.sh
set -ex
MOCKS_DIR="${PWD}/mocks" MOCKS_DIR="${PWD}/mocks"
LTS_NAMES_PATH="${MOCKS_DIR}/LTS_names.txt"
LTS_LIST="$(cat "${LTS_NAMES_PATH}" | tail -n +2)"
mv "${NVM_DIR}/alias/lts" "${NVM_DIR}/alias/lts-backup" ||:
mkdir -p "${NVM_DIR}/alias/lts"
for LTS in $LTS_LIST; do
cp "${NVM_DIR}/alias/lts-backup/${LTS}" "${NVM_DIR}/alias/lts/"
done
set -ex
# sample output at the time the test was written # sample output at the time the test was written
TAB_PATH="${MOCKS_DIR}/nodejs.org-dist-index.tab" TAB_PATH="${MOCKS_DIR}/nodejs.org-dist-index.tab"
nvm_download() { nvm_download() {
@@ -21,8 +33,6 @@ nvm_download() {
nvm_ls_remote >/dev/null || die "nvm_ls_remote_failed?!" nvm_ls_remote >/dev/null || die "nvm_ls_remote_failed?!"
LTS_NAMES_PATH="${MOCKS_DIR}/LTS_names.txt"
N=0 N=0
while IFS= read -r LTS; do while IFS= read -r LTS; do
if [ $N -gt 0 ]; then if [ $N -gt 0 ]; then

View File

@@ -2,11 +2,11 @@
# Save the PATH as it was when the test started to restore it when it # Save the PATH as it was when the test started to restore it when it
# finishes # finishes
ORIG_PATH=$PATH ORIG_PATH="${PATH}"
cleanup() { cleanup() {
# Restore the PATH as it was when the test started # Restore the PATH as it was when the test started
export PATH=ORIG_PATH export PATH="${ORIG_PATH}"
} }
die () { cleanup; echo "$@" ; exit 1; } die () { cleanup; echo "$@" ; exit 1; }
@@ -15,20 +15,23 @@ die () { cleanup; echo "$@" ; exit 1; }
# Directory where mocked binaries used by nvm_get_arch for each OS/arch are # Directory where mocked binaries used by nvm_get_arch for each OS/arch are
# located # located
MOCKS_DIR=`pwd`/../../mocks MOCKS_DIR="$(pwd)/../../mocks"
# Sets the PATH for these tests to include the symlinks to the mocked # Sets the PATH for these tests to include the symlinks to the mocked
# binaries # binaries
export PATH=.:${PATH} export PATH=".:${PATH}"
# Setups mock binaries for a given OS and arch that mimic # Setups mock binaries for a given OS and arch that mimic
# the output of the real binaries used by nvm_get_arch to guess # the output of the real binaries used by nvm_get_arch to guess
# the architecture of a given system. # the architecture of a given system.
setup_mock_arch() { setup_mock_arch() {
local OS=$1 local OS
local ARCH=$2 OS=$1
local OPT=$3 local ARCH
ARCH=$2
local OPT
OPT=$3
if [ "_$OS" = "_solaris" ] || [ "_$OS" = "_smartos" ]; then if [ "_${OS}" = '_solaris' ] || [ "_${OS}" = '_smartos' ]; then
ln -sf "${MOCKS_DIR}/isainfo_${ARCH}" ./isainfo ln -sf "${MOCKS_DIR}/isainfo_${ARCH}" ./isainfo
if [ "_$OPT" != "_no_pkg_info" ]; then if [ "_$OPT" != "_no_pkg_info" ]; then
ln -sf "${MOCKS_DIR}/pkg_info_${ARCH}" ./pkg_info ln -sf "${MOCKS_DIR}/pkg_info_${ARCH}" ./pkg_info
@@ -42,10 +45,12 @@ setup_mock_arch() {
# Cleans up the setup done by setup_mock_arch. # Cleans up the setup done by setup_mock_arch.
cleanup_mock_arch() { cleanup_mock_arch() {
local OS=$1 local OS
local ARCH=$2 OS=$1
local ARCH
ARCH=$2
if [ "_$OS" = "_solaris" ] || [ "_$OS" = "_smartos" ]; then if [ "_${OS}" = '_solaris' ] || [ "_${OS}" = '_smartos' ]; then
rm -f ./isainfo rm -f ./isainfo
rm -f ./pkg_info rm -f ./pkg_info
fi fi
@@ -57,17 +62,22 @@ cleanup_mock_arch() {
# expected output $EXPECTED_OUTPUT with the actual output. Does nothing # expected output $EXPECTED_OUTPUT with the actual output. Does nothing
# and exits cleanly if they match, dies otherwise. # and exits cleanly if they match, dies otherwise.
run_test() { run_test() {
local ARCH=$1 local ARCH
local OS=$2 ARCH=$1
local EXPECTED_OUTPUT=$3 local OS
local OPT=$4 OS=$2
local EXPECTED_OUTPUT
EXPECTED_OUTPUT=$3
local OPT
OPT=$4
setup_mock_arch $OS $ARCH $OPT setup_mock_arch "${OS}" "${ARCH}" "${OPT}"
local OUTPUT="$(nvm_get_arch)" local OUTPUT
cleanup_mock_arch $OS $ARCH OUTPUT="$(nvm_get_arch)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || cleanup_mock_arch "${OS}" "${ARCH}"
die "nvm_get_arch for OS \"$OS\" and arch \"$ARCH\" with OPT \"$OPT\" did [ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] ||
not return \"$EXPECTED_OUTPUT\"; got \"$OUTPUT\"" die "nvm_get_arch for OS \"${OS}\" and arch \"${ARCH}\" with OPT \"${OPT}\" did
not return \"${EXPECTED_OUTPUT}\"; got \"${OUTPUT}\""
} }
run_test x86 smartos x86 run_test x86 smartos x86

View File

@@ -6,7 +6,7 @@ cleanup () {
nvm cache clear nvm cache clear
nvm deactivate nvm deactivate
rm -rf ${NVM_DIR}/v* rm -rf ${NVM_DIR}/v*
nvm unalias default nvm unalias default || true
} }
die () { >&2 echo "$@" ; cleanup ; exit 1; } die () { >&2 echo "$@" ; cleanup ; exit 1; }

View File

@@ -2,29 +2,44 @@
cleanup() { cleanup() {
unset nvm_get_os unset nvm_get_os
rm -rf "${NVM_DIR}/alias/lts"
mv "${NVM_DIR}/alias/lts-backup" "${NVM_DIR}/alias/lts"
} }
die () { cleanup; echo "$@" ; exit 1; } die () { cleanup; echo "$@" ; exit 1; }
\. ../../../nvm.sh \. ../../../nvm.sh
MOCKS_DIR="../Unit tests/mocks"
LTS_NAMES_PATH="${MOCKS_DIR}/LTS_names.txt"
STAR="$(cat "${MOCKS_DIR}/lts-star.txt")"
mv "${NVM_DIR}/alias/lts" "${NVM_DIR}/alias/lts-backup" ||:
mkdir -p "${NVM_DIR}/alias/lts"
echo "${STAR}" > "${NVM_DIR}/alias/lts/\*"
printf '%s\n' "$(cat "${LTS_NAMES_PATH}" | tail -n +1)" | while IFS= read -r LTS; do
cp "${NVM_DIR}/alias/lts-backup/${LTS}" "${NVM_DIR}/alias/lts/"
done
ACTUAL="$(nvm_normalize_lts "foo")" ACTUAL="$(nvm_normalize_lts "foo")"
EXPECTED='foo' EXPECTED='foo'
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<" [ "${ACTUAL}" = "${EXPECTED}" ] || die "foo: expected >${EXPECTED}<, got >${ACTUAL}<"
ACTUAL="$(nvm_normalize_lts "lts/*")" ACTUAL="$(nvm_normalize_lts "lts/*")"
EXPECTED='lts/*' EXPECTED='lts/*'
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<" [ "${ACTUAL}" = "${EXPECTED}" ] || die "*: expected >${EXPECTED}<, got >${ACTUAL}<"
if ACTUAL="$(nvm_normalize_lts lts/ARGON)"; then
MOCKS_DIR="../Unit tests/mocks" die "ARGON: expected failure, got >${ACTUAL}<"
STAR="$(cat "$MOCKS_DIR/lts-star.txt")" fi
ACTUAL="$(nvm_normalize_lts "${STAR}")" ACTUAL="$(nvm_normalize_lts "${STAR}")"
EXPECTED="${STAR}" EXPECTED="${STAR}"
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<" [ "${ACTUAL}" = "${EXPECTED}" ] || die "${STAR}: expected >${EXPECTED}<, got >${ACTUAL}<"
LTS_NAMES_PATH="${MOCKS_DIR}/LTS_names.txt"
LTS_LIST="$(cat "${LTS_NAMES_PATH}" | tail -n +2)" LTS_LIST="$(cat "${LTS_NAMES_PATH}" | tail -n +2)"
INDEX=1 INDEX=1
@@ -36,3 +51,4 @@ printf '%s\n' "${LTS_LIST}" | while IFS= read -r LTS; do
INDEX=$(($INDEX + 1)) INDEX=$(($INDEX + 1))
done done

View File

@@ -9,20 +9,20 @@ die () { echo "$@" ; exit 1; }
nvm unalias default >/dev/null 2>&1 || die 'unable to unalias default' nvm unalias default >/dev/null 2>&1 || die 'unable to unalias default'
set +ex # needed for stderr set +ex # needed for stderr
OUTPUT="$(nvm install --lts 3 2>&1)" OUTPUT="$(nvm install --lts 0.12 2>&1)"
EXIT_CODE="$?"
set -ex set -ex
EXIT_CODE="$(nvm install --lts 3 >/dev/null 2>&1 && echo $? || echo $?)" EXPECTED_OUTPUT="Version '0.12' (with LTS filter) not found - try \`nvm ls-remote --lts\` to browse available versions."
EXPECTED_OUTPUT="Version '3' (with LTS filter) not found - try \`nvm ls-remote --lts\` to browse available versions." [ "${EXIT_CODE}" = 3 ] || die "\`nvm install --lts 0.12\` did not exit with 3, got >${EXIT_CODE}<"
[ "${EXIT_CODE}" = 3 ] || die "\`nvm install --lts 3\` did not exit with 3, got >${EXIT_CODE}<"
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "\`nvm install --lts 3\` output >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<" [ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "\`nvm install --lts 3\` output >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<"
set +ex # needed for stderr set +ex # needed for stderr
OUTPUT="$(nvm install --lts=argon 3 2>&1)" OUTPUT="$(nvm install --lts=argon 0.12 2>&1)"
set -ex EXIT_CODE="$?"
EXIT_CODE="$(nvm install --lts=argon 3 >/dev/null 2>&1 && echo $? || echo $?)" set -x
EXPECTED_OUTPUT="Version '3' (with LTS filter 'argon') not found - try \`nvm ls-remote --lts=argon\` to browse available versions." EXPECTED_OUTPUT="Version '0.12' (with LTS filter 'argon') not found - try \`nvm ls-remote --lts=argon\` to browse available versions."
[ "${EXIT_CODE}" = 3 ] || die "\`nvm install --lts=argon 3\` did not exit with 3, got >${EXIT_CODE}<" [ "${EXIT_CODE}" = 3 ] || die "\`nvm install --lts=argon 0.12\` did not exit with 3, got >${EXIT_CODE}<"
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "\`nvm install --lts=argon 3\` output >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<" [ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "\`nvm install --lts=argon 0.12\` output >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<"
nvm install --lts 4.2.2 || die 'nvm install --lts 4.2.2 failed' nvm install --lts 4.2.2 || die 'nvm install --lts 4.2.2 failed'

View File

@@ -0,0 +1,19 @@
#!/bin/sh
set -ex
die () { echo "$@" ; exit 1; }
\. ../../../nvm.sh
# Deactivate any active node version
nvm deactivate >/dev/null 2>&1 || die 'deactivate failed'
# Attempt to use 'lts' without '--' and capture the error message
ERROR_OUTPUT=$(nvm use lts 2>&1) || true
EXPECTED_ERROR='`lts` is not an alias - you may need to run `nvm install --lts` to install and `nvm use --lts` to use it.'
# Check if the error message matches the expected output
echo "$ERROR_OUTPUT" | grep -q "$EXPECTED_ERROR" \
|| die "Expected error message not found. Got: $ERROR_OUTPUT"