[Tests] add tests for auto-creation of LTS aliases on `nvm_ls_remote`
parent
f0668fd577
commit
4c010f442e
|
@ -7,6 +7,7 @@ alias
|
|||
test/bak
|
||||
.urchin.log
|
||||
.urchin_stdout
|
||||
test/**/test_output
|
||||
|
||||
node_modules/
|
||||
npm-debug.log
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
lts/argon|v4.4.7
|
||||
lts/*|lts/argon
|
|
@ -0,0 +1,50 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -ex
|
||||
|
||||
die () { echo $@ ; cleanup ; exit 1; }
|
||||
|
||||
TEST_PATH="$PWD/test_output"
|
||||
mkdir -p "$TEST_PATH"
|
||||
CALL_COUNT_PATH="$TEST_PATH/call_count.txt"
|
||||
: > "$CALL_COUNT_PATH"
|
||||
ALIAS_ARGS_PATH="$TEST_PATH/nvm_make_alias_args.txt"
|
||||
: > "$ALIAS_ARGS_PATH"
|
||||
|
||||
cleanup() {
|
||||
unset -f nvm_download nvm_make_alias
|
||||
rm -rf "$TEST_PATH"
|
||||
}
|
||||
|
||||
. ../../../nvm.sh
|
||||
|
||||
set -ex
|
||||
|
||||
MOCKS_DIR="$PWD/mocks"
|
||||
|
||||
# sample output at the time the test was written
|
||||
TAB_PATH="$MOCKS_DIR/nodejs.org-dist-index.tab"
|
||||
nvm_download() {
|
||||
cat "$TAB_PATH"
|
||||
}
|
||||
|
||||
nvm_make_alias() {
|
||||
CALL_COUNT="$(cat "$CALL_COUNT_PATH")"
|
||||
CALL_COUNT="$((CALL_COUNT + 1))"
|
||||
echo "$CALL_COUNT" > "$CALL_COUNT_PATH"
|
||||
echo "${1}|${2}" >> "$ALIAS_ARGS_PATH"
|
||||
}
|
||||
|
||||
nvm_ls_remote >/dev/null || die "nvm_ls_remote_failed?!"
|
||||
|
||||
CALL_COUNT="$(cat "$CALL_COUNT_PATH")"
|
||||
|
||||
EXPECTED_COUNT=2
|
||||
[ "$CALL_COUNT" = "$EXPECTED_COUNT" ] || die "nvm_make_alias called $CALL_COUNT times; expected $EXPECTED_COUNT"
|
||||
|
||||
ARGS="$(cat "$ALIAS_ARGS_PATH")"
|
||||
EXPECTED_ARGS_PATH="$MOCKS_DIR/nvm_make_alias LTS alias calls.txt"
|
||||
EXPECTED_ARGS="$(cat "$EXPECTED_ARGS_PATH")"
|
||||
[ "${ARGS}" = "${EXPECTED_ARGS}" ] || die "nvm_make_alias called with >${ARGS}<; expected >${EXPECTED_ARGS}<"
|
||||
|
||||
cleanup
|
|
@ -15,6 +15,11 @@ nvm_is_version_installed() {
|
|||
return 1
|
||||
}
|
||||
|
||||
nvm_make_alias() {
|
||||
# prevent local alias creation
|
||||
return 0
|
||||
}
|
||||
|
||||
nvm_ls_remote > "$MOCKS_DIR/nvm_ls_remote.txt"
|
||||
nvm_ls_remote_iojs > "$MOCKS_DIR/nvm_ls_remote_iojs.txt"
|
||||
NVM_LTS=* nvm_ls_remote > "$MOCKS_DIR/nvm_ls_remote LTS.txt"
|
||||
|
@ -26,4 +31,12 @@ nvm ls-remote --lts > "$MOCKS_DIR/nvm ls-remote lts.txt"
|
|||
nvm ls-remote node > "$MOCKS_DIR/nvm ls-remote node.txt"
|
||||
nvm ls-remote iojs > "$MOCKS_DIR/nvm ls-remote iojs.txt"
|
||||
|
||||
ALIAS_PATH="$MOCKS_DIR/nvm_make_alias LTS alias calls.txt"
|
||||
: > "$ALIAS_PATH"
|
||||
nvm_make_alias() {
|
||||
# prevent local alias creation, and store arguments
|
||||
echo "${1}|${2}" >> "$ALIAS_PATH"
|
||||
}
|
||||
nvm ls-remote --lts
|
||||
|
||||
echo "done! Don't forget to git commit them."
|
||||
|
|
Loading…
Reference in New Issue