2019-08-04 06:33:45 +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'
|
2019-08-04 06:33:45 +02:00
|
|
|
|
2020-12-21 10:50:54 +01:00
|
|
|
function setup_file() {
|
2019-08-04 06:33:45 +02:00
|
|
|
unset_n_env
|
|
|
|
# fixed directory so can reuse the two installs
|
2020-04-11 04:10:29 +02:00
|
|
|
tmpdir="${TMPDIR:-/tmp}"
|
|
|
|
export N_PREFIX="${tmpdir}/n/test/run-which"
|
2024-11-08 23:42:51 +01:00
|
|
|
n download 4.9.1
|
|
|
|
n download lts
|
2021-09-10 11:19:07 +02:00
|
|
|
# using "latest" for download tests with run and exec
|
2019-08-04 06:33:45 +02:00
|
|
|
}
|
|
|
|
|
2020-12-21 10:50:54 +01:00
|
|
|
function teardown_file() {
|
|
|
|
rm -rf "${N_PREFIX}"
|
2019-08-04 06:33:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "setupAll for run/which/exec # (2 installs)" {
|
|
|
|
# Dummy test so setupAll displayed while running first setup
|
|
|
|
[ -d "${N_PREFIX}/n/versions/node/4.9.1" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# n which
|
|
|
|
|
|
|
|
@test "n which 4" {
|
2020-12-20 04:42:27 +01:00
|
|
|
output="$(n which 4)"
|
2020-12-21 10:50:54 +01:00
|
|
|
assert_equal "$output" "${N_PREFIX}/n/versions/node/4.9.1/bin/node"
|
2019-08-04 06:33:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@test "n which v4.9.1" {
|
2020-12-20 04:42:27 +01:00
|
|
|
output="$(n which v4.9.1)"
|
2020-12-21 10:50:54 +01:00
|
|
|
assert_equal "$output" "${N_PREFIX}/n/versions/node/4.9.1/bin/node"
|
2019-08-04 06:33:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "n bin v4.9.1" {
|
2020-12-20 04:42:27 +01:00
|
|
|
output="$(n bin v4.9.1)"
|
2020-12-21 10:50:54 +01:00
|
|
|
assert_equal "$output" "${N_PREFIX}/n/versions/node/4.9.1/bin/node"
|
2019-08-04 06:33:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "n which argon" {
|
2020-12-20 04:42:27 +01:00
|
|
|
output="$(n which argon)"
|
2020-12-21 10:50:54 +01:00
|
|
|
assert_equal "$output" "${N_PREFIX}/n/versions/node/4.9.1/bin/node"
|
2019-08-04 06:33:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "n which lts" {
|
2020-12-20 04:42:27 +01:00
|
|
|
output="$(n which lts)"
|
2019-08-04 06:33:45 +02:00
|
|
|
local LTS_VERSION="$(display_remote_version lts)"
|
2020-12-21 10:50:54 +01:00
|
|
|
assert_equal "$output" "${N_PREFIX}/n/versions/node/${LTS_VERSION}/bin/node"
|
2019-08-04 06:33:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# n run
|
|
|
|
|
|
|
|
@test "n run 4" {
|
2020-12-20 04:42:27 +01:00
|
|
|
output="$(n run 4 --version)"
|
2020-12-21 10:50:54 +01:00
|
|
|
assert_equal "$output" "v4.9.1"
|
2019-08-04 06:33:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "n run lts" {
|
2020-12-20 04:42:27 +01:00
|
|
|
output="$(n run lts --version)"
|
2019-08-04 06:33:45 +02:00
|
|
|
local LTS_VERSION="$(display_remote_version lts)"
|
2020-12-21 10:50:54 +01:00
|
|
|
assert_equal "$output" "v${LTS_VERSION}"
|
2019-08-04 06:33:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "n use 4" {
|
2020-12-20 04:42:27 +01:00
|
|
|
output="$(n use 4 --version)"
|
2020-12-21 10:50:54 +01:00
|
|
|
assert_equal "$output" "v4.9.1"
|
2019-08-04 06:33:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "n as 4" {
|
2020-12-20 04:42:27 +01:00
|
|
|
output="$(n as 4 --version)"
|
2020-12-21 10:50:54 +01:00
|
|
|
assert_equal "$output" "v4.9.1"
|
2019-08-04 06:33:45 +02:00
|
|
|
}
|
|
|
|
|
2021-09-10 11:19:07 +02:00
|
|
|
@test "n run --download latest" {
|
|
|
|
n rm latest || true
|
|
|
|
n run --download latest --version
|
|
|
|
output="$(n run latest --version)"
|
|
|
|
local LATEST_VERSION="$(display_remote_version latest)"
|
|
|
|
assert_equal "$output" "v${LATEST_VERSION}"
|
|
|
|
}
|
2019-08-04 06:33:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
# n exec
|
|
|
|
|
|
|
|
@test "n exec v4.9.1 node" {
|
2020-12-20 04:42:27 +01:00
|
|
|
output="$(n exec v4.9.1 node --version)"
|
2020-12-21 10:50:54 +01:00
|
|
|
assert_equal "$output" "v4.9.1"
|
2019-08-04 06:33:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "n exec 4 npm" {
|
2020-12-20 04:42:27 +01:00
|
|
|
output="$(n exec 4 npm --version)"
|
2020-12-21 10:50:54 +01:00
|
|
|
assert_equal "$output" "2.15.11"
|
2019-08-04 06:33:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "n exec lts" {
|
2020-12-20 04:42:27 +01:00
|
|
|
output="$(n exec lts node --version)"
|
2019-08-04 06:33:45 +02:00
|
|
|
local LTS_VERSION="$(display_remote_version lts)"
|
2020-12-21 10:50:54 +01:00
|
|
|
assert_equal "$output" "v${LTS_VERSION}"
|
2019-08-04 06:33:45 +02:00
|
|
|
}
|
2021-09-10 11:19:07 +02:00
|
|
|
|
|
|
|
@test "n exec -d latest" {
|
|
|
|
n rm latest || true
|
|
|
|
n exec -d latest node --version
|
|
|
|
output="$(n exec latest node --version)"
|
|
|
|
local LATEST_VERSION="$(display_remote_version latest)"
|
|
|
|
assert_equal "$output" "v${LATEST_VERSION}"
|
|
|
|
}
|