From 124bad0292b6bfd70260dad805ea2c22fcfc8c3d Mon Sep 17 00:00:00 2001 From: Chris Barth Date: Thu, 17 Sep 2026 11:21:08 -0500 Subject: [PATCH] Assert the debug output's value, not its colour The token test looked for "Token:" in what _outputOptions wrote. chalk colours the option name, so an ANSI reset sits between the name and the colon, and the assertion only held where chalk had gone quiet -- any run whose stdout is a pipe, meaning CI and every scripted run. It failed the first time the suite ran in a terminal, during a release. The captured output now goes through stripVTControlCharacters, so the test asserts the value it was always about rather than the spelling it arrived in. Co-Authored-By: Claude Opus 5 --- test/Gren.membership.spec.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/Gren.membership.spec.js b/test/Gren.membership.spec.js index c2e00332..8f919053 100644 --- a/test/Gren.membership.spec.js +++ b/test/Gren.membership.spec.js @@ -3,6 +3,7 @@ import fs from "node:fs"; import os from "node:os"; import path from "node:path"; import { execFileSync } from "node:child_process"; +import { stripVTControlCharacters } from "node:util"; import Gren from "../lib/src/Gren.js"; import * as git from "../lib/src/_git.js"; import { createReleaseRepo } from "./fixtures/release-repo.js"; @@ -815,10 +816,13 @@ describe("Gren release membership", () => { process.stdout.write = write; } - const output = written.join(""); + // chalk colours the option names only when stdout is a terminal, so the run that + // matters -- a maintainer's, by hand -- is the one an assertion on the escape codes + // would fail. Assert the value, not the spelling it arrived in. + const output = stripVTControlCharacters(written.join("")); assert.notInclude(output, "ghp_averysecrettoken", "The token is not in the output"); - assert.include(output, "Token:", "The option is still reported"); + assert.include(output, "Token: ", "The option is still reported"); assert.include(output, "Repo: current", "The other options are still reported"); });