[Tests] run every remaining test file: exec bits, fixes; add `check-exec` to CI
Before adoption: this commit came in with the history the project adopted, so no landing records it.
urchin only executes test files that have the executable bit, silently skipping the rest, and `npm run test:check-exec` would catch non-executable ones, but no workflow ran it - so several test files have never actually run. Make all of them executable, and fix the ones that were broken: - the io.js source-install tests, skipped since 2016: io.js requires python 2 and gcc <= 5, so they now skip on toolchains that can not compile it, and a new gcc:4.9-container CI job runs them unmodified - resolving, downloading, checksumming, and compiling io.js for real. New `fake source` variants exercise nvm's source pipeline everywhere - cache lookup, offline resolution, extraction, configure, make, make install, activation - via a tiny fake source tree seeded into the download cache and installed with `--offline`. Also strengthen the `nvm run | grep` assertions with `--silent`, since the version banner used to satisfy the grep even when the built binary could not run, and give the final assertions the `die` they always meant to call. - `nvm uninstall ... incorrect file permissions fails nicely`, parked in 2025 as failing: `sudo npm` resets PATH, so node 5's npm crashed under the system node. The permissions check only trips on files that are neither writable nor self-owned, and that precondition only needs `sudo touch` - not npm, jspm, or the network - so use that, against a fake installed version, and skip only where passwordless sudo does not exist. - `nvm install --offline`: `nvm ls | tail -1` always grabbed an alias line, never a version; use `nvm_ls` and skip its trailing `system <version>` line. - `nvm exec ... help should not parse`: in a BRE, `[options]` is a bracket expression, so the grep could never match node's literal `Usage: node [options]` output. - `nvm use ... nvmrc containing not installed version`: current output once again matches its expectations verbatim; no changes needed. Rewrite `test:check-exec` in POSIX sh - npm runs scripts with /bin/sh, which is dash on Ubuntu, where the previous `[[`/`$'\n'` bashisms would break; match by extension, so that filenames containing dots can not dodge the check; and disable git's `core.quotePath` mangling of the non-ASCII test filenames. Then wire it into the lint workflow.
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
14 files+266 added−26 removed
- tests:+211 added−23 removed
- other:+55 added−3 removed
Provenance
- Commit
c7d5d77- Tree
c7b37ed- Author
Jordan Harband <ljharb@gmail.com>- Committer
Jordan Harband <ljharb@gmail.com>- Parent
4e48294
14 files changed+266 added−26 removed
modified:.github/workflows/lint.yml+19 added-1 removed
69 unmodified lines7071727374757677787980818283848586878889909192939495789697989969 unmodified lines - uses: actions/checkout@v6 - name: check tests filenames run: ./rename_test.sh --check
check_exec: runs-on: ubuntu-latest steps: - uses: step-security/harden-runner@v2 with: allowed-endpoints: github.com:443 raw.githubusercontent.com:443 nodejs.org:443 registry.npmjs.org:443 - uses: actions/checkout@v6 - uses: ljharb/actions/node/install@main name: 'nvm install lts/* && npm install' with: node-version: 'lts/*' - name: check that test files are executable run: npm run test:check-exec
all: permissions: contents: none name: 'all linting' needs: [eclint, dockerfile_lint, doctoc, test_naming] needs: [eclint, dockerfile_lint, doctoc, test_naming, check_exec] runs-on: ubuntu-latest steps: - run: truemodified:.github/workflows/tests-installation-iojs.yml+35 added-1 removed
96 unmodified lines97 if: always()98 run: sudo apt-get install curl -y99 shell: bash100 101+ installation_iojs_source_compile:102+ permissions:103+ contents: read104+105+ name: 'actually compile io.js from source (gcc 4.9 container)'106+ runs-on: ubuntu-latest107+ timeout-minutes: 60108+109+ steps:110+ - name: Harden Runner111+ uses: step-security/harden-runner@v2112+ with:113+ allowed-endpoints:114+ github.com:443115+ mirror.gcr.io:443116+ storage.googleapis.com:443117+ iojs.org:443118+ - uses: actions/checkout@v6119+ # io.js requires python 2 and gcc <= 5 to compile; the gcc:4.9 image120+ # (debian jessie) has both, plus curl/wget/xz and CA certificates that121+ # still validate iojs.org - so the source-install tests run unmodified,122+ # resolving, downloading, checksumming, and compiling for real.123+ # The image is pulled through Google's Docker Hub mirror: it serves124+ # manifests and blobs from a single stable hostname (Docker Hub's blob125+ # CDN hostnames rotate, which the blocked-egress policy can not allow),126+ # and it is not subject to Docker Hub's anonymous pull rate limits.127+ - name: compile io.js from source, for real128+ run: |129+ docker run --rm -v "${PWD}:/nvm-under-test" -e NVM_DIR=/nvm-under-test mirror.gcr.io/library/gcc:4.9 bash -ec '130+ cd "${NVM_DIR}/test/installation_iojs"131+ sh "./install from source"132+ sh "./install version specified in .nvmrc from source"133+ '134+135 all:136 permissions:137 contents: none138 name: 'all installation_iojs tests'105- needs: [installation_iojs_without_curl]139+ needs: [installation_iojs_without_curl, installation_iojs_source_compile]140 runs-on: ubuntu-latest141 steps:142 - run: truemodified:test/fast/Unit tests/nvm install --offline+4 added-2 removed
10 unmodified lines11 die "nvm_download should not be called in offline mode"12 }13 14 # --offline with an already-installed version should succeed15-INSTALLED_VERSION="$(nvm ls | command tail -1 | command awk '{print $1}' | command sed 's/\x1b\[[0-9;]*m//g')"16-if [ -n "${INSTALLED_VERSION}" ] && [ "_${INSTALLED_VERSION}" != '_N/A' ] && [ "_${INSTALLED_VERSION}" != '_system' ]; then15+# (`nvm ls` ends with the alias listing, so use `nvm_ls`, which emits bare16+# versions, and skip its trailing `system <version>` line)17+INSTALLED_VERSION="$(nvm_ls | command grep -v '^system' | command tail -n1)"18+if [ -n "${INSTALLED_VERSION}" ] && [ "_${INSTALLED_VERSION}" != '_N/A' ]; then19 try nvm install --offline "${INSTALLED_VERSION}"20 [ "_$CAPTURED_EXIT_CODE" = "_0" ] \21 || die "nvm install --offline with installed version '${INSTALLED_VERSION}' should succeed, got exit code $CAPTURED_EXIT_CODE"22 fi19 unmodified linesadded:test/fixtures/fake-source-tarball/configure+22 added
1+#!/bin/sh2+3+# a fake node/io.js `configure`, for source-install tests: real io.js (and4+# old node) can no longer be compiled on modern toolchains (python 25+# `configure`, ancient V8), so source-install tests exercise nvm's entire6+# source pipeline against this tiny stand-in instead.7+8+PREFIX=''9+while [ $# -gt 0 ]; do10+ case "${1}" in11+ --prefix=*) PREFIX="${1#--prefix=}" ;;12+ esac13+ shift14+done15+16+if [ -z "${PREFIX}" ]; then17+ echo 'configure: a --prefix is required' >&218+ exit 119+fi20+21+printf 'PREFIX = %s\n' "${PREFIX}" > config.mk22+echo "configured with PREFIX=${PREFIX}"added:test/fixtures/fake-source-tarball/Makefile+15 added
1+include config.mk2+3+all: out/fake-bin4+5+out/fake-bin: VERSION6+ mkdir -p out7+ printf '#!/bin/sh\necho %s\n' "$$(cat VERSION)" > out/fake-bin8+ chmod +x out/fake-bin9+10+install: all11+ mkdir -p "$(PREFIX)/bin"12+ cp out/fake-bin "$(PREFIX)/bin/node"13+ cp out/fake-bin "$(PREFIX)/bin/iojs"14+15+.PHONY: all installadded:test/installation_iojs/install from fake source+44 added
1+#!/bin/sh2+3+\. ../common.sh4+5+die () { echo "$@" ; exit 1; }6+7+\. ../../nvm.sh8+9+set -ex10+11+NVM_TEST_VERSION='v3.99.9'12+NVM_PREFIXED_TEST_VERSION="iojs-${NVM_TEST_VERSION}"13+14+# Remove the stuff we're clobbering.15+nvm uninstall "${NVM_TEST_VERSION}" || echo 'not installed'16+17+# Exercise nvm's entire source-install pipeline - cache, extract, configure,18+# make, make install, activation - against a tiny fake source tree, seeded19+# into the download cache and installed with --offline. This runs everywhere,20+# including on toolchains where real io.js can not compile; `install from21+# source` covers the real compile, in CI's gcc:4.9 container job.22+SLUG="$(nvm_get_download_slug iojs source "${NVM_TEST_VERSION}")"23+COMPRESSION="$(nvm_get_artifact_compression "${NVM_TEST_VERSION}")"24+CACHE_DIR="$(nvm_cache_dir)/src/${SLUG}"25+STAGING="$(mktemp -d)"26+mkdir -p "${STAGING}/${SLUG}" "${CACHE_DIR}"27+cp ../fixtures/fake-source-tarball/configure ../fixtures/fake-source-tarball/Makefile "${STAGING}/${SLUG}/"28+chmod +x "${STAGING}/${SLUG}/configure"29+echo "${NVM_TEST_VERSION}" > "${STAGING}/${SLUG}/VERSION"30+if [ "${COMPRESSION}" = 'tar.xz' ]; then31+ (cd "${STAGING}" && tar -cJf "${CACHE_DIR}/${SLUG}.${COMPRESSION}" "${SLUG}")32+else33+ (cd "${STAGING}" && tar -czf "${CACHE_DIR}/${SLUG}.${COMPRESSION}" "${SLUG}")34+fi35+rm -rf "${STAGING}"36+37+# Install from source38+nvm install -s --offline "${NVM_PREFIXED_TEST_VERSION}" || die "'nvm install -s --offline ${NVM_PREFIXED_TEST_VERSION}' failed"39+40+# Check41+nvm_is_version_installed "${NVM_PREFIXED_TEST_VERSION}" || die 'version not installed'42+nvm run --silent "${NVM_PREFIXED_TEST_VERSION}" --version | grep "${NVM_TEST_VERSION}" || die "'nvm run ${NVM_PREFIXED_TEST_VERSION} --version | grep ${NVM_TEST_VERSION}' failed"43+44+rm -rf "${CACHE_DIR}"modified:test/installation_iojs/install from source+18 added-1 removed
6 unmodified lines7 \. ../../nvm.sh8 9 set -ex10 11+# Compiling io.js requires a period toolchain: python 2 (its `configure`),12+# and gcc <= 5 (its bundled V8). CI compiles it for real in a gcc:4.913+# container job; on modern toolchains, this can only be skipped14+# (`install from fake source` covers nvm's source pipeline everywhere).15+GCC_MAJOR="$(gcc -dumpversion 2>/dev/null | command cut -d. -f1)"16+if ! command -v python2 >/dev/null 2>&1 && ! python -V 2>&1 | command grep -q '^Python 2'; then17+ echo 'python 2 is not available; skipping the io.js source install'18+ exit 019+fi20+case "${GCC_MAJOR}" in21+ '' | *[!0-9]*) echo 'gcc is not available; skipping the io.js source install'; exit 0 ;;22+esac23+if [ "${GCC_MAJOR}" -gt 5 ]; then24+ echo "gcc <= 5 is required to compile io.js, got ${GCC_MAJOR}; skipping the io.js source install"25+ exit 026+fi27+28 NVM_TEST_VERSION='v3.3.1'29 NVM_PREFIXED_TEST_VERSION="iojs-${NVM_TEST_VERSION}"30 31 # Remove the stuff we're clobbering.3 unmodified lines35 (watch nvm install -s "${NVM_PREFIXED_TEST_VERSION}") || die "'nvm install -s ${NVM_PREFIXED_TEST_VERSION}' failed"36 37 # Check38 nvm_is_version_installed "${NVM_PREFIXED_TEST_VERSION}" || die 'version not installed'22-nvm run "${NVM_PREFIXED_TEST_VERSION}" --version | grep "${NVM_TEST_VERSION}" || "'nvm run ${NVM_PREFIXED_TEST_VERSION} --version | grep ${NVM_TEST_VERSION}' failed"39+nvm run --silent "${NVM_PREFIXED_TEST_VERSION}" --version | grep "${NVM_TEST_VERSION}" || die "'nvm run ${NVM_PREFIXED_TEST_VERSION} --version | grep ${NVM_TEST_VERSION}' failed"added:test/installation_iojs/install version specified in .nvmrc from fake source+45 added
1+#!/bin/sh2+3+die () { echo "$@" ; exit 1; }4+5+\. ../../nvm.sh6+7+set -ex8+9+NVM_TEST_VERSION='v3.99.8'10+NVM_PREFIXED_TEST_VERSION="iojs-${NVM_TEST_VERSION}"11+12+# Remove the stuff we're clobbering.13+nvm uninstall "${NVM_TEST_VERSION}" || echo 'not installed'14+15+# Exercise nvm's source-install pipeline against a tiny fake source tree,16+# seeded into the download cache and installed with --offline (see `install17+# from fake source`). This runs everywhere, including on toolchains where18+# real io.js can not compile; `install version specified in .nvmrc from19+# source` covers the real compile, in CI's gcc:4.9 container job.20+SLUG="$(nvm_get_download_slug iojs source "${NVM_TEST_VERSION}")"21+COMPRESSION="$(nvm_get_artifact_compression "${NVM_TEST_VERSION}")"22+CACHE_DIR="$(nvm_cache_dir)/src/${SLUG}"23+STAGING="$(mktemp -d)"24+mkdir -p "${STAGING}/${SLUG}" "${CACHE_DIR}"25+cp ../fixtures/fake-source-tarball/configure ../fixtures/fake-source-tarball/Makefile "${STAGING}/${SLUG}/"26+chmod +x "${STAGING}/${SLUG}/configure"27+echo "${NVM_TEST_VERSION}" > "${STAGING}/${SLUG}/VERSION"28+if [ "${COMPRESSION}" = 'tar.xz' ]; then29+ (cd "${STAGING}" && tar -cJf "${CACHE_DIR}/${SLUG}.${COMPRESSION}" "${SLUG}")30+else31+ (cd "${STAGING}" && tar -czf "${CACHE_DIR}/${SLUG}.${COMPRESSION}" "${SLUG}")32+fi33+rm -rf "${STAGING}"34+35+# Install from source, with the version specified in .nvmrc36+echo "${NVM_PREFIXED_TEST_VERSION}" > .nvmrc37+38+nvm install -s --offline || die "'nvm install -s --offline' failed"39+40+# Check41+nvm_is_version_installed "${NVM_PREFIXED_TEST_VERSION}" || die 'version is not installed'42+nvm run --silent "${NVM_PREFIXED_TEST_VERSION}" --version | grep "${NVM_TEST_VERSION}" \43+ || die "'nvm run ${NVM_PREFIXED_TEST_VERSION} --version | grep ${NVM_TEST_VERSION}' failed"44+45+rm -rf "${CACHE_DIR}"modified:test/installation_iojs/install version specified in .nvmrc from source+21 added-3 removed
4 unmodified lines5 \. ../../nvm.sh6 7 set -ex8 9+# Compiling io.js requires a period toolchain: python 2 (its `configure`),10+# and gcc <= 5 (its bundled V8). CI compiles it for real in a gcc:4.911+# container job; on modern toolchains, this can only be skipped12+# (`install version specified in .nvmrc from fake source` covers nvm's13+# source pipeline everywhere).14+GCC_MAJOR="$(gcc -dumpversion 2>/dev/null | command cut -d. -f1)"15+if ! command -v python2 >/dev/null 2>&1 && ! python -V 2>&1 | command grep -q '^Python 2'; then16+ echo 'python 2 is not available; skipping the io.js source install'17+ exit 018+fi19+case "${GCC_MAJOR}" in20+ '' | *[!0-9]*) echo 'gcc is not available; skipping the io.js source install'; exit 0 ;;21+esac22+if [ "${GCC_MAJOR}" -gt 5 ]; then23+ echo "gcc <= 5 is required to compile io.js, got ${GCC_MAJOR}; skipping the io.js source install"24+ exit 025+fi26+27 NVM_TEST_VERSION='v3.3.0'28 NVM_PREFIXED_TEST_VERSION="iojs-${NVM_TEST_VERSION}"29 30 # Remove the stuff we're clobbering.31 nvm uninstall "${NVM_TEST_VERSION}" || echo 'not installed'32 15-# Install from binary33+# Install from source, with the version specified in .nvmrc34 echo "${NVM_PREFIXED_TEST_VERSION}" > .nvmrc35 18-nvm install -s || "'nvm install -s' failed"36+nvm install -s || die "'nvm install -s' failed"37 38 # Check39 nvm_is_version_installed "${NVM_PREFIXED_TEST_VERSION}" || die 'version is not installed'22-nvm run "${NVM_PREFIXED_TEST_VERSION}" --version | grep "${NVM_TEST_VERSION}" \40+nvm run --silent "${NVM_PREFIXED_TEST_VERSION}" --version | grep "${NVM_TEST_VERSION}" \41 || die "'nvm run ${NVM_PREFIXED_TEST_VERSION} --version | grep ${NVM_TEST_VERSION}' failed"modified:test/installation_iojs/teardown_dir+2 added
4 unmodified lines5 nvm uninstall iojs-v1.0.06 nvm uninstall iojs-v1.0.37 nvm uninstall iojs-v3.3.08 nvm uninstall iojs-v3.3.19+nvm uninstall iojs-v3.99.810+nvm uninstall iojs-v3.99.911 12 if [ -f ".nvmrc" ]; then13 rm .nvmrc14 fi4 unmodified linesmodified:test/slow/nvm exec/Running 'nvm exec' with help should not parse+3 added-1 removed
4 unmodified lines5 \. ../../../nvm.sh6 7 nvm use 0.108 9+# note: in a BRE, `[options]` is a bracket expression, so the literal `[options]`10+# in node's help output could never match; match the unbracketed prefix instead9-nvm exec stable -- node --help | grep 'Usage: node [options]' || die "Help menu should have been displayed for node and not nvm"11+nvm exec stable -- node --help | grep 'Usage: node' || die "Help menu should have been displayed for node and not nvm"modified:test/slow/nvm uninstall/Running 'nvm uninstall' with incorrect file permissions fails nicely+37 added-16 removed
1 #!/bin/sh2 3-die () { echo "$@" ; exit 1; }3+die () { echo "$@" ; cleanup ; exit 1; }4 5 # Source nvm6 \. ../../../nvm.sh7 8-# Version to install/uninstall9-NVM_TEST_VERSION=5.10.18+\. ../../common.sh9 11-# Make sure it's not already here12-[ -e ../../../$NVM_TEST_VERSION ] && rm -R ../../../$NVM_TEST_VERSION10+NVM_TEST_VERSION=v5.99.9911 14-# Install it15-nvm install $NVM_TEST_VERSION12+cleanup() {13+ VERSION_PATH="${VERSION_PATH-}"14+ if [ -n "${VERSION_PATH}" ] && [ -d "${VERSION_PATH}" ]; then15+ sudo -n rm -f "${VERSION_PATH}/lib/root-owned-file" 2>/dev/null16+ rm -rf "${VERSION_PATH}"17+ fi18+}19 17-# Make sure it installed18-nvm ls | grep "$NVM_TEST_VERSION" || die "Failed to install node"20+# The permissions check only trips on files that are neither writable nor21+# self-owned, and creating one requires another user: skip where passwordless22+# sudo is unavailable; CI always has it.23+if ! sudo -n true 2>/dev/null; then24+ echo 'passwordless sudo is not available, skipping'25+ exit 026+fi27 20-# Install global module as root21-npm_path=$(which npm)22-sudo -n "$npm_path" install jspm@'<2' -g || die 'either sudo failed, or `npm install jspm -g` failed`'28+# Install a fake version to uninstall29+make_fake_node "${NVM_TEST_VERSION}" || die 'unable to make fake node'30+VERSION_PATH="$(nvm_version_path "${NVM_TEST_VERSION}")"31 24-# Switch to another version so we can uninstall25-nvm use 0.12.732+# Make part of the installation folder unwritable, and not self-owned33+mkdir -p "${VERSION_PATH}/lib"34+sudo -n touch "${VERSION_PATH}/lib/root-owned-file" || die 'sudo touch failed'35+sudo -n chmod 444 "${VERSION_PATH}/lib/root-owned-file" || die 'sudo chmod failed'36 37+# Make sure the version to uninstall is not the active one38+nvm deactivate >/dev/null 2>&1 || true39+40 # Attempt to uninstall it28-RETURN_MESSAGE="$(nvm uninstall $NVM_TEST_VERSION 2>&1)"41+RETURN_MESSAGE="$(nvm uninstall "${NVM_TEST_VERSION}" 2>&1)"42 CHECK_FOR="Cannot uninstall, incorrect permissions on installation folder"30-test "${RETURN_MESSAGE#*$CHECK_FOR}" != "$RETURN_MESSAGE" || die "Failed to show error message"43+case "${RETURN_MESSAGE}" in44+ *"${CHECK_FOR}"*) ;;45+ *) die "Failed to show error message; got: ${RETURN_MESSAGE}" ;;46+esac47+48+# ... and the version must not have been removed49+nvm_is_version_installed "${NVM_TEST_VERSION}" || die 'version was uninstalled despite the permissions error'50+51+cleanupmodified:test/slow/nvm use/Running 'nvm use' with nvmrc containing not installed version
modified:package.json+1 added-1 removed
12 unmodified lines13 "test/installation": "npm run --silent test/installation/node && npm run --silent test/installation/iojs",14 "test/installation/node": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=installation_node test-$shell",15 "test/installation/iojs": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=installation_iojs test-$shell",16 "test/sourcing": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=sourcing test-$shell",17- "test:check-exec": "(IFS=$'\\n'; for file in $(git ls-files test); do if [ ! -x \"$file\" ] && [[ \"$file\" != *.* ]] && [[ \"$file\" != test/fixtures/* ]]; then echo \"$file\"; fi; done) | tee /dev/stderr | awk 'END {if (NR > 0) exit 1}'",17+ "test:check-exec": "git -c core.quotePath=false ls-files test | while IFS= read -r file; do if [ ! -x \"$file\" ]; then case \"$file\" in test/fixtures/*|*.json|*.txt|*.sh|*.js|*.log|*.tab|*.gitkeep) ;; *) echo \"$file\" ;; esac; fi; done | tee /dev/stderr | awk 'END {if (NR > 0) exit 1}'",18 "test:check-nonexec": "(IFS=$'\\n'; for file in $(git ls-files test); do if [ -x \"$file\" ] && [ ! -d \"$file\" ] && { [[ \"$file\" =~ '\\.(json|txt|sh|js|log)$' ]] || [[ \"$file\" =~ '^test/(mocks|fixtures)/.*' ]]; }; then echo \"$file\"; fi; done) | tee /dev/stderr | awk 'END {if (NR > 0) exit 1}'",19 "doctoc": "doctoc --title='## Table of Contents' --github README.md",20 "predoctoc:check": "cp README.md v-README.md.orig && npm run doctoc",21 "doctoc:check": "diff -q README.md v-README.md.orig",32 unmodified lines