mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-02-11 04:12:48 +08:00
[patch] show system Node.js version in nvm ls
Normalize `nvm_version` output when `nvm_ls` returns "system vX" so alias and .nvmrc resolutions treat system correctly. Add fast tests for system alias behavior in `nvm ls`, `nvm use`, and `nvm which`.
This commit is contained in:
committed by
Jordan Harband
parent
b1dd81097f
commit
29a652f90f
38
test/fast/Running 'nvm use' should respect alias pointing to system
Executable file
38
test/fast/Running 'nvm use' should respect alias pointing to system
Executable file
@@ -0,0 +1,38 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -ex
|
||||
|
||||
die () { echo "$@" ; cleanup ; exit 1; }
|
||||
cleanup () {
|
||||
rm -f "$(nvm_alias_path)/default"
|
||||
if [ -n "${SYSTEM_DIR-}" ]; then
|
||||
rm -rf "${SYSTEM_DIR}"
|
||||
fi
|
||||
if [ -n "${ORIG_PATH-}" ]; then
|
||||
PATH="${ORIG_PATH}"
|
||||
fi
|
||||
unset -f nvm_print_npm_version
|
||||
}
|
||||
|
||||
\. ../../nvm.sh
|
||||
|
||||
nvm_make_alias default system
|
||||
|
||||
ORIG_PATH="${PATH}"
|
||||
SYSTEM_VERSION="v0.0.0"
|
||||
SYSTEM_DIR="$(mktemp -d)"
|
||||
cat > "${SYSTEM_DIR}/node" <<EOF
|
||||
#!/bin/sh
|
||||
command printf '%s\n' "${SYSTEM_VERSION}"
|
||||
EOF
|
||||
chmod +x "${SYSTEM_DIR}/node"
|
||||
PATH="${SYSTEM_DIR}:${PATH}"
|
||||
nvm_print_npm_version() { command printf ' (npm v1.2.3)'; }
|
||||
|
||||
EXPECTED_OUTPUT="Now using system version of node: ${SYSTEM_VERSION}$(nvm_print_npm_version)"
|
||||
set +ex # since stderr is needed
|
||||
OUTPUT="$(nvm use default 2>&1)"
|
||||
set -ex
|
||||
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "Could not use system via alias. Got >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<"
|
||||
|
||||
cleanup
|
||||
Reference in New Issue
Block a user