2020-07-25 11:59:32 +02:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
# 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}"
|
2021-06-06 01:39:26 +02:00
|
|
|
printf "8.1.0" > .n-node-version
|
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.1.0"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto .n-node-version, unix eol" {
|
|
|
|
cd "${MY_DIR}"
|
2021-06-06 01:39:26 +02:00
|
|
|
printf "8.1.1\n" > .n-node-version
|
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.1.1"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto .n-node-version, Windows eol" {
|
|
|
|
cd "${MY_DIR}"
|
2021-06-06 01:39:26 +02:00
|
|
|
printf "8.1.2\r\n" > .n-node-version
|
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.1.2"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto .n-node-version, leading v" {
|
|
|
|
cd "${MY_DIR}"
|
2021-06-06 01:39:26 +02:00
|
|
|
printf "v8.1.3\n" > .n-node-version
|
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.1.3"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto .n-node-version, first line only" {
|
|
|
|
cd "${MY_DIR}"
|
2021-06-06 01:39:26 +02:00
|
|
|
printf "8.1.4\nmore text\n" > .n-node-version
|
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.1.4"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto .n-node-version, from sub directory" {
|
|
|
|
cd "${MY_DIR}"
|
2021-06-06 01:39:26 +02:00
|
|
|
printf "8.2.0\n" > .n-node-version
|
2020-07-25 11:59:32 +02:00
|
|
|
mkdir -p sub6
|
|
|
|
cd sub6
|
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.2.0"
|
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}"
|
2021-06-06 01:39:26 +02:00
|
|
|
printf "8.2.1\n" > .n-node-version
|
2020-07-25 11:59:32 +02:00
|
|
|
mkdir -p sub7
|
|
|
|
cd sub7
|
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.2.1"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|