[New] nvm use/nvm install: add --save option#2869
Conversation
Fixes nvm-sh#2849. Co-authored-by: Martin <maartin00000@gmail.com> Co-authored-by: Jordan Harband <ljharb@gmail.com>
--save option for nvm use and nvm install
ljharb
left a comment
There was a problem hiding this comment.
Let's add a bunch more tests - here's some example input:
nvm use --save --ltsnvm use --save lts/argonnvm use --save lts/*nvm use --save nodenvm use --save iojsnvm use --save foo(wherefoois a custom user alias)nvm use --save(where the version is read from a.nvmrcin a higher directory)
Let's also add some error tests for the cases where the .nvmrc file fails to be written (no permissions in the current directory, or the disk is full, for example)
|
Thanks for all the advice, it's been really helpful! |
|
If you can make them be "fast" tests, then one file is totally fine - mainly it'll depend on how much setup is required. Generally each test file should only have one batch of setup at the beginning, and one batch of cleanup at the end. |
test/slow/nvm use/Running 'nvm use --save --lts' should work as expected
Outdated
Show resolved
Hide resolved
ljharb
left a comment
There was a problem hiding this comment.
The nvm install and nvm use tests should definitely be in separate files.
Also, could the tests all be moved to fast? they'd be able to use mocks for nvm ls-remote calls, and as long as the dynamically-looked-up expected versions were fake-installed already, then they wouldn't need to actually install anything.
test/slow/nvm use/Running 'nvm use --save --lts' should work as expected
Outdated
Show resolved
Hide resolved
test/slow/nvm use/Running 'nvm use --save --lts' should work as expected
Outdated
Show resolved
Hide resolved
test/slow/nvm use/Running 'nvm use --save --lts' should work as expected
Outdated
Show resolved
Hide resolved
test/slow/nvm use/Running 'nvm use --save --lts' should work as expected
Outdated
Show resolved
Hide resolved
test/slow/nvm use/Running 'nvm use --save --lts' should work as expected
Outdated
Show resolved
Hide resolved
I've moved all of the test to 'fast' and split them into different files, however I'm not sure how to do fake installs (have you got any existing functions to do that?) |
test/fast/Running 'nvm install --save --lts' with incorrect file permissions fails nicely
Outdated
Show resolved
Hide resolved
i do! grep for |
Hmm, I tried that (from |
|
If you'd like I can prepend that to all of the |
|
ah right, the other piece is that you have to mock out |
|
I'm not quite sure how to mock |
|
I added the mocks; I think this might be good to go! It'll have to wait until the broken travis tests on master are fixed; please keep the fork/branch undeleted and the PR open until then :-) |
--save option for nvm use and nvm installnvm use/nvm install: add --save option
67ab6bb to
a40bfed
Compare
b226e57 to
2519281
Compare
|
Just pushed again with a 3 more things:
|
yeah, that's fine - sometimes i have to setting -e isn't even really a good practice anymore, so i'm not too worried about it. good to set it in tests if possible tho :-) |
|
Just rebased again if you think this is ready to merge? |
|
Unfortunately the Travis tests are still failing - https://app.travis-ci.com/github/nvm-sh/nvm/jobs/619295015 |
28ebb07 to
4375ca3
Compare
|
@ljharb There was only one issue which was surprisingly simple to fix, but annoying to figure out - I just needed to add a couple of extra bits to the 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
} |
|
@maartin0 sorry for the delay here; can you please rebase this and resolve the conflicts? |
|
@ljharb All done and no worries, although Travis seems to have another issue?
|
|
yep, known and don’t worry about that one :-) |
c6cfc3a to
c20db2a
Compare

In this PR I've:
--saveoption as pernvm useshould write a.nvmrcfile by default #2849nvm useandnvm install(which actually just carries over the option)bash,shandzshFixes #2849