Compare commits

...

2 Commits

Author SHA1 Message Date
Jordan Harband
179d45050b
v0.40.1 2024-08-27 13:44:15 -07:00
Jordan Harband
ff7634577b
[Tests] fix broken tests exposed by 863bd63
Leaves 2 non-executable, + some TODOs
2024-08-27 12:46:40 -07:00
21 changed files with 272 additions and 173 deletions

2
.gitignore vendored
View File

@ -22,3 +22,5 @@ current
npm-shrinkwrap.json
package-lock.json
yarn.lock
target/

View File

@ -6,7 +6,7 @@
</a>
# Node Version Manager [![Build Status](https://app.travis-ci.com/nvm-sh/nvm.svg?branch=master)][3] [![nvm version](https://img.shields.io/badge/version-v0.40.0-yellow.svg)][4] [![CII Best Practices](https://bestpractices.dev/projects/684/badge)](https://bestpractices.dev/projects/684)
# Node Version Manager [![Build Status](https://app.travis-ci.com/nvm-sh/nvm.svg?branch=master)][3] [![nvm version](https://img.shields.io/badge/version-v0.40.1-yellow.svg)][4] [![CII Best Practices](https://bestpractices.dev/projects/684/badge)](https://bestpractices.dev/projects/684)
<!-- To update this table of contents, ensure you have run `npm install` then `npm run doctoc` -->
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
@ -102,10 +102,10 @@ nvm is a version manager for [node.js](https://nodejs.org/en/), designed to be i
To **install** or **update** nvm, you should run the [install script][2]. To do that, you may either download and run the script manually, or use the following cURL or Wget command:
```sh
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
```
```sh
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
```
Running either of the above commands downloads a script and runs it. The script clones the nvm repository to `~/.nvm`, and attempts to add the source lines from the snippet below to the correct profile file (`~/.bash_profile`, `~/.zshrc`, `~/.profile`, or `~/.bashrc`).
@ -127,7 +127,7 @@ Eg: `curl ... | NVM_DIR="path/to/nvm"`. Ensure that the `NVM_DIR` does not conta
- The installer can use `git`, `curl`, or `wget` to download `nvm`, whichever is available.
- You can instruct the installer to not edit your shell config (for example if you already get completions via a [zsh nvm plugin](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/nvm)) by setting `PROFILE=/dev/null` before running the `install.sh` script. Here's an example one-line command to do that: `PROFILE=/dev/null bash -c 'curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash'`
- You can instruct the installer to not edit your shell config (for example if you already get completions via a [zsh nvm plugin](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/nvm)) by setting `PROFILE=/dev/null` before running the `install.sh` script. Here's an example one-line command to do that: `PROFILE=/dev/null bash -c 'curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash'`
#### Troubleshooting on Linux
@ -175,7 +175,7 @@ You can use a task:
```yaml
- name: Install nvm
ansible.builtin.shell: >
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
args:
creates: "{{ ansible_env.HOME }}/.nvm/nvm.sh"
```
@ -237,7 +237,7 @@ If you have `git` installed (requires git v1.7.10+):
1. clone this repo in the root of your user profile
- `cd ~/` from anywhere then `git clone https://github.com/nvm-sh/nvm.git .nvm`
1. `cd ~/.nvm` and check out the latest version with `git checkout v0.40.0`
1. `cd ~/.nvm` and check out the latest version with `git checkout v0.40.1`
1. activate `nvm` by sourcing it from your shell: `. ./nvm.sh`
Now add these lines to your `~/.bashrc`, `~/.profile`, or `~/.zshrc` file to have it automatically sourced upon login:
@ -843,13 +843,13 @@ If installing nvm on Alpine Linux *is* still what you want or need to do, you sh
### Alpine Linux 3.13+
```sh
apk add -U curl bash ca-certificates openssl ncurses coreutils python3 make gcc g++ libgcc linux-headers grep util-linux binutils findutils
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
```
### Alpine Linux 3.5 - 3.12
```sh
apk add -U curl bash ca-certificates openssl ncurses coreutils python2 make gcc g++ libgcc linux-headers grep util-linux binutils findutils
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
```
_Note: Alpine 3.5 can only install NodeJS versions up to v6.9.5, Alpine 3.6 can only install versions up to v6.10.3, Alpine 3.7 installs versions up to v8.9.3, Alpine 3.8 installs versions up to v8.14.0, Alpine 3.9 installs versions up to v10.19.0, Alpine 3.10 installs versions up to v10.24.1, Alpine 3.11 installs versions up to v12.22.6, Alpine 3.12 installs versions up to v12.22.12, Alpine 3.13 & 3.14 install versions up to v14.20.0, Alpine 3.15 & 3.16 install versions up to v16.16.0 (**These are all versions on the main branch**). Alpine 3.5 - 3.12 required the package `python2` to build NodeJS, as they are older versions to build. Alpine 3.13+ requires `python3` to successfully build newer NodeJS versions, but you can use `python2` with Alpine 3.13+ if you need to build versions of node supported in Alpine 3.5 - 3.15, you just need to specify what version of NodeJS you need to install in the package install script._
@ -952,9 +952,9 @@ You have to make sure that the user directory name in `$HOME` and the user direc
To change the user directory and/or account name follow the instructions [here](https://support.apple.com/en-us/HT201548)
[1]: https://github.com/nvm-sh/nvm.git
[2]: https://github.com/nvm-sh/nvm/blob/v0.40.0/install.sh
[2]: https://github.com/nvm-sh/nvm/blob/v0.40.1/install.sh
[3]: https://app.travis-ci.com/nvm-sh/nvm
[4]: https://github.com/nvm-sh/nvm/releases/tag/v0.40.0
[4]: https://github.com/nvm-sh/nvm/releases/tag/v0.40.1
[Urchin]: https://git.sdf.org/tlevine/urchin
[Fish]: https://fishshell.com
@ -1012,7 +1012,7 @@ Here's what you will need to do:
If one of these broken versions is installed on your system, the above step will likely still succeed even if you didn't include the `--shared-zlib` flag.
However, later, when you attempt to `npm install` something using your old version of node.js, you will see `incorrect data check` errors.
If you want to avoid the possible hassle of dealing with this, include that flag.
For more details, see [this issue](https://github.com/nodejs/node/issues/39313) and [this comment](https://github.com/nodejs/node/issues/39313#issuecomment-90.40.076)
For more details, see [this issue](https://github.com/nodejs/node/issues/39313) and [this comment](https://github.com/nodejs/node/issues/39313#issuecomment-90.40.176)
- Exit back to your native shell.
@ -1039,7 +1039,7 @@ Now you should be able to use node as usual.
If you've encountered this error on WSL-2:
```sh
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- 0:00:09 --:--:-- 0curl: (6) Could not resolve host: raw.githubusercontent.com
@ -1074,7 +1074,7 @@ Currently, the sole maintainer is [@ljharb](https://github.com/ljharb) - more ma
## Project Support
Only the latest version (v0.40.0 at this time) is supported.
Only the latest version (v0.40.1 at this time) is supported.
## Enterprise Support

View File

@ -33,7 +33,7 @@ nvm_install_dir() {
}
nvm_latest_version() {
nvm_echo "v0.40.0"
nvm_echo "v0.40.1"
}
nvm_profile_is_bash_or_zsh() {

14
nvm.sh
View File

@ -2199,7 +2199,7 @@ nvm_install_binary_extract() {
command mkdir -p "${VERSION_PATH}" || return 1
if [ "${NVM_OS}" = 'win' ]; then
command mv "${TMPDIR}/"*/* "${VERSION_PATH}" || return 1
command mv "${TMPDIR}/"*/* "${VERSION_PATH}/" || return 1
command chmod +x "${VERSION_PATH}"/node.exe || return 1
command chmod +x "${VERSION_PATH}"/npm || return 1
command chmod +x "${VERSION_PATH}"/npx 2>/dev/null
@ -2278,8 +2278,8 @@ nvm_install_binary() {
# Read nosource from arguments
if [ "${nosource-}" = '1' ]; then
nvm_err 'Binary download failed. Download from source aborted.'
return 0
nvm_err 'Binary download failed. Download from source aborted.'
return 0
fi
nvm_err 'Binary download failed, trying source.'
@ -2922,11 +2922,11 @@ nvm_is_natural_num() {
nvm_write_nvmrc() {
local VERSION_STRING
VERSION_STRING=$(nvm_version "${1-$VERSION_STRING}")
if [ "$VERSION_STRING" = '∞' ] || [ "$VERSION_STRING" = 'N/A' ]; then
VERSION_STRING=$(nvm_version "${1-}")
if [ "${VERSION_STRING}" = '∞' ] || [ "${VERSION_STRING}" = 'N/A' ]; then
return 1
fi
echo "$VERSION_STRING" | tee "$PWD"/.nvmrc > /dev/null || {
echo "${VERSION_STRING}" | tee "$PWD"/.nvmrc > /dev/null || {
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
nvm_err "Warning: Unable to write version number ($VERSION_STRING) to .nvmrc"
fi
@ -4396,7 +4396,7 @@ nvm() {
NVM_VERSION_ONLY=true NVM_LTS="${NVM_LTS-}" nvm_remote_version "${PATTERN:-node}"
;;
"--version" | "-v")
nvm_echo '0.40.0'
nvm_echo '0.40.1'
;;
"unload")
nvm deactivate >/dev/null 2>&1

View File

@ -1,6 +1,6 @@
{
"name": "nvm",
"version": "0.40.0",
"version": "0.40.1",
"description": "Node Version Manager - Simple bash script to manage multiple active node.js versions",
"directories": {
"test": "test"
@ -14,6 +14,8 @@
"test/installation/node": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=installation_node test-$shell",
"test/installation/iojs": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=installation_iojs test-$shell",
"test/sourcing": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=sourcing test-$shell",
"test:check-exec": "(IFS=$'\\n'; for file in $(git ls-files test); do if [ ! -x \"$file\" ] && [[ \"$file\" != *.* ]] && [[ \"$file\" != test/fixtures/* ]]; then echo \"$file\"; fi; done) | tee /dev/stderr | awk 'END {if (NR > 0) exit 1}'",
"test:check-nonexec": "(IFS=$'\\n'; for file in $(git ls-files test); do if [ -x \"$file\" ] && [ ! -d \"$file\" ] && { [[ \"$file\" =~ '\\.(json|txt|sh|js|log)$' ]] || [[ \"$file\" =~ '^test/(mocks|fixtures)/.*' ]]; }; then echo \"$file\"; fi; done) | tee /dev/stderr | awk 'END {if (NR > 0) exit 1}'",
"doctoc": "doctoc --title='## Table of Contents' --github README.md",
"predoctoc:check": "cp README.md v-README.md.orig && npm run doctoc",
"doctoc:check": "diff -q README.md v-README.md.orig",

View File

@ -4,40 +4,58 @@
set -e
TEST_VERSION="v0.2.4"
TEST_VERSION='v0.2.4'
if [ -f .nvmrc ]; then mv .nvmrc .nvmrc.orig; fi
cleanup () {
cleanup() {
nvm cache clear
nvm deactivate
nvm unalias default
rm -rf ${NVM_DIR}/v* .nvmrc
rm -rf "${NVM_DIR}/v0.2.4" .nvmrc
if [ -f .nvmrc.orig ]; then mv .nvmrc.orig .nvmrc; fi
unset -f nvm_ls_remote nvm_ls_remote_iojs
}
die () {
die() {
echo "$@"
cleanup
exit 1
}
REMOTE="$PWD/mocks/nvm_ls_remote.txt"
REMOTE="${PWD}/mocks/nvm_ls_remote.txt"
nvm_ls_remote() {
cat "$REMOTE"
if [ -n "${PATTERN}" ]; then
cat "${REMOTE}" | \grep "${PATTERN}"
else
cat "${REMOTE}"
fi
}
REMOTE_IOJS="$PWD/mocks/nvm_ls_remote_iojs.txt"
nvm_ls_remote_iojs() {
cat "$REMOTE_IOJS"
local PATTERN
PATTERN="${1-}"
if [ -n "${PATTERN}" ]; then
cat "${REMOTE_IOJS}" | \grep "${PATTERN}"
else
cat "${REMOTE_IOJS}"
fi
}
make_fake_node "$TEST_VERSION"
make_fake_node "${TEST_VERSION}"
nvm install --save "$TEST_VERSION" || die "\`nvm install --save $TEST_VERSION\` failed"
nvm install -w "${TEST_VERSION}" || die "\`nvm install -w ${TEST_VERSION}\` failed"
OUTPUT="$(cat .nvmrc)"
nvm_is_valid_version "$(cat .nvmrc)" \
|| die "\`nvm install --save $TEST_VERSION\`+ \`cat .nvmrc\` outputted invalid version: got '${OUTPUT}'"
nvm_is_valid_version "${OUTPUT}" \
|| die "\`nvm install -w ${TEST_VERSION}\`+ \`cat .nvmrc\` outputted invalid version: got '${OUTPUT}'"
rm .nvmrc || die 'removing of .nvmrc failed'
nvm install --save "${TEST_VERSION}" || die "\`nvm install --save ${TEST_VERSION}\` failed"
OUTPUT="$(cat .nvmrc)"
nvm_is_valid_version "${OUTPUT}" \
|| die "\`nvm install --save ${TEST_VERSION}\`+ \`cat .nvmrc\` outputted invalid version: got '${OUTPUT}'"
cleanup

View File

@ -0,0 +1,61 @@
#!/bin/sh
\. ../../../nvm.sh
\. ../../common.sh
set -e
TEST_VERSION='v0.2.4'
if [ -f .nvmrc ]; then mv .nvmrc .nvmrc.orig; fi
cleanup() {
nvm cache clear
nvm deactivate
nvm unalias default
rm -rf "${NVM_DIR}/v0.2.4" .nvmrc
if [ -f .nvmrc.orig ]; then mv .nvmrc.orig .nvmrc; fi
unset -f nvm_ls_remote nvm_ls_remote_iojs
}
die() {
echo "$@"
cleanup
exit 1
}
REMOTE="${PWD}/mocks/nvm_ls_remote.txt"
nvm_ls_remote() {
if [ -n "${PATTERN}" ]; then
cat "${REMOTE}" | \grep "${PATTERN}"
else
cat "${REMOTE}"
fi
}
REMOTE_IOJS="$PWD/mocks/nvm_ls_remote_iojs.txt"
nvm_ls_remote_iojs() {
local PATTERN
PATTERN="${1-}"
if [ -n "${PATTERN}" ]; then
cat "${REMOTE_IOJS}" | \grep "${PATTERN}"
else
cat "${REMOTE_IOJS}"
fi
}
make_fake_node "${TEST_VERSION}"
nvm use -w "${TEST_VERSION}" || die "\`nvm install -w ${TEST_VERSION}\` failed"
OUTPUT="$(cat .nvmrc)"
nvm_is_valid_version "${OUTPUT}" \
|| die "\`nvm install -w ${TEST_VERSION}\`+ \`cat .nvmrc\` outputted invalid version: got '${OUTPUT}'"
rm .nvmrc || die 'removing of .nvmrc failed'
nvm use --save "${TEST_VERSION}" || die "\`nvm install --save ${TEST_VERSION}\` failed"
OUTPUT="$(cat .nvmrc)"
nvm_is_valid_version "${OUTPUT}" \
|| die "\`nvm install --save ${TEST_VERSION}\`+ \`cat .nvmrc\` outputted invalid version: got '${OUTPUT}'"
cleanup

View File

@ -12,7 +12,7 @@ cleanup () {
nvm cache clear
nvm deactivate
nvm unalias default
rm -rf ${NVM_DIR}/v* .nvmrc
rm -rf "${NVM_DIR}/${TEST_VERSION:?}" .nvmrc
if [ -f .nvmrc.orig ]; then mv .nvmrc.orig .nvmrc; fi
unset -f nvm_ls_remote nvm_ls_remote_iojs
}
@ -23,21 +23,29 @@ die () {
exit 1
}
REMOTE="$PWD/mocks/nvm_ls_remote.txt"
REMOTE="${PWD}/mocks/nvm_ls_remote.txt"
nvm_ls_remote() {
cat "$REMOTE"
cat "${REMOTE}"
}
REMOTE_IOJS="$PWD/mocks/nvm_ls_remote_iojs.txt"
REMOTE_IOJS="${PWD}/mocks/nvm_ls_remote_iojs.txt"
nvm_ls_remote_iojs() {
cat "$REMOTE_IOJS"
cat "${REMOTE_IOJS}"
}
make_fake_node "$TEST_VERSION"
make_fake_node "${TEST_VERSION}"
OUTPUT=$(nvm use --save --silent "$TEST_VERSION" || die "\`nvm use --save --silent $TEST_VERSION\` failed")
EXPECTED_OUTPUT=""
OUTPUT=$(nvm use --save --silent "${TEST_VERSION}" || die "\`nvm use --save --silent ${TEST_VERSION}\` failed")
EXPECTED_OUTPUT=''
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|| die "\`nvm use --save --silent $TEST_VERSION\` output was not silenced to '$EXPECTED_OUTPUT'; got '$OUTPUT'"
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] \
|| die "\`nvm use --save --silent ${TEST_VERSION}\` output was not silenced to '${EXPECTED_OUTPUT}'; got '${OUTPUT}'"
rm .nvmrc || die 'removing of .nvmrc failed'
OUTPUT=$(nvm use -w --silent "${TEST_VERSION}" || die "\`nvm use -w --silent ${TEST_VERSION}\` failed")
EXPECTED_OUTPUT=''
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] \
|| die "\`nvm use -w --silent ${TEST_VERSION}\` output was not silenced to '${EXPECTED_OUTPUT}'; got '${OUTPUT}'"
cleanup

View File

@ -1,62 +0,0 @@
#!/bin/sh
\. ../../../nvm.sh
set -e
if [ -f .nvmrc ]; then mv .nvmrc .nvmrc.orig; fi
TEST_VERSION="v0.2.4"
cleanup () {
nvm cache clear
nvm deactivate
nvm unalias default
rm -rf ${NVM_DIR}/v* .nvmrc
if [ -f .nvmrc.orig ]; then mv .nvmrc.orig .nvmrc; fi
unset -f nvm_ls_remote nvm_ls_remote_iojs
}
die () {
echo "$@"
cleanup
exit 1
}
nvm deactivate 2>/dev/null || die 'unable to deactivate'
\. ../../common.sh
REMOTE="$PWD/mocks/nvm_ls_remote.txt"
nvm_ls_remote() {
cat "$REMOTE"
}
REMOTE_IOJS="$PWD/mocks/nvm_ls_remote_iojs.txt"
nvm_ls_remote_iojs() {
cat "$REMOTE_IOJS"
}
make_fake_node "$TEST_VERSION"
# 1. install
nvm install -w "$TEST_VERSION" || die "\`nvm install -w $TEST_VERSION\` failed"
OUTPUT="$(cat .nvmrc)"
nvm_is_valid_version "$(cat .nvmrc)" \
|| die "\`nvm install -w $TEST_VERSION\`+ \`cat .nvmrc\` outputted invalid version: got '${OUTPUT}'"
#
unset OUTPUT
# 2. use
nvm use -w "$TEST_VERSION" || die "\`nvm use -w $TEST_VERSION\` failed"
OUTPUT="$(cat .nvmrc)"
nvm_is_valid_version "$(cat .nvmrc)" \
|| die "\`nvm use -w $TEST_VERSION\`+ \`cat .nvmrc\` outputted invalid version: got '${OUTPUT}'"
#
cleanup

View File

@ -22,11 +22,11 @@ nvm deactivate 2>/dev/null || die 'unable to deactivate'
\. ../../common.sh
MOCKS_DIR="$PWD/mocks"
MOCKS_DIR="${PWD}/mocks"
nvm_download() {
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"
return
fi
return 42
@ -34,15 +34,15 @@ nvm_download() {
EXPECTED_OUTPUT_PATH="${MOCKS_DIR}/nvm ls-remote lts.txt"
OUTPUT="$(nvm ls-remote --lts | 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 $(echo ">$OUTPUT<") expected $(echo ">$EXPECTED_OUTPUT<")"
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}<"
EXPECTED_OUTPUT_PATH="${MOCKS_DIR}/nvm ls-remote lts.txt"
OUTPUT="$(nvm ls-remote "lts/*" | 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 $(echo ">$OUTPUT<") expected $(echo ">$EXPECTED_OUTPUT<")"
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}<"
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)"
@ -56,18 +56,18 @@ printf '%s\n' "${LTS_LIST}" | while IFS= read -r LTS; do
INDEX=$(($INDEX + 1))
done
REMOTE="$PWD/mocks/nvm_ls_remote.txt"
REMOTE="${PWD}/mocks/nvm_ls_remote.txt"
nvm_ls_remote() {
cat "$REMOTE"
cat "${REMOTE}"
}
REMOTE_IOJS="$PWD/mocks/nvm_ls_remote_iojs.txt"
REMOTE_IOJS="${PWD}/mocks/nvm_ls_remote_iojs.txt"
nvm_ls_remote_iojs() {
cat "$REMOTE_IOJS"
cat "${REMOTE_IOJS}"
}
EXPECTED_OUTPUT_PATH="${MOCKS_DIR}/nvm ls-remote.txt"
OUTPUT="$(nvm ls-remote | sed 's/[ \t]*$//')"
EXPECTED_OUTPUT="$(cat "$EXPECTED_OUTPUT_PATH" | sed 's/[ \t]*$//' )"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "bare nvm ls-remote did not output expected sorted versions; got $(echo ">$OUTPUT<") expected $(echo ">$EXPECTED_OUTPUT<")"
EXPECTED_OUTPUT="$(cat "${EXPECTED_OUTPUT_PATH}" | sed 's/[ \t]*$//' )"
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] || die "bare nvm ls-remote did not output expected sorted versions; got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<"
cleanup

View File

@ -1,7 +1,7 @@
#!/bin/sh
cleanup () {
unset -f die cleanup NVM_AUTH_HEADER
unset -f die cleanup
docker stop httpbin && docker rm httpbin
}
die () { echo "$@" ; cleanup ; exit 1; }
@ -17,13 +17,12 @@ nvm_download "https://raw.githubusercontent.com/nvm-sh/nvm/HEAD/install.sh" >/de
! nvm_download "https://raw.githubusercontent.com/nvm-sh/nvm/HEAD/wrong_install.sh" >/dev/null || die "nvm_download should fail to download no existing file"
# nvm_download should pass when calling with auth header
docker pull kennethreitz/httpbin && docker run --shell=bash -d --name httpbin -p 80:80 kennethreitz/httpbin
docker pull kennethreitz/httpbin && SHELL=bash docker run -d --name httpbin -p 80:80 kennethreitz/httpbin
sleep 1 # wait for httpbin to start
NVM_AUTH_HEADER="Bearer test-token" nvm_download "http://127.0.0.1/bearer" > /dev/null || die 'nvm_download with auth header should send correctly'
# nvm_download should fail when calling without auth header
nvm_download "http://127.0.0.1/bearer" > /dev/null && die 'nvm_download with no auth header should not send the header and should fail'
docker stop httpbin && docker rm httpbin
# ensure quoted extra args remain quoted
nvm_download "https://raw.githubusercontent.com/nvm-sh/nvm/HEAD/install.sh" -o "; die quoted-command-not-quoted" || die 'command failed'

View File

@ -2,27 +2,29 @@
\. ../../../nvm.sh
FILE="$NVM_DIR/default-packages"
FILE="${NVM_DIR}/default-packages"
die () { echo "$@" ; cleanup ; exit 1; }
setup () {
if [ -f $FILE ]; then
ORIG_DEFAULT_PACKAGES=$(cat $FILE)
if [ -f "${FILE}" ]; then
ORIG_DEFAULT_PACKAGES=$(cat "${FILE}")
mkdir -p ./tmp/ ||:
mv $FILE ./tmp/default-packages ||:
mv "${FILE}" ./tmp/default-packages ||:
fi
touch $FILE
touch "${FILE}"
}
cleanup () {
if [ "$ORIG_DEFAULT_PACKAGES" != "" ]; then
if [ "${ORIG_DEFAULT_PACKAGES}" != "" ]; then
rm -rf ./tmp/
echo "$ORIG_DEFAULT_PACKAGES" > $FILE
echo "${ORIG_DEFAULT_PACKAGES}" > "${FILE}"
else
rm "${FILE}"
fi
}
setup
cat > $FILE << EOF
cat > "${FILE}" << EOF
rimraf
object-inspect@1.0.2
@ -39,7 +41,7 @@ cleanup
setup
cat > $FILE << EOF
cat > "${FILE}" << EOF
rimraf
not~a~package~name
mkdirp
@ -53,12 +55,12 @@ cleanup
setup
cat > $FILE << EOF
cat > "${FILE}" << EOF
rimraf
not~a~package~name
mkdirp
EOF
printf %s "$(cat "${FILE}")" > $FILE # strip trailing newline
printf %s "$(cat "${FILE}")" > "${FILE}" # strip trailing newline
DEFAULT_PKGS="$(nvm_get_default_packages)"
EXPECTED_PKGS='rimraf not~a~package~name mkdirp'
@ -68,7 +70,7 @@ cleanup
setup
cat > $FILE << EOF
cat > "${FILE}" << EOF
object-inspect @ 1.0.2
rimraf
EOF
@ -81,12 +83,12 @@ cleanup
setup
rm -rf $FILE
rm -rf "${FILE}"
DEFAULT_PKGS="$(nvm_get_default_packages)"
EXPECTED_PKGS=''
[ "${DEFAULT_PKGS}" = "${EXPECTED_PKGS}" ] || die "5: expected default packages >${EXPECTED_PKGS}<; got >${DEFAULT_PKGS}<"
touch $FILE
touch "${FILE}"
cleanup

View File

@ -1,33 +1,43 @@
#!/bin/sh
cleanup () {
[ -d "$tmp_dir" ] && rm -rf "$tmp_dir"
[ -d "$NVM_DIR" ] && rm -rf "$NVM_DIR"
cleanup() {
[ -d "${tmp_dir}" ] && rm -rf "${tmp_dir}"
[ -d "${NVM_DIR}" ] && rm -rf "${NVM_DIR}"
unset -f die cleanup test_archi nvm_supports_xz
unset NVM_DIR tmp_dir version archi
}
die () { echo "$@" ; cleanup ; exit 1; }
die() { echo "$@" ; cleanup ; exit 1; }
test_archi(){
local os="$1"
local version="$2"
local archi="$os-$3"
local node="$4"
local ext="$5"
local command="$6"
local command_option="$7"
local node_path="$tmp_dir/node-$version-$archi/$node"
test_archi() {
local os
os="$1"
local version
version="$2"
local archi
archi="$os-$3"
local node
node="$4"
local ext
ext="$5"
local command
command="$6"
local command_option
command_option="$7"
local node_dir
node_dir="${tmp_dir}/node-${version}-${archi}"
local node_path
node_path="${node_dir}/${node}"
# Create tarball
mkdir -p "$(dirname "$node_path")"
echo "node $version" > "$node_path"
(cd "$tmp_dir" && "$command" "$command_option" "$tmp_dir/node-$version-$archi.$ext" "node-$version-$archi" && rm -rf "$tmp_dir/node-$version-$archi")
[ -f "$tmp_dir/node-$version-$archi.$ext" ] || die "Unable to create fake $ext file"
mkdir -p "$(dirname "${node_path}")"
echo "node ${version}" > "${node_path}"
(cd "${tmp_dir}" && "${command}" "${command_option}" "${node_dir}.${ext}" "node-${version}-${archi}")
[ -f "${node_dir}.${ext}" ] || die "Unable to create fake ${ext} file"
# Extract it
nvm_install_binary_extract "$os" "$version" "${version:1}" "$tmp_dir/node-$version-$archi.$ext" "$tmp_dir/files"
[ "$(cat "$NVM_DIR/versions/node/$version/bin/node")" = "node $version" ] || die "Unable to extract $ext file"
nvm_install_binary_extract "$os" "$version" "$(expr "${version}" : '.\(.*\)')" "${node_dir}.$ext" "${tmp_dir}/files"
[ "$(cat "${NVM_DIR}/versions/node/${version}/bin/node")" = "node ${version}" ] || die "Unable to extract ${ext} file"
}
\. ../../../nvm.sh
@ -39,17 +49,18 @@ type nvm_install_binary_extract > /dev/null 2>&1 || die 'nvm_install_binary_extr
NVM_DIR=$(mktemp -d)
tmp_dir=$(mktemp -d)
if [ -z "$NVM_DIR" ] || [ -z "$tmp_dir" ]; then
if [ -z "${NVM_DIR}" ] || [ -z "${tmp_dir}" ]; then
die 'Unable to create temporary folder'
fi
# Test windows zip
test_archi 'win' 'v15.6.0' 'x64' 'node' 'zip' 'zip' '-qr'
# TODO: enable this
# test_archi 'win' 'v15.6.0' 'x64' 'node' 'zip' 'zip' '-qr'
# Test linux tar.xz
test_archi 'linux' 'v14.15.4' 'x64' 'bin/node' 'tar.xz' 'tar' '-cJf'
nvm_supports_xz(){
nvm_supports_xz() {
return 1
}

View File

@ -13,11 +13,9 @@ die () { >&2 echo "$@" ; cleanup ; exit 1; }
\. ../../../nvm.sh
nvm_has_colors() { return 1 ; }
cleanup
OUTPUT="$(2>&1 nvm install --no-progress v0.12.18)"
OUTPUT="$(TERM=dumb 2>&1 nvm install --no-progress v0.12.18)"
EXPECTED_OUTPUT="Downloading and installing node v0.12.18...
Downloading https://nodejs.org/dist/v0.12.18/node-v0.12.18-linux-x64.tar.xz...
Computing checksum with sha256sum
@ -25,19 +23,63 @@ Checksums matched!
Now using node v0.12.18 (npm v2.15.11)
Creating default alias: default -> v0.12.18 *"
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<, got >${OUTPUT}<"
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "1: expected >
${EXPECTED_OUTPUT}<, got >
${OUTPUT}<"
cleanup
OUTPUT="$(2>&1 nvm install v0.12.18)"
OUTPUT="$(TERM=dumb 2>&1 nvm install v0.12.18)"
EXPECTED_OUTPUT="Downloading and installing node v0.12.18...
Downloading https://nodejs.org/dist/v0.12.18/node-v0.12.18-linux-x64.tar.xz...
######################################################################## 100.0%
######################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v0.12.18 (npm v2.15.11)
Creating default alias: default -> v0.12.18 *"
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<, got >${OUTPUT}<"
[ "$(echo "${OUTPUT}" | wc -l)" = "$(echo "${EXPECTED_OUTPUT}" | wc -l)" ] || die "2: expected 7 lines, got $(echo "${OUTPUT}" | wc -l)"
# Preprocess function to handle carriage returns and extract final output
preprocess_output() {
echo "$1" | awk '
{
# For each line in the input
while (index($0, "\r") > 0) {
# If a carriage return is found, process it
pos = index($0, "\r")
before_cr = substr($0, 1, pos - 1)
after_cr = substr($0, pos + 1)
# Overwrite the line up to the carriage return with content after it
$0 = after_cr
}
print $0
}' | sed '/^$/d' # Remove any empty lines
}
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || {
echo "$OUTPUT" \
| while IFS= read -r output_line && IFS= read -r expected_line <&3; do
line_number=$((line_number + 1))
# Strip non-visible characters from both lines
clean_output=$(preprocess_output "$output_line")
if [ "${output_line}" != "${expected_line}" ] && ! echo "${clean_output}" | \grep -qE '^#+ 100\.0%$'; then
echo "Difference on line ${line_number}:"
echo "Output: ${output_line}"
echo "Expected: ${expected_line}"
echo "Byte-by-byte comparison:"
echo "Output: $(echo "${clean_output}" | od -An -tx1 | tr -d '\n')"
echo "Expected: $(echo "${expected_line}" | od -An -tx1 | tr -d '\n')"
die "4: expected >
${EXPECTED_OUTPUT}<, got >
${OUTPUT}<"
fi
done 3<<EOF
$EXPECTED_OUTPUT
EOF
}
cleanup

0
test/installation_iojs/install from source Executable file → Normal file
View File

View File

View File

@ -1,6 +1,10 @@
#!/bin/sh
die () { echo "$@" ; exit 1; }
die () {
unset -f nvm_install_binary nvm_install_source
echo "$@"
exit 1
}
\. ../../nvm.sh
@ -22,16 +26,28 @@ nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION || die "'nvm run $N
NVM_CURRENT_DEFAULT="$(nvm_alias default)"
[ "$NVM_CURRENT_DEFAULT" = "$NVM_TEST_VERSION" ] || die "wrong default alias: $(nvm alias)"
# Falls back to source but if -b is set fails binary download.
nvm_install_binary() {
>&2 echo 'binary failed'
return 1
}
# binary fails, falls back to source, but if -b is set, fails
OUTPUT="$(nvm install -b 9.0.0 2>&1)"
EXPECTED_OUTPUT='Binary download failed. Download from source aborted.'
if [ "${OUTPUT#*$EXPECTED_OUTPUT}" = "${OUTPUT}" ]; then
EXPECTED_OUTPUT='binary failed'
if [ "${OUTPUT#*"${EXPECTED_OUTPUT}"}" = "${OUTPUT}" ]; then
die "No source binary flag is active and should have returned >${EXPECTED_OUTPUT}<. Instead it returned >${OUTPUT}<"
fi
# Falls back to source but if -b is not set.
nvm_install_source() {
>&2 echo 'source intentionally failed'
return 1
}
# binary fails, falls back to source if -b is not set
OUTPUT="$(nvm install 9.0.0 2>&1)"
EXPECTED_OUTPUT='Binary download failed. Download from source aborted.'
if [ "${OUTPUT#*$EXPECTED_OUTPUT}" != "${OUTPUT}" ]; then
die "No source binary flag is active and should have returned >${EXPECTED_OUTPUT}<. Instead it returned >${OUTPUT}<"
fi
EXPECTED_OUTPUT="binary failed
Detected that you have 2 CPU core(s)
Number of CPU core(s) less than or equal to 2, running in single-threaded mode
source intentionally failed"
[ "${EXPECTED_OUTPUT}" = "${OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<, got >${OUTPUT}<"

View File

0
test/slow/nvm reinstall-packages/test-npmlink/index.js Executable file → Normal file
View File

View File