2020-07-25 11:59:32 +02:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
# Note: full semver is resolved without lookup, so can use arbitrary versions for testing like 999.999.999
|
|
|
|
# Not testing all the permutations on both files, as know they are currenly implemented using same code!
|
|
|
|
|
|
|
|
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-file"
|
|
|
|
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}/.n-node-version"
|
|
|
|
rm -f "${MY_DIR}/.node-version"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto, missing file" {
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
run n N_TEST_DISPLAY_LATEST_RESOLVED_VERSION auto
|
2020-12-21 10:50:54 +01:00
|
|
|
assert [ "$status" -ne 0 ]
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto .n-node-version, no eol" {
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
printf "101.0.1" > .n-node-version
|
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}" "101.0.1"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto .n-node-version, unix eol" {
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
printf "101.0.2\n" > .n-node-version
|
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}" "101.0.2"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto .n-node-version, Windows eol" {
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
printf "101.0.3\r\n" > .n-node-version
|
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}" "101.0.3"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto .n-node-version, leading v" {
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
printf "v101.0.4\n" > .n-node-version
|
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}" "101.0.4"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto .n-node-version, first line only" {
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
printf "101.0.5\nmore text\n" > .n-node-version
|
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}" "101.0.5"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto .n-node-version, from sub directory" {
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
printf "101.0.6\nmore text\n" > .n-node-version
|
|
|
|
mkdir -p sub6
|
|
|
|
cd sub6
|
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}" "101.0.6"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto .node-version, partial version lookup" {
|
|
|
|
# Check normal resolving
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
printf "4.9\n" > .node-version
|
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 .node-version, from sub directory" {
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
printf "101.0.7\nmore text\n" > .n-node-version
|
|
|
|
mkdir -p sub7
|
|
|
|
cd sub7
|
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}" "101.0.7"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|