You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.2 KiB
87 lines
2.2 KiB
#!/bin/sh |
|
puts() (IFS=" "; printf %s\\n "$*" ;) |
|
|
|
cleanup () { |
|
rm -rf "$npm_config_prefix/lib" >/dev/null 2>&1 |
|
unset npm_config_prefix |
|
|
|
rm -f npm |
|
PATH="$ORIGINAL_PATH" |
|
|
|
unset -f setup cleanup die |
|
unset message ORIGINAL_PATH |
|
} |
|
|
|
die () { puts "!! $@" ; cleanup ; exit 1; } |
|
|
|
NVM_ENV=testing . ../../install.sh |
|
|
|
setup () { |
|
ORIGINAL_PATH="$PATH" |
|
|
|
npm_config_prefix="$(pwd)" |
|
export npm_config_prefix |
|
mkdir -p "$npm_config_prefix/lib" |
|
} |
|
|
|
setup |
|
|
|
|
|
npm install -g nop >/dev/null || die 'nvm_check_global_modules cannot be tested because `npm` cannot install the `nop` package' |
|
message=$(nvm_check_global_modules) |
|
[ ! -z "$message" ] || { |
|
puts '-- `npm --version`: '"$(npm --version)" |
|
puts '-- `npm list -g`:' |
|
npm list -g --depth=0 |
|
puts '-- Printed message:' |
|
puts "'''$message'''" |
|
|
|
die "nvm_check_global_modules should have printed a notice when npm had global modules installed" ;} |
|
|
|
|
|
npm uninstall -g nop >/dev/null |
|
message=$(nvm_check_global_modules) |
|
[ -z "$message" ] || { |
|
puts '-- `npm --version`: '"$(npm --version)" |
|
puts '-- `npm list -g`:' |
|
npm list -g --depth=0 |
|
puts '-- Printed message:' |
|
puts "'''$message'''" |
|
|
|
die "nvm_check_global_modules should not have printed a notice when npm had no global modules installed" ;} |
|
|
|
|
|
# Faking an installation of npm |
|
mkdir -p "$npm_config_prefix/lib/node_modules/npm" |
|
cat <<'JSON' >"$npm_config_prefix/lib/node_modules/npm/package.json" |
|
{ "name": "npm", "version": "0.0.1fake" } |
|
JSON |
|
|
|
message=$(nvm_check_global_modules) |
|
[ -z "$message" ] || { |
|
puts '-- `which npm`: ' "$(which npm)" |
|
puts '-- `npm --version`: ' "$(npm --version)" |
|
puts '-- `npm list -g`:' |
|
npm list -g --depth=0 |
|
puts '-- Printed message:' |
|
puts "'''$message'''" |
|
|
|
die "nvm_check_global_modules should not have printed a notice when npm had only itself installed as a global module" ;} |
|
|
|
|
|
# Faking the absence of npm |
|
PATH=".:$PATH" |
|
touch npm |
|
chmod +x npm |
|
|
|
message=$(nvm_check_global_modules) |
|
[ -z "$message" ] || { |
|
puts '-- `which npm`: ' "$(which npm)" |
|
puts '-- `npm --version`: ' "$(npm --version)" |
|
puts '-- Printed message:' |
|
puts "'''$message'''" |
|
|
|
die "nvm_check_global_modules should not have printed a notice when npm was unavailable" ;} |
|
|
|
|
|
cleanup
|
|
|