Tests for NVM_PREFER_LOCAL_BINS

This commit is contained in:
Ian MacLeod 2017-09-04 11:58:01 -07:00
parent e8e5f89098
commit a04d4e5e80
No known key found for this signature in database
GPG Key ID: 4181ED3804601ED6

View File

@ -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"