Skip to content

Commit a801cd0

Browse files
committed
Use fixture for nodenv root
We can have a single node version fixture. And have the tests ship with a nodenv_root fixture. This allows us to have the plugin under test be symlinked into our root fixture, which requires less setup (no more env var munging) and is faster than creating the test root from scratch. Also with this root fixture, we can just symlink the single node fixture into nodenv root's versions directory, to simulate any number of installed nodes. The only additional work, is that we now have to clean up the versions directory and the global version, since the root fixture now persists between tests.
1 parent 8beca12 commit a801cd0

File tree

4 files changed

+18
-23
lines changed

4 files changed

+18
-23
lines changed

test/fixtures/node-x.y.z/bin/node

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../..

test/nodenv-package-json-engine.bats

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
load test_helper
44

55
@test 'Recognizes simple node version specified in package.json engines' {
6-
create_version 4.2.1
6+
with_installed_node_versions 4.2.1
77
cd_into_package 4.2.1
88

99
run nodenv version
@@ -13,24 +13,23 @@ load test_helper
1313
}
1414

1515
@test 'Recognizes a semver range matching an installed version' {
16-
create_version 4.2.1
16+
with_installed_node_versions 4.2.1
1717
cd_into_package '>= 4.0.0'
1818

1919
run nodenv version
2020
assert_success '4.2.1 (set by package-json-engine matching >= 4.0.0)'
2121
}
2222

2323
@test 'Prefers the greatest installed version matching a range' {
24-
create_version 4.0.0
25-
create_version 4.2.1
24+
with_installed_node_versions 4.0.0 4.2.1
2625
cd_into_package '^4.0.0'
2726

2827
run nodenv version
2928
assert_success '4.2.1 (set by package-json-engine matching ^4.0.0)'
3029
}
3130

3231
@test 'Ignores non-matching installed versions' {
33-
create_version 0.12.7
32+
with_installed_node_versions 0.12.7
3433
cd_into_package '>= 4.0.0'
3534

3635
# For unknown reasons, nodenv-version succeeds when version-name fails,
@@ -46,8 +45,7 @@ load test_helper
4645
}
4746

4847
@test 'Prefers nodenv-local over package.json' {
49-
create_version 4.2.1
50-
create_version 5.0.0
48+
with_installed_node_versions 4.2.1 5.0.0
5149
cd_into_package 4.2.1
5250
nodenv local 5.0.0
5351

@@ -56,7 +54,7 @@ load test_helper
5654
}
5755

5856
@test 'Prefers nodenv-shell over package.json' {
59-
create_version 5.0.0
57+
with_installed_node_versions 5.0.0
6058
cd_into_package 4.2.1
6159
eval "$(nodenv sh-shell 5.0.0)"
6260

@@ -65,8 +63,7 @@ load test_helper
6563
}
6664

6765
@test 'Prefers package.json over nodenv-global' {
68-
create_version 4.2.1
69-
create_version 5.0.0
66+
with_installed_node_versions 4.2.1 5.0.0
7067
cd_into_package 4.2.1
7168
nodenv global 5.0.0
7269

@@ -75,8 +72,7 @@ load test_helper
7572
}
7673

7774
@test 'Is not confused by nodenv-shell shadowing nodenv-global' {
78-
create_version 4.2.1
79-
create_version 5.0.0
75+
with_installed_node_versions 4.2.1 5.0.0
8076
cd_into_package 4.2.1
8177
nodenv global 5.0.0
8278
eval "$(nodenv sh-shell 5.0.0)"
@@ -86,7 +82,7 @@ load test_helper
8682
}
8783

8884
@test 'Does not match babel preset env settings' {
89-
create_version 4.2.1
85+
with_installed_node_versions 4.2.1
9086
cd_into_babel_env_package
9187
run nodenv version-name
9288
assert_success 'system'

test/test_helper.bash

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ setup() {
77
unset NODENV_VERSION
88

99
local node_modules_bin=$BATS_TEST_DIRNAME/../node_modules/.bin
10-
local plugin_bin=$BATS_TEST_DIRNAME/../bin
1110

12-
export PATH="$plugin_bin:$node_modules_bin:/usr/bin:/bin:/usr/sbin:/sbin"
11+
export PATH="$node_modules_bin:/usr/bin:/bin:/usr/sbin:/sbin"
1312

14-
export NODENV_ROOT="$BATS_TMPDIR/nodenv_root"
15-
export NODENV_HOOK_PATH="$BATS_TEST_DIRNAME/../etc/nodenv.d"
13+
export NODENV_ROOT="$BATS_TEST_DIRNAME/fixtures/nodenv_root"
1614

1715
# unique
1816

@@ -21,7 +19,8 @@ setup() {
2119

2220
teardown() {
2321
rm -r "$EXAMPLE_PACKAGE_DIR"
24-
rm -r "$NODENV_ROOT"
22+
rm "$NODENV_ROOT"/versions/*
23+
rm -f "$NODENV_ROOT/version"
2524
}
2625

2726
# cd_into_package nodeVersion [extraArgs]
@@ -54,9 +53,8 @@ cd_into_babel_env_package() {
5453
JSON
5554
}
5655

57-
# Creates fake version directory
58-
create_version() {
59-
d="$NODENV_ROOT/versions/$1/bin"
60-
mkdir -p "$d"
61-
ln -s /bin/echo "$d/node"
56+
with_installed_node_versions() {
57+
for v in "$@"; do
58+
ln -fhs $BATS_TEST_DIRNAME/fixtures/node-x.y.z/ $NODENV_ROOT/versions/$v
59+
done
6260
}

0 commit comments

Comments
 (0)