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-priority"
|
|
|
|
mkdir -p "${MY_DIR}"
|
|
|
|
|
|
|
|
# Need a version of node available for reading package.json
|
|
|
|
export N_PREFIX="${MY_DIR}"
|
|
|
|
export PATH="${MY_DIR}/bin:${PATH}"
|
2020-12-21 10:50:54 +01:00
|
|
|
n install lts
|
|
|
|
}
|
|
|
|
|
|
|
|
function teardown_file() {
|
|
|
|
rm -rf "${MY_DIR}"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
2020-12-21 10:50:54 +01:00
|
|
|
function setup() {
|
|
|
|
# Bit fragile, but reuse directory and clean up between tests.
|
|
|
|
rm -f "${MY_DIR}/package.json"
|
|
|
|
rm -f "${MY_DIR}/.n-node-version"
|
|
|
|
rm -f "${MY_DIR}/.node-version"
|
|
|
|
rm -f "${MY_DIR}/.nvmrc"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test ".n-node-version first" {
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
echo "401.0.1" > .n-node-version
|
|
|
|
echo "401.0.2" > .node-version
|
|
|
|
echo "401.0.3" > .nvmrc
|
|
|
|
echo '{ "engines" : { "node" : "v401.0.4" } }' > package.json
|
|
|
|
|
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}" "401.0.1"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test ".node-version second" {
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
echo "401.0.2" > .node-version
|
|
|
|
echo "401.0.3" > .nvmrc
|
|
|
|
echo '{ "engines" : { "node" : "v401.0.4" } }' > package.json
|
|
|
|
|
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}" "401.0.2"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test ".nvmrc third" {
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
echo "401.0.3" > .nvmrc
|
|
|
|
echo '{ "engines" : { "node" : "v401.0.4" } }' > package.json
|
|
|
|
|
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}" "401.0.3"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test ".package.json last" {
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
echo '{ "engines" : { "node" : "v401.0.4" } }' > package.json
|
|
|
|
|
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}" "401.0.4"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
2020-12-20 04:17:18 +01:00
|
|
|
@test ".package.json last, after parent scanning" {
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
echo "401.0.2" > .node-version
|
|
|
|
mkdir package
|
|
|
|
cd package
|
|
|
|
echo '{ "engines" : { "node" : "v401.0.4" } }' > package.json
|
|
|
|
|
|
|
|
output="$(n N_TEST_DISPLAY_LATEST_RESOLVED_VERSION auto)"
|
2020-12-21 10:50:54 +01:00
|
|
|
assert_equal "${output}" "401.0.2"
|
2020-12-20 04:17:18 +01:00
|
|
|
|
|
|
|
rm package.json
|
|
|
|
cd ..
|
|
|
|
rmdir package
|
|
|
|
}
|