2020-07-25 11:59:32 +02:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load shared-functions
|
2020-12-21 10:50:54 +01:00
|
|
|
load '../../node_modules/bats-support/load'
|
|
|
|
load '../../node_modules/bats-assert/load'
|
2020-07-25 11:59:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
# auto
|
|
|
|
|
2020-12-21 10:50:54 +01:00
|
|
|
function setup_file() {
|
2020-07-25 11:59:32 +02:00
|
|
|
unset_n_env
|
|
|
|
tmpdir="${TMPDIR:-/tmp}"
|
|
|
|
export MY_DIR="${tmpdir}/n/test/version-resolve-auto-nvmrc"
|
|
|
|
mkdir -p "${MY_DIR}"
|
|
|
|
}
|
|
|
|
|
2020-12-21 10:50:54 +01:00
|
|
|
function teardown_file() {
|
|
|
|
rm -rf "${MY_DIR}"
|
|
|
|
}
|
|
|
|
|
|
|
|
function setup() {
|
|
|
|
rm -f "${MY_DIR}/.nvmrc"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto .nvmrc, numeric" {
|
|
|
|
cd "${MY_DIR}"
|
2021-06-06 01:39:26 +02:00
|
|
|
printf "8.10.0\n" > .nvmrc
|
2020-12-20 04:17:18 +01:00
|
|
|
output="$(n N_TEST_DISPLAY_LATEST_RESOLVED_VERSION auto)"
|
2021-06-06 01:39:26 +02:00
|
|
|
assert_equal "${output}" "8.10.0"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto .nvmrc, numeric with leading v" {
|
|
|
|
cd "${MY_DIR}"
|
2021-06-06 01:39:26 +02:00
|
|
|
printf "v8.11.0\n" > .nvmrc
|
2020-12-20 04:17:18 +01:00
|
|
|
output="$(n N_TEST_DISPLAY_LATEST_RESOLVED_VERSION auto)"
|
2021-06-06 01:39:26 +02:00
|
|
|
assert_equal "${output}" "8.11.0"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto .nvmrc, node" {
|
|
|
|
local TARGET_VERSION="$(display_remote_version latest)"
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
printf "node\n" > .nvmrc
|
2020-12-20 04:17:18 +01:00
|
|
|
output="$(n N_TEST_DISPLAY_LATEST_RESOLVED_VERSION auto)"
|
2020-12-21 10:50:54 +01:00
|
|
|
assert_equal "${output}" "${TARGET_VERSION}"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto .nvmrc, lts/*" {
|
|
|
|
local TARGET_VERSION="$(display_remote_version lts)"
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
printf "lts/*\n" > .nvmrc
|
2020-12-20 04:17:18 +01:00
|
|
|
output="$(n N_TEST_DISPLAY_LATEST_RESOLVED_VERSION auto)"
|
2020-12-21 10:50:54 +01:00
|
|
|
assert_equal "${output}" "${TARGET_VERSION}"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto .nvmrc, lts/argon" {
|
|
|
|
local TARGET_VERSION="$(display_remote_version lts)"
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
printf "lts/argon\n" > .nvmrc
|
2020-12-20 04:17:18 +01:00
|
|
|
output="$(n N_TEST_DISPLAY_LATEST_RESOLVED_VERSION auto)"
|
2020-12-21 10:50:54 +01:00
|
|
|
assert_equal "${output}" "4.9.1"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto .nvmrc, sub directory" {
|
|
|
|
cd "${MY_DIR}"
|
2021-06-06 01:39:26 +02:00
|
|
|
printf "v8.11.1\n" > .nvmrc
|
2020-07-25 11:59:32 +02:00
|
|
|
mkdir -p sub-npmrc
|
|
|
|
cd sub-npmrc
|
2020-12-20 04:17:18 +01:00
|
|
|
output="$(n N_TEST_DISPLAY_LATEST_RESOLVED_VERSION auto)"
|
2021-06-06 01:39:26 +02:00
|
|
|
assert_equal "${output}" "8.11.1"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
2024-10-28 02:58:34 +01:00
|
|
|
|
|
|
|
@test "auto .nvmrc, trailing comment" {
|
|
|
|
local TARGET_VERSION="8.10.0"
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
printf "${TARGET_VERSION} # comment" > .nvmrc
|
|
|
|
output="$(n N_TEST_DISPLAY_LATEST_RESOLVED_VERSION auto)"
|
|
|
|
assert_equal "${output}" "${TARGET_VERSION}"
|
|
|
|
}
|