From 50b5a0836352a31022a44e32b18018cceb64eda7 Mon Sep 17 00:00:00 2001 From: Parker Brown <17183625+parkerbxyz@users.noreply.github.com> Date: Fri, 13 Mar 2026 19:05:44 -0700 Subject: [PATCH] Stabilize stderr snapshots Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- tests/index.js | 9 ++++++++- tests/index.js.snapshot | 36 ++++++++++++++++++------------------ 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/tests/index.js b/tests/index.js index d3e2521..11ce4a8 100644 --- a/tests/index.js +++ b/tests/index.js @@ -11,6 +11,13 @@ snapshot.setDefaultSnapshotSerializers([ (value) => (typeof value === "string" ? value : undefined), ]); +function normalizeStderr(stderr) { + return stderr + .replaceAll(/\u001B\[[0-9;]*m/g, "") + .replaceAll(process.cwd(), "") + .replaceAll(/:\d+:\d+/g, "::"); +} + // Get all files in tests directory const files = readdirSync("tests"); @@ -42,7 +49,7 @@ for (const file of testFiles) { const { stderr, stdout } = await execFileAsync("node", [`tests/${file}`], { env, }); - const trimmedStderr = stderr.replace(/\r?\n$/, ""); + const trimmedStderr = normalizeStderr(stderr).replace(/\r?\n$/, ""); const trimmedStdout = stdout.replace(/\r?\n$/, ""); await t.test("stderr", (t) => { if (trimmedStderr) t.assert.snapshot(trimmedStderr); diff --git a/tests/index.js.snapshot b/tests/index.js.snapshot index b5b4215..e9700a2 100644 --- a/tests/index.js.snapshot +++ b/tests/index.js.snapshot @@ -19,12 +19,12 @@ POST /api/v3/app/installations/123456/access_tokens exports[`main-enterprise-installation-not-found.test.js > stderr 1`] = ` Error: No enterprise installation found matching the name test-enterprise. - at getTokenFromEnterprise (file:///Users/parkerbxyz/.copilot/worktrees/create-github-app-token/pr-263/lib/main.js:223:13) - at process.processTicksAndRejections (node:internal/process/task_queues:104:5) - at async pRetry (file:///Users/parkerbxyz/.copilot/worktrees/create-github-app-token/pr-263/node_modules/p-retry/index.js:197:19) - at async main (file:///Users/parkerbxyz/.copilot/worktrees/create-github-app-token/pr-263/lib/main.js:95:52) - at async test (file:///Users/parkerbxyz/.copilot/worktrees/create-github-app-token/pr-263/tests/main.js:111:3) - at async file:///Users/parkerbxyz/.copilot/worktrees/create-github-app-token/pr-263/tests/main-enterprise-installation-not-found.test.js:4:1 + at getTokenFromEnterprise (file:///lib/main.js::) + at process.processTicksAndRejections (node:internal/process/task_queues::) + at async pRetry (file:///node_modules/p-retry/index.js::) + at async main (file:///lib/main.js::) + at async test (file:///tests/main.js::) + at async file:///tests/main-enterprise-installation-not-found.test.js:: `; exports[`main-enterprise-installation-not-found.test.js > stdout 1`] = ` @@ -36,22 +36,22 @@ GET /enterprises/test-enterprise/installation exports[`main-enterprise-mutual-exclusivity-owner.test.js > stderr 1`] = ` Error: Cannot use 'enterprise-slug' input with 'owner' or 'repositories' inputs - at main (file:///Users/parkerbxyz/.copilot/worktrees/create-github-app-token/pr-263/lib/main.js:31:11) - at run (file:///Users/parkerbxyz/.copilot/worktrees/create-github-app-token/pr-263/main.js:35:10) - at file:///Users/parkerbxyz/.copilot/worktrees/create-github-app-token/pr-263/main.js:50:16 - at ModuleJob.run (node:internal/modules/esm/module_job:430:25) - at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:639:26) - at async file:///Users/parkerbxyz/.copilot/worktrees/create-github-app-token/pr-263/tests/main-enterprise-mutual-exclusivity-owner.test.js:12:3 + at main (file:///lib/main.js::) + at run (file:///main.js::) + at file:///main.js:: + at ModuleJob.run (node:internal/modules/esm/module_job::) + at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader::) + at async file:///tests/main-enterprise-mutual-exclusivity-owner.test.js:: `; exports[`main-enterprise-mutual-exclusivity-repositories.test.js > stderr 1`] = ` Error: Cannot use 'enterprise-slug' input with 'owner' or 'repositories' inputs - at main (file:///Users/parkerbxyz/.copilot/worktrees/create-github-app-token/pr-263/lib/main.js:31:11) - at run (file:///Users/parkerbxyz/.copilot/worktrees/create-github-app-token/pr-263/main.js:35:10) - at file:///Users/parkerbxyz/.copilot/worktrees/create-github-app-token/pr-263/main.js:50:16 - at ModuleJob.run (node:internal/modules/esm/module_job:430:25) - at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:639:26) - at async file:///Users/parkerbxyz/.copilot/worktrees/create-github-app-token/pr-263/tests/main-enterprise-mutual-exclusivity-repositories.test.js:12:3 + at main (file:///lib/main.js::) + at run (file:///main.js::) + at file:///main.js:: + at ModuleJob.run (node:internal/modules/esm/module_job::) + at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader::) + at async file:///tests/main-enterprise-mutual-exclusivity-repositories.test.js:: `; exports[`main-enterprise-only-success.test.js > stdout 1`] = `