forked from nvm-sh/nvm
-
Notifications
You must be signed in to change notification settings - Fork 0
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 nvm-sh#2849. Co-authored-by: Martin <maartin00000@gmail.com> Co-authored-by: Jordan Harband <ljharb@gmail.com>
- Loading branch information
1 parent
c24c313
commit 6709d7d
Showing
8 changed files
with
261 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
42 changes: 42 additions & 0 deletions
42
...nit tests/Running 'nvm install --save --lts' 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,42 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
\. ../../../nvm.sh | ||
\. ../../common.sh | ||
|
||
if [ -f .nvmrc ]; then mv .nvmrc .nvmrc.orig; fi | ||
|
||
cleanup () { | ||
rm -f .nvmrc ../.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 lts/* | ||
|
||
{ | ||
(nvm install --save lts/*) && | ||
die "\`nvm install --save --lts\` did not fail with invalid permissions" | ||
} || echo "\`nvm install --save --lts\` failed successfully" | ||
|
||
cleanup |
46 changes: 46 additions & 0 deletions
46
...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,46 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
\. ../../../nvm.sh | ||
\. ../../common.sh | ||
|
||
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 lts/* | ||
|
||
rm -f .nvmrc ../.nvmrc | ||
(cd .. | ||
nvm install --save lts/*) | ||
|
||
nvm install --save lts/* | ||
OUTPUT="$(cat .nvmrc)" | ||
EXPECTED_OUTPUT="$(nvm_ls_current)" | ||
|
||
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] \ | ||
|| die "\`nvm use use --save\`+ \`cat .nvmrc\` did not output '${EXPECTED_OUTPUT}'; got '${OUTPUT}'" | ||
|
||
cleanup |
52 changes: 52 additions & 0 deletions
52
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,52 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
\. ../../../nvm.sh | ||
\. ../../common.sh | ||
|
||
if [ -f .nvmrc ]; then mv .nvmrc .nvmrc.orig; fi | ||
|
||
cleanup () { | ||
rm -f .nvmrc ../.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-} | ||
|
||
make_fake_node "${VERSION}" | ||
|
||
echo "+ nvm install --save $VERSION" | ||
nvm install --save "$VERSION" || die "\`nvm install --save ${VERSION}\` failed" | ||
OUTPUT="$(cat .nvmrc)" | ||
EXPECTED_OUTPUT="$(nvm_ls_current)" | ||
|
||
[ "_${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 |
39 changes: 39 additions & 0 deletions
39
test/fast/Unit tests/Running 'nvm install --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,39 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
\. ../../../nvm.sh | ||
\. ../../common.sh | ||
|
||
if [ -f .nvmrc ]; then mv .nvmrc .nvmrc.orig; fi | ||
|
||
cleanup () { | ||
rm -f .nvmrc ../.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 node | ||
|
||
OUTPUT=$(nvm install node --save --silent || die 'nvm use node failed') | ||
EXPECTED_OUTPUT="" | ||
|
||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \ | ||
|| die "'nvm install node --save --silent' output was not silenced to '$EXPECTED_OUTPUT'; got '$OUTPUT'" | ||
|
||
cleanup |
42 changes: 42 additions & 0 deletions
42
...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,42 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
\. ../../../nvm.sh | ||
\. ../../common.sh | ||
|
||
if [ -f .nvmrc ]; then mv .nvmrc .nvmrc.orig; fi | ||
|
||
cleanup () { | ||
rm -f .nvmrc ../.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 lts/* | ||
|
||
nvm alias test lts/* | ||
nvm use test --save || die "\`nvm use test --save\` failed" | ||
OUTPUT="$(cat .nvmrc)" | ||
EXPECTED_OUTPUT=$(nvm_ls_current) | ||
|
||
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] \ | ||
|| die "\`nvm use --save test\`+ \`cat .nvmrc\` did not output '${EXPECTED_OUTPUT}'; got '${OUTPUT}'" | ||
|
||
cleanup |