fix(tests): clear NODE_TEST_CONTEXT for nested node --test in two suites (#1508)
test-foundation.sh and test-discord.sh ran a nested node --test that would exit 0 on failure under a parent runner. Both clear the variable now, and each has a check that fails the suite if it comes back. Darkwing wrote it, Filbert approved it (e464be6c). Nine suites green on an index export. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Executable
+39
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
# N13 check (#1508): a failing nested `node --test` must fail test-foundation.sh
|
||||
# and test-discord.sh even when a parent runner's NODE_TEST_CONTEXT is set.
|
||||
# Runs in a scratch clone only: n13-check.sh CLONE (a clone of HEAD with
|
||||
# node_modules linked). It copies this checkout's two suites into the clone,
|
||||
# plants a failing test in each suite's test directory, and restores after.
|
||||
set -uo pipefail
|
||||
SRC="$(cd "$(dirname "$0")/../../../.." && pwd)"
|
||||
CLONE="${1:?usage: n13-check.sh CLONE}"
|
||||
[ "$(cd "$CLONE" && pwd)" != "$SRC" ] || { echo "refusing to run in the canonical checkout" >&2; exit 4; }
|
||||
cd "$CLONE" || exit 1
|
||||
|
||||
PLANT='import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
test("N13 planted failure", () => assert.equal(1, 2));'
|
||||
FAILS=0
|
||||
expect() { # NAME WANT GOT
|
||||
if [ "$2" = "$3" ]; then echo "ok $1 (rc $3)"; else echo "FAIL $1 (want rc $2, got $3)"; FAILS=$((FAILS+1)); fi
|
||||
}
|
||||
run() { # SUITE -> rc, output in /tmp/n13-<suite>-<tag>.txt
|
||||
NODE_TEST_CONTEXT=child-v8 NO_COLOR=1 "scripts/test-$1.sh" >"/tmp/n13-$1-$2.txt" 2>&1
|
||||
}
|
||||
|
||||
for pair in foundation:scripts/foundation discord:packages/discord/tests; do
|
||||
suite=${pair%%:*} dir=${pair#*:}
|
||||
git checkout -q -- "scripts/test-$suite.sh"
|
||||
printf '%s\n' "$PLANT" >"$dir/zz-n13-planted.test.mjs"
|
||||
run "$suite" head-planted; expect "$suite at HEAD, planted failure, parent context set" 0 $?
|
||||
cp -p "$SRC/scripts/test-$suite.sh" "scripts/test-$suite.sh"
|
||||
run "$suite" fixed-planted; expect "$suite fixed, planted failure, parent context set" 1 $?
|
||||
rm -f "$dir/zz-n13-planted.test.mjs"
|
||||
run "$suite" fixed-clean; expect "$suite fixed, no planted failure, parent context set" 0 $?
|
||||
sed -i 's/node_tests() { env -u NODE_TEST_CONTEXT node --test/node_tests() { node --test/' "scripts/test-$suite.sh"
|
||||
run "$suite" mutant-clean; expect "$suite with the clearing removed, no planted failure" 1 $?
|
||||
git checkout -q -- "scripts/test-$suite.sh"
|
||||
done
|
||||
git status --short
|
||||
echo "n13 check: $FAILS failed"
|
||||
[ "$FAILS" -eq 0 ]
|
||||
Reference in New Issue
Block a user