Skip to content
Myr

[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.

authored by Jordan Harband · committed by Jordan Harband · parent 4e48294 · Browse files · 14 files+266 added−26 removed
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

14 files+266 added−26 removed

modified:.github/workflows/lint.yml+19 added-1 removed
modified:.github/workflows/tests-installation-iojs.yml+35 added-1 removed
96 unmodified lines
97 if: always()98 run: sudo apt-get install curl -y99 shell: bash100101 installation_iojs_source_compile:102 permissions:103 contents: read104105 name: 'actually compile io.js from source (gcc 4.9 container)'106 runs-on: ubuntu-latest107 timeout-minutes: 60108109 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 '134135 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: true
modified:test/fast/Unit tests/nvm install --offline+4 added-2 removed
10 unmodified lines
11 die "nvm_download should not be called in offline mode"12}1314# --offline with an already-installed version should succeed15INSTALLED_VERSION="$(nvm ls | command tail -1 | command awk '{print $1}' | command sed 's/\x1b\[[0-9;]*m//g')"16if [ -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)17INSTALLED_VERSION="$(nvm_ls | command grep -v '^system' | command tail -n1)"18if [ -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"22fi
19 unmodified lines
added:test/fixtures/fake-source-tarball/configure+22 added
1#!/bin/sh23# 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.78PREFIX=''9while [ $# -gt 0 ]; do10 case "${1}" in11 --prefix=*) PREFIX="${1#--prefix=}" ;;12 esac13 shift14done1516if [ -z "${PREFIX}" ]; then17 echo 'configure: a --prefix is required' >&218 exit 119fi2021printf 'PREFIX = %s\n' "${PREFIX}" > config.mk22echo "configured with PREFIX=${PREFIX}"
added:test/fixtures/fake-source-tarball/Makefile+15 added
1include config.mk23all: out/fake-bin45out/fake-bin: VERSION6 mkdir -p out7 printf '#!/bin/sh\necho %s\n' "$$(cat VERSION)" > out/fake-bin8 chmod +x out/fake-bin910install: all11 mkdir -p "$(PREFIX)/bin"12 cp out/fake-bin "$(PREFIX)/bin/node"13 cp out/fake-bin "$(PREFIX)/bin/iojs"1415.PHONY: all install
added:test/installation_iojs/install from fake source+44 added
1#!/bin/sh23\. ../common.sh45die () { echo "$@" ; exit 1; }67\. ../../nvm.sh89set -ex1011NVM_TEST_VERSION='v3.99.9'12NVM_PREFIXED_TEST_VERSION="iojs-${NVM_TEST_VERSION}"1314# Remove the stuff we're clobbering.15nvm uninstall "${NVM_TEST_VERSION}" || echo 'not installed'1617# 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.22SLUG="$(nvm_get_download_slug iojs source "${NVM_TEST_VERSION}")"23COMPRESSION="$(nvm_get_artifact_compression "${NVM_TEST_VERSION}")"24CACHE_DIR="$(nvm_cache_dir)/src/${SLUG}"25STAGING="$(mktemp -d)"26mkdir -p "${STAGING}/${SLUG}" "${CACHE_DIR}"27cp ../fixtures/fake-source-tarball/configure ../fixtures/fake-source-tarball/Makefile "${STAGING}/${SLUG}/"28chmod +x "${STAGING}/${SLUG}/configure"29echo "${NVM_TEST_VERSION}" > "${STAGING}/${SLUG}/VERSION"30if [ "${COMPRESSION}" = 'tar.xz' ]; then31 (cd "${STAGING}" && tar -cJf "${CACHE_DIR}/${SLUG}.${COMPRESSION}" "${SLUG}")32else33 (cd "${STAGING}" && tar -czf "${CACHE_DIR}/${SLUG}.${COMPRESSION}" "${SLUG}")34fi35rm -rf "${STAGING}"3637# Install from source38nvm install -s --offline "${NVM_PREFIXED_TEST_VERSION}" || die "'nvm install -s --offline ${NVM_PREFIXED_TEST_VERSION}' failed"3940# Check41nvm_is_version_installed "${NVM_PREFIXED_TEST_VERSION}" || die 'version not installed'42nvm run --silent "${NVM_PREFIXED_TEST_VERSION}" --version | grep "${NVM_TEST_VERSION}" || die "'nvm run ${NVM_PREFIXED_TEST_VERSION} --version | grep ${NVM_TEST_VERSION}' failed"4344rm -rf "${CACHE_DIR}"
modified:test/installation_iojs/install from source+18 added-1 removed
6 unmodified lines
7\. ../../nvm.sh89set -ex1011# 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).15GCC_MAJOR="$(gcc -dumpversion 2>/dev/null | command cut -d. -f1)"16if ! 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 019fi20case "${GCC_MAJOR}" in21 '' | *[!0-9]*) echo 'gcc is not available; skipping the io.js source install'; exit 0 ;;22esac23if [ "${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 026fi2728NVM_TEST_VERSION='v3.3.1'29NVM_PREFIXED_TEST_VERSION="iojs-${NVM_TEST_VERSION}"3031# Remove the stuff we're clobbering.
3 unmodified lines
35(watch nvm install -s "${NVM_PREFIXED_TEST_VERSION}") || die "'nvm install -s ${NVM_PREFIXED_TEST_VERSION}' failed"3637# Check38nvm_is_version_installed "${NVM_PREFIXED_TEST_VERSION}" || die 'version not installed'22nvm run "${NVM_PREFIXED_TEST_VERSION}" --version | grep "${NVM_TEST_VERSION}" || "'nvm run ${NVM_PREFIXED_TEST_VERSION} --version | grep ${NVM_TEST_VERSION}' failed"39nvm 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/sh23die () { echo "$@" ; exit 1; }45\. ../../nvm.sh67set -ex89NVM_TEST_VERSION='v3.99.8'10NVM_PREFIXED_TEST_VERSION="iojs-${NVM_TEST_VERSION}"1112# Remove the stuff we're clobbering.13nvm uninstall "${NVM_TEST_VERSION}" || echo 'not installed'1415# 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.20SLUG="$(nvm_get_download_slug iojs source "${NVM_TEST_VERSION}")"21COMPRESSION="$(nvm_get_artifact_compression "${NVM_TEST_VERSION}")"22CACHE_DIR="$(nvm_cache_dir)/src/${SLUG}"23STAGING="$(mktemp -d)"24mkdir -p "${STAGING}/${SLUG}" "${CACHE_DIR}"25cp ../fixtures/fake-source-tarball/configure ../fixtures/fake-source-tarball/Makefile "${STAGING}/${SLUG}/"26chmod +x "${STAGING}/${SLUG}/configure"27echo "${NVM_TEST_VERSION}" > "${STAGING}/${SLUG}/VERSION"28if [ "${COMPRESSION}" = 'tar.xz' ]; then29 (cd "${STAGING}" && tar -cJf "${CACHE_DIR}/${SLUG}.${COMPRESSION}" "${SLUG}")30else31 (cd "${STAGING}" && tar -czf "${CACHE_DIR}/${SLUG}.${COMPRESSION}" "${SLUG}")32fi33rm -rf "${STAGING}"3435# Install from source, with the version specified in .nvmrc36echo "${NVM_PREFIXED_TEST_VERSION}" > .nvmrc3738nvm install -s --offline || die "'nvm install -s --offline' failed"3940# Check41nvm_is_version_installed "${NVM_PREFIXED_TEST_VERSION}" || die 'version is not installed'42nvm 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"4445rm -rf "${CACHE_DIR}"
modified:test/installation_iojs/install version specified in .nvmrc from source+21 added-3 removed
4 unmodified lines
5\. ../../nvm.sh67set -ex89# 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).14GCC_MAJOR="$(gcc -dumpversion 2>/dev/null | command cut -d. -f1)"15if ! 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 018fi19case "${GCC_MAJOR}" in20 '' | *[!0-9]*) echo 'gcc is not available; skipping the io.js source install'; exit 0 ;;21esac22if [ "${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 025fi2627NVM_TEST_VERSION='v3.3.0'28NVM_PREFIXED_TEST_VERSION="iojs-${NVM_TEST_VERSION}"2930# Remove the stuff we're clobbering.31nvm uninstall "${NVM_TEST_VERSION}" || echo 'not installed'3215# Install from binary33# Install from source, with the version specified in .nvmrc34echo "${NVM_PREFIXED_TEST_VERSION}" > .nvmrc3518nvm install -s || "'nvm install -s' failed"36nvm install -s || die "'nvm install -s' failed"3738# Check39nvm_is_version_installed "${NVM_PREFIXED_TEST_VERSION}" || die 'version is not installed'22nvm run "${NVM_PREFIXED_TEST_VERSION}" --version | grep "${NVM_TEST_VERSION}" \40nvm 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 lines
5nvm uninstall iojs-v1.0.06nvm uninstall iojs-v1.0.37nvm uninstall iojs-v3.3.08nvm uninstall iojs-v3.3.19nvm uninstall iojs-v3.99.810nvm uninstall iojs-v3.99.91112if [ -f ".nvmrc" ]; then13 rm .nvmrc14fi
4 unmodified lines
modified:test/slow/nvm exec/Running 'nvm exec' with help should not parse+3 added-1 removed
4 unmodified lines
5\. ../../../nvm.sh67nvm use 0.1089# 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 instead9nvm exec stable -- node --help | grep 'Usage: node [options]' || die "Help menu should have been displayed for node and not nvm"11nvm 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/sh23die () { echo "$@" ; exit 1; }3die () { echo "$@" ; cleanup ; exit 1; }45# Source nvm6\. ../../../nvm.sh78# Version to install/uninstall9NVM_TEST_VERSION=5.10.18\. ../../common.sh911# Make sure it's not already here12[ -e ../../../$NVM_TEST_VERSION ] && rm -R ../../../$NVM_TEST_VERSION10NVM_TEST_VERSION=v5.99.991114# Install it15nvm install $NVM_TEST_VERSION12cleanup() {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}1917# Make sure it installed18nvm 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.23if ! sudo -n true 2>/dev/null; then24 echo 'passwordless sudo is not available, skipping'25 exit 026fi2720# Install global module as root21npm_path=$(which npm)22sudo -n "$npm_path" install jspm@'<2' -g || die 'either sudo failed, or `npm install jspm -g` failed`'28# Install a fake version to uninstall29make_fake_node "${NVM_TEST_VERSION}" || die 'unable to make fake node'30VERSION_PATH="$(nvm_version_path "${NVM_TEST_VERSION}")"3124# Switch to another version so we can uninstall25nvm use 0.12.732# Make part of the installation folder unwritable, and not self-owned33mkdir -p "${VERSION_PATH}/lib"34sudo -n touch "${VERSION_PATH}/lib/root-owned-file" || die 'sudo touch failed'35sudo -n chmod 444 "${VERSION_PATH}/lib/root-owned-file" || die 'sudo chmod failed'3637# Make sure the version to uninstall is not the active one38nvm deactivate >/dev/null 2>&1 || true3940# Attempt to uninstall it28RETURN_MESSAGE="$(nvm uninstall $NVM_TEST_VERSION 2>&1)"41RETURN_MESSAGE="$(nvm uninstall "${NVM_TEST_VERSION}" 2>&1)"42CHECK_FOR="Cannot uninstall, incorrect permissions on installation folder"30test "${RETURN_MESSAGE#*$CHECK_FOR}" != "$RETURN_MESSAGE" || die "Failed to show error message"43case "${RETURN_MESSAGE}" in44 *"${CHECK_FOR}"*) ;;45 *) die "Failed to show error message; got: ${RETURN_MESSAGE}" ;;46esac4748# ... and the version must not have been removed49nvm_is_version_installed "${NVM_TEST_VERSION}" || die 'version was uninstalled despite the permissions error'5051cleanup
modified:test/slow/nvm use/Running 'nvm use' with nvmrc containing not installed version
modified:package.json+1 added-1 removed
12 unmodified lines
13 "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