0
0
mirror of https://github.com/tj/n.git synced 2024-11-28 21:22:03 +01:00
n/test/tests/run-which.bats
John Gee 59adcab8b4
Add auto label to read version from .node-version (#616)
* Add support for auto, reading version from .node-version

* Make version unique in tests

* Add support for auto doing a lookup for unresolved version

* Make auto description more consistent in style with other labels.
2020-04-11 14:10:29 +12:00

125 lines
2.2 KiB
Bash

#!/usr/bin/env bats
load shared-functions
function setup() {
unset_n_env
# fixed directory so can reuse the two installs
tmpdir="${TMPDIR:-/tmp}"
export N_PREFIX="${tmpdir}/n/test/run-which"
# beforeAll
# See https://github.com/bats-core/bats-core/issues/39
if [[ "${BATS_TEST_NUMBER}" -eq 1 ]] ; then
n --download 4.9.1
n --download lts
fi
}
function teardown() {
# afterAll
if [[ "${#BATS_TEST_NAMES[@]}" -eq "${BATS_TEST_NUMBER}" ]] ; then
rm -rf "${N_PREFIX}"
fi
}
@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" {
run n which 4
[ "$status" -eq 0 ]
[ "$output" = "${N_PREFIX}/n/versions/node/4.9.1/bin/node" ]
}
@test "n which v4.9.1" {
run n which v4.9.1
[ "$status" -eq 0 ]
[ "$output" = "${N_PREFIX}/n/versions/node/4.9.1/bin/node" ]
}
@test "n bin v4.9.1" {
run n bin v4.9.1
[ "$status" -eq 0 ]
[ "$output" = "${N_PREFIX}/n/versions/node/4.9.1/bin/node" ]
}
@test "n which argon" {
run n which argon
[ "$status" -eq 0 ]
[ "$output" = "${N_PREFIX}/n/versions/node/4.9.1/bin/node" ]
}
@test "n which lts" {
run n which lts
local LTS_VERSION="$(display_remote_version lts)"
[ "$status" -eq 0 ]
[ "$output" = "${N_PREFIX}/n/versions/node/${LTS_VERSION}/bin/node" ]
}
# n run
@test "n run 4" {
run n run 4 --version
[ "$status" -eq 0 ]
[ "$output" = "v4.9.1" ]
}
@test "n run lts" {
run n run lts --version
local LTS_VERSION="$(display_remote_version lts)"
[ "$status" -eq 0 ]
[ "$output" = "v${LTS_VERSION}" ]
}
@test "n use 4" {
run n use 4 --version
[ "$status" -eq 0 ]
[ "$output" = "v4.9.1" ]
}
@test "n as 4" {
run n as 4 --version
[ "$status" -eq 0 ]
[ "$output" = "v4.9.1" ]
}
# n exec
@test "n exec v4.9.1 node" {
run n exec v4.9.1 node --version
[ "$status" -eq 0 ]
[ "$output" = "v4.9.1" ]
}
@test "n exec 4 npm" {
run n exec 4 npm --version
[ "$status" -eq 0 ]
[ "$output" = "2.15.11" ]
}
@test "n exec lts" {
run n exec lts node --version
local LTS_VERSION="$(display_remote_version lts)"
[ "$status" -eq 0 ]
[ "$output" = "v${LTS_VERSION}" ]
}