-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[New]
nvm use
/nvm install
: add --save
option
Fixes #2849. Co-authored-by: Martin <[email protected]> Co-authored-by: Jordan Harband <[email protected]>
- Loading branch information
1 parent
c24c313
commit ae27ed5
Showing
8 changed files
with
281 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ test/bak | |
.urchin.log | ||
.urchin_stdout | ||
test/**/test_output | ||
test/**/.nvmrc | ||
|
||
node_modules/ | ||
npm-debug.log | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ test/bak | |
.urchin.log | ||
.urchin_stdout | ||
test/**/test_output | ||
test/**/.nvmrc | ||
|
||
node_modules/ | ||
npm-debug.log | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...Unit tests/Running 'nvm install --save node' with incorrect file permissions fails nicely
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
\. ../../../nvm.sh | ||
\. ../../common.sh | ||
|
||
TEST_VERSION="$(nvm_version node)" | ||
echo "Using test version '$TEST_VERSION'" | ||
|
||
if [ -f .nvmrc ]; then mv .nvmrc .nvmrc.orig; fi | ||
|
||
cleanup () { | ||
rm -f .nvmrc | ||
if [ -f .nvmrc.orig ]; then mv .nvmrc.orig .nvmrc; fi | ||
} | ||
|
||
die () { | ||
unset -f nvm_ls_remote nvm_ls_remote_iojs | ||
>&2 echo "$@" | ||
cleanup | ||
exit 1 | ||
} | ||
|
||
rm -f .nvmrc | ||
echo '' > .nvmrc | ||
chmod 0 .nvmrc | ||
|
||
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" | ||
|
||
{ | ||
(nvm install --save "$TEST_VERSION") && | ||
die "\`nvm install --save $TEST_VERSION\` did not fail with invalid permissions" | ||
} || echo "\`nvm install --save $TEST_VERSION\` failed successfully" | ||
|
||
cleanup |
49 changes: 49 additions & 0 deletions
49
...sts/Running 'nvm install --save' should work with a '.nvmrc' file in the parent directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
\. ../../../nvm.sh | ||
\. ../../common.sh | ||
|
||
TEST_VERSION="$(nvm_version node)" | ||
echo "Using test version '$TEST_VERSION'" | ||
|
||
if [ -f .nvmrc ]; then mv .nvmrc .nvmrc.orig; fi | ||
if [ -f ../.nvmrc ]; then mv ../.nvmrc ../.nvmrc.orig; fi | ||
|
||
cleanup () { | ||
rm -f .nvmrc ../.nvmrc | ||
if [ -f .nvmrc.orig ]; then mv .nvmrc.orig .nvmrc; fi | ||
if [ -f ../.nvmrc.orig ]; then mv ../.nvmrc.orig ../.nvmrc; fi | ||
unset -f nvm_ls_remote nvm_ls_remote_iojs | ||
} | ||
|
||
die () { | ||
>&2 echo "$@" | ||
cleanup | ||
exit 1 | ||
} | ||
|
||
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" | ||
|
||
rm -f .nvmrc ../.nvmrc | ||
(cd .. | ||
nvm install --save "$TEST_VERSION") | ||
|
||
nvm install --save "$TEST_VERSION" | ||
OUTPUT="$(nvm_version $(cat .nvmrc))" | ||
EXPECTED_OUTPUT="$TEST_VERSION" | ||
|
||
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] \ | ||
|| die "\`nvm use use --save\`+ \`cat .nvmrc\` did not output '${EXPECTED_OUTPUT}'; got '${OUTPUT}'" | ||
|
||
cleanup |
53 changes: 53 additions & 0 deletions
53
test/fast/Unit tests/Running 'nvm install --save' works as expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
\. ../../../nvm.sh | ||
\. ../../common.sh | ||
|
||
if [ -f .nvmrc ]; then mv .nvmrc .nvmrc.orig; fi | ||
|
||
cleanup () { | ||
rm -f .nvmrc | ||
if [ -f .nvmrc.orig ]; then mv .nvmrc.orig .nvmrc; fi | ||
unset -f nvm_ls_remote nvm_ls_remote_iojs | ||
} | ||
|
||
die () { | ||
>&2 echo "$@" | ||
cleanup | ||
exit 1 | ||
} | ||
|
||
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" | ||
} | ||
|
||
test_version () { | ||
rm -f .nvmrc | ||
VERSION=${1-} | ||
TEST_VERSION="$(nvm_version "$VERSION")" | ||
|
||
make_fake_node "${TEST_VERSION}" | ||
|
||
echo "+ nvm install --save $VERSION" | ||
nvm install --save "$VERSION" || die "\`nvm install --save ${VERSION}\` failed" | ||
OUTPUT="$(nvm_version $(cat .nvmrc))" | ||
EXPECTED_OUTPUT="$(nvm_version)" | ||
|
||
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] \ | ||
|| die "\`nvm install --save ${VERSION}\`+ \`cat .nvmrc\` did not output '${EXPECTED_OUTPUT}'; got '${OUTPUT}'" | ||
} | ||
|
||
test_version "--lts" || die | ||
test_version "lts/iron" || die | ||
test_version "lts/*" || die | ||
#test_version "node" || die | ||
test_version "iojs" || die | ||
|
||
cleanup |
54 changes: 54 additions & 0 deletions
54
...Unit tests/Running 'nvm use --save test' where 'test' is an alias should work as expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
\. ../../../nvm.sh | ||
\. ../../common.sh | ||
|
||
TEST_VERSION=$(nvm_version node) | ||
echo "Using test version '$TEST_VERSION'" | ||
|
||
if [ -f .nvmrc ]; then mv .nvmrc .nvmrc.orig; fi | ||
|
||
cleanup () { | ||
rm -f .nvmrc | ||
if [ -f .nvmrc.orig ]; then mv .nvmrc.orig .nvmrc; fi | ||
unset -f nvm_ls_remote nvm_ls_remote_iojs | ||
nvm unalias test | ||
} | ||
|
||
die () { | ||
>&2 echo "$@" | ||
cleanup | ||
exit 1 | ||
} | ||
|
||
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" | ||
|
||
echo "+ nvm unalias test" | ||
nvm unalias test &>/dev/null | ||
echo "+ nvm install $TEST_VERSION" | ||
nvm install "$TEST_VERSION" | ||
echo "+ nvm alias test $TEST_VERSION" | ||
nvm alias test "$TEST_VERSION" | ||
echo "+ nvm install test" | ||
nvm install test | ||
echo "nvm use --save test" | ||
nvm use --save test | ||
|
||
OUTPUT="$(nvm_version "$(cat .nvmrc)")" | ||
EXPECTED_OUTPUT="$TEST_VERSION" | ||
|
||
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] \ | ||
|| die "\`nvm use --save test\`+ \`cat .nvmrc\` did not output '${EXPECTED_OUTPUT}'; got '${OUTPUT}'" | ||
|
||
cleanup |
44 changes: 44 additions & 0 deletions
44
test/fast/Unit tests/Running 'nvm use --silent --save' doesn't output anything
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
\. ../../../nvm.sh | ||
\. ../../common.sh | ||
|
||
TEST_VERSION=$(nvm_version node) | ||
echo "Using test version '$TEST_VERSION'" | ||
|
||
if [ -f .nvmrc ]; then mv .nvmrc .nvmrc.orig; fi | ||
|
||
cleanup () { | ||
rm -f .nvmrc | ||
if [ -f .nvmrc.orig ]; then mv .nvmrc.orig .nvmrc; fi | ||
unset -f nvm_ls_remote nvm_ls_remote_iojs | ||
} | ||
|
||
die () { | ||
>&2 echo "$@" | ||
cleanup | ||
exit 1 | ||
} | ||
|
||
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" | ||
nvm install "$TEST_VERSION" || die "'nvm install $TEST_VERSION' failed" | ||
|
||
echo "+ nvm use --save --silent $TEST_VERSION" | ||
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'" | ||
|
||
cleanup |