mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-09-10 08:39:07 +00:00
Create nvm_print_npm_version
and use that when printing the npm
version.
This commit is contained in:
@@ -5,9 +5,13 @@ die () { echo $@ ; exit 1; }
|
||||
. ../../nvm.sh
|
||||
|
||||
nvm_has_system_node() { return 0; }
|
||||
[ "$(nvm use system 2>&1 | tail -n1)" = "Now using system version of node: $(node -v) (npm v$(npm -v))" ] || die "Could not use system version of node"
|
||||
nvm_print_npm_version() { return ' (npm v1.2.3)'; }
|
||||
EXPECTED_OUTPUT="Now using system version of node: $(node -v)$(nvm_print_npm_version)"
|
||||
[ "$(nvm use system 2>&1 | tail -n1)" = "$EXPECTED_OUTPUT" ] || die "Could not use system version of node"
|
||||
|
||||
nvm_has_system_node() { return 1; }
|
||||
[ "$(nvm use system 2>&1 | tail -n1)" = "System version of node not found." ] || die "Did not report error, system node not found"
|
||||
nvm_print_npm_version() { return ''; }
|
||||
EXPECTED_OUTPUT="System version of node not found."
|
||||
[ "$(nvm use system 2>&1 | tail -n1)" = "$EXPECTED_OUTPUT" ] || die "Did not report error, system node not found"
|
||||
nvm use system 2>&1 > /dev/null || [ $? -eq 127 ] || die "Did not return error code, system node not found"
|
||||
|
||||
|
28
test/fast/Unit tests/nvm_print_npm_version
Executable file
28
test/fast/Unit tests/nvm_print_npm_version
Executable file
@@ -0,0 +1,28 @@
|
||||
#!/bin/sh
|
||||
|
||||
cleanup () {
|
||||
alias nvm_has='\nvm_has'
|
||||
alias npm='\npm'
|
||||
unset -f nvm_has npm
|
||||
}
|
||||
die () { echo $@ ; exit 1; }
|
||||
|
||||
. ../../../nvm.sh
|
||||
|
||||
nvm_has() { return 1; }
|
||||
OUTPUT="$(nvm_print_npm_version)"
|
||||
[ -z "$OUTPUT" ] || die "nvm_print_npm_version did not return empty when nvm_has returns 1, got '$OUTPUT'"
|
||||
|
||||
nvm_has() { return 0; }
|
||||
npm() {
|
||||
if [ "_$@" = "_--version" ]; then
|
||||
echo "1.2.3"
|
||||
else
|
||||
echo "error"
|
||||
fi
|
||||
}
|
||||
OUTPUT="$(nvm_print_npm_version)"
|
||||
EXPECTED_OUTPUT=" (npm v1.2.3)"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_print_npm_version did not provided '$EXPECTED_OUTPUT', got '$OUTPUT'"
|
||||
|
||||
cleanup
|
Reference in New Issue
Block a user