From a04d4e5e8055c3bd0b775c63eb8076ba5f58929b Mon Sep 17 00:00:00 2001 From: Ian MacLeod Date: Mon, 4 Sep 2017 11:58:01 -0700 Subject: [PATCH] Tests for NVM_PREFER_LOCAL_BINS --- tests/options/NVM_PREFER_LOCAL_BINS | 41 +++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 tests/options/NVM_PREFER_LOCAL_BINS diff --git a/tests/options/NVM_PREFER_LOCAL_BINS b/tests/options/NVM_PREFER_LOCAL_BINS new file mode 100755 index 0000000..4718fc6 --- /dev/null +++ b/tests/options/NVM_PREFER_LOCAL_BINS @@ -0,0 +1,41 @@ +#!/bin/sh +source ../common.sh + +# Setup projects in tmp, so we don't have ancestor paths of this repo messing +# with things. +cd $(mktemp -d) +# npm bin can resolve to a different path (/private/var instead of /var) on some +# platforms. It also resolves to the current directory if there is no +# package.json up the current path. So, we use it to expand our path. +sandbox=$(dirname $(dirname $(npm bin))) +echo "Running NVM_PREFER_LOCAL_BINS in $sandbox\n" + +mkdir -p package/src/a/b +touch package/package.json +mkdir -p package/vendor +touch package/vendor/package.json + +# Load it. +export NVM_PREFER_LOCAL_BINS=true +load_zsh_nvm +# This is our base path, without any local binary paths in it. +base_path=$PATH + +# Check cd directly into a package directory +cd ./package +[[ "$PATH" == "$sandbox/package/node_modules/.bin:$base_path" ]] || die "Didn't prepend local bin dir to path when moving into package directory" + +# Check package subdirs +cd ./src +cd ./a +cd ./b +[[ "$PATH" == "$sandbox/package/node_modules/.bin:$base_path" ]] || die "Didn't prepend local bin dir to path when moving into package subdirectories" + +# Check nested packages +cd ../../.. +cd ./vendor +[[ "$PATH" == "$sandbox/package/vendor/node_modules/.bin:$base_path" ]] || die "Didn't prepend local bin dir to path when moving into a nested package" + +# Check leaving +cd ../.. +[[ "$PATH" == "$base_path" ]] || die "Didn't remove local bin dir when leaving a package directory"