-
-
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
Showing
9 changed files
with
168 additions
and
6 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
32 changes: 32 additions & 0 deletions
32
...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,32 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
die () { | ||
unset -f nvm_ls_remote nvm_ls_remote_iojs | ||
>&2 echo "$@" | ||
exit 1 | ||
} | ||
|
||
\. ../../../nvm.sh | ||
\. ../../common.sh | ||
|
||
rm -rf .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" |
41 changes: 41 additions & 0 deletions
41
test/fast/Unit tests/Running 'nvm install --save x' 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,41 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
die () { | ||
unset -f nvm_ls_remote nvm_ls_remote_iojs | ||
>&2 echo "$@" | ||
exit 1 | ||
} | ||
|
||
\. ../../../nvm.sh | ||
\. ../../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" | ||
} | ||
|
||
test_version () { | ||
rm -f .nvmrc | ||
VERSION=${1-} | ||
|
||
make_fake_node "${VERSION}" | ||
|
||
nvm install --save "${VERSION}" || die "\`nvm install --save ${VERSION}\` failed" | ||
OUTPUT="$(cat .nvmrc)" | ||
EXPECTED_OUTPUT="$(nvm_ls_current)" | ||
|
||
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] \ | ||
|| die "\`nvm use use --save ${VERSION}\`+ \`cat .nvmrc\` did not output '${EXPECTED_OUTPUT}'; got '${OUTPUT}'" | ||
} | ||
|
||
test_version '--lts' || die | ||
test_version 'lts/argon' || die | ||
test_version 'lts/*' || die | ||
test_version 'node' || die | ||
test_version 'iojs' || die |
35 changes: 35 additions & 0 deletions
35
...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,35 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
die () { | ||
unset -f nvm_ls_remote nvm_ls_remote_iojs | ||
>&2 echo "$@" | ||
exit 1 | ||
} | ||
|
||
\. ../../../nvm.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 lts | ||
|
||
(cd .. | ||
rm -rf .nvmrc | ||
nvm install --save --lts) | ||
|
||
nvm install --save | ||
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}'" | ||
|
||
rm -rf ../.nvmrc .nvmrc |
19 changes: 19 additions & 0 deletions
19
...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,19 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
die () { echo "$@" ; exit 1; } | ||
|
||
\. ../../../nvm.sh | ||
|
||
rm -rf .nvmrc; | ||
|
||
nvm alias test node | ||
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}'" | ||
|
||
nvm unalias test |
14 changes: 14 additions & 0 deletions
14
test/fast/Unit tests/Running 'nvm use --silent --save node' should be silenced
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,14 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
die () { echo "$@" ; exit 1; } | ||
|
||
\. ../../../nvm.sh | ||
|
||
rm -rf .nvmrc; | ||
OUTPUT="$(nvm use --silent --save node || die "\`nvm use --silent --save node\` failed")" | ||
EXPECTED_OUTPUT='' | ||
|
||
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] \ | ||
|| die "\`nvm use --silent --save node\` was not silenced; got '${OUTPUT}'" |
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