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-20 04:17:18 +01:00
|
|
|
# engine is a label too! These tests mostly use auto as first available only through auto.
|
2020-07-25 11:59:32 +02:00
|
|
|
|
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-engine"
|
|
|
|
mkdir -p "${MY_DIR}"
|
|
|
|
|
|
|
|
# Need a version of node and npx 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() {
|
|
|
|
rm -f "${MY_DIR}/package.json"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function write_engine() {
|
|
|
|
echo '{ "engines" : { "node" : "'"$1"'" } }' > package.json
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "setupAll for auto-engine # (1 install)" {
|
|
|
|
# Dummy test so setupAll displayed while running first setup
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto engine, 104.0.1" {
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
write_engine "103.0.1"
|
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}" "103.0.1"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto engine, v104.0.2" {
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
write_engine "v104.0.2"
|
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}" "104.0.2"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto engine, =104.0.3" {
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
write_engine "=103.0.3"
|
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}" "103.0.3"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto engine, =v104.0.4" {
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
write_engine "=v104.0.4"
|
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}" "104.0.4"
|
2020-12-20 04:17:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "engine, =v104.0.5" {
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
write_engine "=v104.0.5"
|
|
|
|
output="$(n N_TEST_DISPLAY_LATEST_RESOLVED_VERSION engine)"
|
2020-12-21 10:50:54 +01:00
|
|
|
assert_equal "${output}" "104.0.5"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto engine, >1" {
|
|
|
|
local TARGET_VERSION="$(display_remote_version latest)"
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
write_engine ">1"
|
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 engine, >=2" {
|
|
|
|
local TARGET_VERSION="$(display_remote_version latest)"
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
write_engine ">=2"
|
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 engine, 8" {
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
write_engine "8"
|
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}" "8.17.0"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto engine, 8.x" {
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
write_engine "8.x"
|
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}" "8.17.0"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto engine, 8.X" {
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
write_engine "8.X"
|
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}" "8.17.0"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto engine, 8.*" {
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
write_engine "8.*"
|
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}" "8.17.0"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto engine, ~8.11.0" {
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
write_engine "~8.11.0"
|
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}" "8.11.4"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto engine, ~8.11" {
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
write_engine "~8.11"
|
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}" "8.11.4"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto engine, ~8" {
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
write_engine "~8"
|
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}" "8.17.0"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto engine, ^8.11.0" {
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
write_engine "^8.11.0"
|
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}" "8.17.0"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto engine, ^8.x" {
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
write_engine "^8.x"
|
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}" "8.17.0"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto engine, subdir" {
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
write_engine "8.11.2"
|
|
|
|
mkdir -p sub-engine
|
|
|
|
cd sub-engine
|
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}" "8.11.2"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto engine (semver), <8.12" {
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
write_engine "<8.12"
|
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}" "8.11.4"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto engine (semver), 8.11.1 - 8.11.3" {
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
write_engine "8.11.1 - 8.11.3"
|
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}" "8.11.3"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto engine (semver), >8.1 <8.12 || >2.1 <3.4" {
|
|
|
|
cd "${MY_DIR}"
|
|
|
|
write_engine ">8.1 <8.12 || >2.1 <3.4"
|
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}" "8.11.4"
|
2020-07-25 11:59:32 +02:00
|
|
|
}
|