Skip to content
Myr

[Fix] `nvm-exec`: improve the no-version failure message

Before adoption: this commit came in with the history the project adopted, so no landing records it.

The message claimed "no .nvmrc file found" even when one was found and its version simply was not installed, and it never mentioned that `NODE_VERSION=default` selects the `default` alias. Refs #3810

authored by Jordan Harband · committed by Jordan Harband · parent cd84623 · Browse files · 2 files+36 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+36 added−3 removed

  • tests:+33 added−2 removed
  • other:+3 added−1 removed

2 files+36 added−3 removed

modified:test/fast/Running 'nvm-exec' should display required node version+33 added-2 removed
1#!/bin/bash23set -x4export NVM_DIR="$(cd ../.. && pwd)"56# an ambient value would send nvm-exec down its `NODE_VERSION` branch7unset NODE_VERSION89: nvm.sh10\. ../../nvm.sh117cleanup() { rm -f .nvmrc; }12ORIG_PWD="$(pwd)"1314cleanup() {15 cd "${ORIG_PWD}" 2>/dev/null || true16 rm -f .nvmrc17 [ -n "${TMP_DIR-}" ] && rm -rf "${TMP_DIR}"18}19die () { echo "$@" ; cleanup ; exit 1; }2021NVM_TEST_VERSION=v0.422223HINT="nvm-exec: unable to select a node version24 Set \`NODE_VERSION\` (e.g. \`NODE_VERSION=default\`), or add an \`.nvmrc\` file."2526# Write it to nvmrc27echo "$NVM_TEST_VERSION" > .nvmrc2829OUTPUT="$(../../nvm-exec 2>&1)";30EXPECTED="Found '$(pwd)/.nvmrc' with version <${NVM_TEST_VERSION}>31N/A: version \"${NVM_TEST_VERSION}\" is not yet installed.3233You need to run \`nvm install ${NVM_TEST_VERSION}\` to install and use it.20No NODE_VERSION provided; no .nvmrc file found";34${HINT}";3536# Skip install, we want to test the error message37[ "${EXPECTED}" = "${OUTPUT}" ] || die "expected >${EXPECTED}<, got >${OUTPUT}<"3839rm -f .nvmrc4041NVM_EXEC="$(cd ../.. && pwd)/nvm-exec"4243# Run from a fresh, empty directory so no ambient .nvmrc above the test dir44# can satisfy the lookup and mask the hint.45TMP_DIR="$(mktemp -d)"46cd "${TMP_DIR}" || die "could not cd to temp dir"4748OUTPUT="$("${NVM_EXEC}" node </dev/null 2>&1)";49EXIT_CODE=$?50EXPECTED="No version provided and no .nvmrc file found51${HINT}";5253[ "${EXPECTED}" = "${OUTPUT}" ] || die "expected >${EXPECTED}<, got >${OUTPUT}<"54[ "${EXIT_CODE}" = 127 ] || die "expected exit code 127, got >${EXIT_CODE}<"5556cleanup
modified:nvm-exec+3 added-1 removed
10 unmodified lines
11 nvm use "$NODE_VERSION" > /dev/null || exit 12712else13 { NVM_RC_VERSION="$(nvm_rc_version 3>&1 1>&4)"; } 4>&1 && nvm_ensure_version_installed "$NVM_RC_VERSION";14 if ! nvm use >/dev/null 2>&1; then15 echo "No NODE_VERSION provided; no .nvmrc file found" >&215 nvm_err 'nvm-exec: unable to select a node version'16 # shellcheck disable=SC201617 nvm_err ' Set `NODE_VERSION` (e.g. `NODE_VERSION=default`), or add an `.nvmrc` file.'18 exit 12719 fi20fi21
1 unmodified line