mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-09-10 08:39:07 +00:00
[New] nvm install
: add --latest-npm
option to automatically try to upgrade to the latest working version of npm
.
- also add `nvm install-latest-npm` top-level command
This commit is contained in:
58
test/fast/Unit tests/nvm_install_latest_npm
Executable file
58
test/fast/Unit tests/nvm_install_latest_npm
Executable file
@@ -0,0 +1,58 @@
|
||||
#!/bin/sh
|
||||
|
||||
\. ../../common.sh
|
||||
|
||||
die () { echo "$@" ; exit 1; }
|
||||
|
||||
\. ../../../nvm.sh
|
||||
|
||||
nvm deactivate >/dev/null 2>&1
|
||||
|
||||
CURRENT="$(nvm current)"
|
||||
[ "$CURRENT" = 'none' ] || [ "$CURRENT" = 'system' ] || die "nvm should be using none or system; got $CURRENT"
|
||||
|
||||
nvm_ls_current() {
|
||||
echo 'none'
|
||||
}
|
||||
node() {
|
||||
return 1
|
||||
}
|
||||
npm() {
|
||||
echo '1.2.3'
|
||||
}
|
||||
|
||||
OUTPUT="$(nvm_install_latest_npm 2>&1 >/dev/null)"
|
||||
EXIT_CODE="$(nvm_install_latest_npm >/dev/null 2>&1 ; echo $?)"
|
||||
|
||||
EXPECTED="Unable to obtain node version."
|
||||
[ "${OUTPUT}" = "${EXPECTED}" ] || die "When node is unavailable, expected >${EXPECTED}<; got >${OUTPUT}"
|
||||
|
||||
node() {
|
||||
echo 'v4.5.6'
|
||||
}
|
||||
nvm_ls_current() {
|
||||
node --version
|
||||
}
|
||||
npm() {
|
||||
return 1
|
||||
}
|
||||
OUTPUT="$(nvm_install_latest_npm 2>&1 >/dev/null)"
|
||||
EXIT_CODE="$(nvm_install_latest_npm >/dev/null 2>&1 ; echo $?)"
|
||||
|
||||
EXPECTED="Unable to obtain npm version."
|
||||
[ "${OUTPUT}" = "${EXPECTED}" ] || die "When node is available and npm is unavailable, expected >${EXPECTED}<; got >${OUTPUT}"
|
||||
|
||||
node() {
|
||||
echo 'v4.5.6'
|
||||
}
|
||||
nvm_ls_current() {
|
||||
echo 'system'
|
||||
}
|
||||
npm() {
|
||||
return 1
|
||||
}
|
||||
OUTPUT="$(nvm_install_latest_npm 2>&1 >/dev/null)"
|
||||
EXIT_CODE="$(nvm_install_latest_npm >/dev/null 2>&1 ; echo $?)"
|
||||
|
||||
EXPECTED="Unable to obtain npm version."
|
||||
[ "${OUTPUT}" = "${EXPECTED}" ] || die "When node is system and npm is unavailable, expected >${EXPECTED}<; got >${OUTPUT}"
|
34
test/installation_node/install latest npm
Executable file
34
test/installation_node/install latest npm
Executable file
@@ -0,0 +1,34 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -ex
|
||||
|
||||
die () { echo "$@" ; exit 1; }
|
||||
|
||||
set +e # todo: fix
|
||||
\. ../../nvm.sh
|
||||
set -e
|
||||
|
||||
nvm deactivate >/dev/null 2>&1 || die 'unable to deactivate: 1'
|
||||
nvm install 4 >/dev/null 2>&1 || die 'install v4 failed'
|
||||
nvm install-latest-npm || die 'nvm install-latest-npm failed: 1'
|
||||
NPM_VERSION="$(npm --version)"
|
||||
nvm_version_greater_than_or_equal_to "${NPM_VERSION}" 5.0.0 || die "node v4.x updates to ${NPM_VERSION}; expected >= v5"
|
||||
|
||||
nvm deactivate >/dev/null 2>&1 || die 'unable to deactivate: 2'
|
||||
nvm install 1 >/dev/null 2>&1 || die 'install v1 failed'
|
||||
nvm install-latest-npm || die 'nvm install-latest-npm failed: 2'
|
||||
NPM_VERSION="$(npm --version)"
|
||||
[ "${NPM_VERSION}" = '4.6.1' ] || die "io.js v1.x updates to ${NPM_VERSION}; expected v4.6.1"
|
||||
|
||||
nvm deactivate >/dev/null 2>&1 || die 'unable to deactivate: 3'
|
||||
nvm install 0.8.27 >/dev/null 2>&1 || die 'install v0.8 failed'
|
||||
nvm install-latest-npm || die 'nvm install-latest-npm failed: 3'
|
||||
NPM_VERSION="$(npm --version)"
|
||||
[ "${NPM_VERSION}" = '4.5.0' ] || die "node 0.8.27 updates to ${NPM_VERSION}; expected v4.5.0"
|
||||
|
||||
nvm deactivate >/dev/null 2>&1 || die 'unable to deactivate: 4'
|
||||
nvm install 0.6.21 >/dev/null 2>&1 || die 'install v0.6 failed'
|
||||
export NPM_CONFIG_STRICT_SSL=false # npm 1 on travis can't handle SSL to npm
|
||||
nvm install-latest-npm || die 'nvm install-latest-npm failed: 4'
|
||||
NPM_VERSION="$(npm --version)"
|
||||
[ "${NPM_VERSION}" = '1.3.26' ] || die "node 0.6.21 updates to ${NPM_VERSION}; expected v1.3.26"
|
12
test/installation_node/install with --latest-npm
Executable file
12
test/installation_node/install with --latest-npm
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -ex
|
||||
|
||||
die () { echo "$@" ; exit 1; }
|
||||
|
||||
set +e # todo: fix
|
||||
\. ../../nvm.sh
|
||||
set -e
|
||||
|
||||
NVM_DEBUG=1 nvm install --latest-npm 4.2.2 \
|
||||
| grep 'Attempting to upgrade to the latest working version of npm...' || die 'did not call through to nvm_install_latest_npm'
|
Reference in New Issue
Block a user