mirror of
https://github.com/actions/create-github-app-token.git
synced 2026-12-01 14:55:26 +00:00
test: strip ANSI escape codes from snapshot output (#412)
Strips ANSI escape codes from captured `stdout` and `stderr` before comparing test output to snapshots. When `FORCE_COLOR` is set (some terminals and tools set it), Node colorizes logged errors, so `main-token-get-owner-set-client-error.test.js` fails locally even though it passes in CI. With this change, snapshots match regardless of color settings. CI output is unchanged. Split out from #411. Co-authored-by: Aiqiao Yan <55104035+aiqiaoy@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
This commit is contained in:
1 file changed
+3
-3
+3
-3
@@ -1,6 +1,6 @@
|
||||
import { readdirSync } from "node:fs";
|
||||
import { execFile } from "node:child_process";
|
||||
import { promisify } from "node:util";
|
||||
import { promisify, stripVTControlCharacters } from "node:util";
|
||||
|
||||
import { snapshot, test } from "node:test";
|
||||
|
||||
@@ -60,8 +60,8 @@ for (const file of testFiles) {
|
||||
|
||||
({ stderr, stdout } = error);
|
||||
}
|
||||
const trimmedStderr = stderr.replace(/\r?\n$/, "");
|
||||
const trimmedStdout = stdout.replace(/\r?\n$/, "");
|
||||
const trimmedStderr = stripVTControlCharacters(stderr).replace(/\r?\n$/, "");
|
||||
const trimmedStdout = stripVTControlCharacters(stdout).replace(/\r?\n$/, "");
|
||||
await t.test("stderr", (t) => {
|
||||
if (trimmedStderr) t.assert.snapshot(trimmedStderr);
|
||||
else t.assert.strictEqual(trimmedStderr, "");
|
||||
|
||||
Reference in new issue
Block a user