Skip to content

Commit

Permalink
[Tests] improve debug output on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Dec 28, 2022
1 parent ce35311 commit dc69112
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions test/install_script/nvm_check_global_modules
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@ 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" ] || die "nvm_check_global_modules should have printed a notice when npm had global modules installed"
[ ! -z "$message" ] || die "nvm_check_global_modules should have printed a notice when npm had global modules installed; got:\n${message}"

# Admit we're using NVM, just for this one test
message=$(NVM_DIR=$ORIGINAL_NVM_DIR nvm_check_global_modules)
[ -z "$message" ] || die "nvm_check_global_modules should not have printed a notice when npm is managed by nvm"
if [ -n "${ORIGINAL_NVM_DIR}" ]; then
# Admit we're using NVM, just for this one test
message=$(NVM_DIR="${ORIGINAL_NVM_DIR}" nvm_check_global_modules)
[ -z "$message" ] || die "nvm_check_global_modules should not have printed a notice when npm is managed by nvm; got:\n${message}"
fi

npm uninstall -g nop >/dev/null
message=$(nvm_check_global_modules)
[ -z "$message" ] || die "nvm_check_global_modules should not have printed a notice when npm had no global modules installed"
[ -z "$message" ] || die "nvm_check_global_modules should not have printed a notice when npm had no global modules installed; got:\n${message}"

# Faking an installation of npm
mkdir -p "$npm_config_prefix/lib/node_modules/npm"
Expand All @@ -49,15 +51,15 @@ cat <<'JSON' >"$npm_config_prefix/lib/node_modules/npm/package.json"
JSON

message=$(nvm_check_global_modules)
[ -z "$message" ] || die "nvm_check_global_modules should have not printed a notice when npm had only itself installed as a global module"
[ -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}"

# Faking the absence of npm
PATH=".:$PATH"
touch npm
chmod +x npm

message=$(nvm_check_global_modules)
[ -z "$message" ] || die "nvm_check_global_modules should have not printed a notice when npm was unavailable"
[ -z "$message" ] || die "nvm_check_global_modules should have not printed a notice when npm was unavailable; got:\n${message}"


cleanup

0 comments on commit dc69112

Please sign in to comment.