Skip to content

Commit 1976277

Browse files
committed
Robust test env setup
The test environment needs an isolated NODENV_ROOT, an unaltered NODENV_VERSION, nodenv to be in PATH (from npm), for the plugin under test to be in PATH, and for the plugin under test's hooks to be in NODENV_HOOK_PATH. An alternative would be to just symlink the plugin under test into a dummy NODENV_ROOT/plugins. However, that's much slower than just setting the env vars. Further, the explicit variables more clearly document what's necessary for a plugin integration.
1 parent df0ceb9 commit 1976277

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

test/nodenv-package-json-engine.bats

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ load test_helper
8686
}
8787

8888
@test 'Does not match babel preset env settings' {
89+
create_version 4.2.1
8990
cd_into_babel_env_package
9091
run nodenv version-name
9192
assert_success 'system'

test/test_helper.bash

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@
33
load ../node_modules/bats-assert/all
44

55
setup() {
6+
# common nodenv setup
67
unset NODENV_VERSION
78

8-
EXAMPLE_PACKAGE_DIR="$BATS_TMPDIR/example_package"
9+
local node_modules_bin=$BATS_TEST_DIRNAME/../node_modules/.bin
10+
local plugin_bin=$BATS_TEST_DIRNAME/../bin
11+
12+
export PATH="$plugin_bin:$node_modules_bin:/usr/bin:/bin:/usr/sbin:/sbin"
913

1014
export NODENV_ROOT="$BATS_TMPDIR/nodenv_root"
15+
export NODENV_HOOK_PATH="$BATS_TEST_DIRNAME/../etc/nodenv.d"
1116

12-
PATH="$(npm bin):/usr/bin:/bin:/usr/sbin:/sbin"
13-
PATH="${BATS_TEST_DIRNAME}/../bin:$PATH"
14-
export PATH
17+
# unique
1518

16-
eval "$(nodenv init -)"
19+
EXAMPLE_PACKAGE_DIR="$BATS_TMPDIR/example_package"
1720
}
1821

1922
teardown() {

0 commit comments

Comments
 (0)