Skip to content
Myr

nvm_check_global_modules

This file

Path

test/install_script/nvm_check_global_modules

65 lines · 2.0 KiB

Last changed by

Not known.

History of this file

Take it

1#!/bin/sh23cleanup () {4  rm -rf "$npm_config_prefix/lib" >/dev/null 2>&15  unset npm_config_prefix67  rm -f npm8  PATH="$ORIGINAL_PATH"9  NVM_DIR="$ORIGINAL_NVM_DIR"1011  unset -f setup cleanup die12  unset message ORIGINAL_PATH ORIGINAL_NVM_DIR13}14die () { echo "$@" ; cleanup ; exit 1; }1516NVM_ENV=testing \. ../../install.sh1718setup () {19  ORIGINAL_PATH="$PATH"20  ORIGINAL_NVM_DIR="$NVM_DIR"2122  # Pretend we're not using NVM23  unset NVM_DIR2425  npm_config_prefix="$(pwd)"26  export npm_config_prefix27  mkdir -p "$npm_config_prefix/lib"28}2930setup3132npm install -g nop >/dev/null || die 'nvm_check_global_modules cannot be tested because `npm` cannot install the `nop` package'33message=$(nvm_check_global_modules)34[ ! -z "$message" ] || die "nvm_check_global_modules should have printed a notice when npm had global modules installed; got:\n${message}"3536if [ -n "${ORIGINAL_NVM_DIR}" ] && [ -z "${GITHUB_ACTIONS}" ]; then37  # Admit we're using NVM, just for this one test38  # TODO: fix this for GHA39  message=$(NVM_DIR="${ORIGINAL_NVM_DIR}" nvm_check_global_modules)40  [ -z "$message" ] || die "nvm_check_global_modules should not have printed a notice when npm is managed by nvm; got:\n${message}"41fi4243npm uninstall -g nop >/dev/null44message=$(nvm_check_global_modules)45[ -z "$message" ] || die "nvm_check_global_modules should not have printed a notice when npm had no global modules installed; got:\n${message}"4647# Faking an installation of npm48mkdir -p "$npm_config_prefix/lib/node_modules/npm"49cat <<'JSON' >"$npm_config_prefix/lib/node_modules/npm/package.json"50{ "name": "npm", "version": "0.0.1fake" }51JSON5253message=$(nvm_check_global_modules)54[ -z "$message" ] || die "nvm_check_global_modules should have not printed a notice when npm had only itself installed as a global module; got:\n${message}"5556# Faking the absence of npm57PATH=".:$PATH"58touch npm59chmod +x npm6061message=$(nvm_check_global_modules)62[ -z "$message" ] || die "nvm_check_global_modules should have not printed a notice when npm was unavailable; got:\n${message}"636465cleanup