create-github-app-token/tests/index.js
Parker Brown e85f677b44
test: omit stack traces from snapshots (#401)
The `integration` check fails on `main` because 10 snapshots include
Node.js internal stack frames, and their names changed between Node.js
versions. CI installs the latest Node.js that matches `>=24.4.0`, so
these snapshots can break without any change to the action.

This PR runs each test with `--stack-trace-limit=0`, so error output no
longer includes stack traces. Snapshots still capture the error message,
any HTTP error details, and the `::error::` output users see. Code
coverage is still enforced by `c8 --100`.

Without stack traces, `normalizeStderr` is no longer needed, so this
removes it.

All 120 tests pass with 100% coverage on Node.js 24 and 26.

---------

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: b91f96b7-a7f3-4ff3-8f52-3a617307ede2
2026-10-12 15:35:22 -07:00

74 lines
2.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { readdirSync } from "node:fs";
import { execFile } from "node:child_process";
import { promisify } from "node:util";
import { snapshot, test } from "node:test";
const execFileAsync = promisify(execFile);
// Serialize strings as-is so multiline output is human-readable in snapshots
snapshot.setDefaultSnapshotSerializers([
(value) => (typeof value === "string" ? value : undefined),
]);
// Get all files in tests directory
const files = readdirSync("tests");
// Files to ignore
const ignore = [
"index.js",
"index.js.snapshot",
"main.js",
"mock-agent.js",
"README.md",
];
const testFiles = files.filter((file) => !ignore.includes(file)).sort();
// Throw an error if there is a file that does not end with test.js in the tests directory
for (const file of testFiles) {
if (!file.endsWith(".test.js")) {
throw new Error(`File ${file} does not end with .test.js`);
}
test(file, async (t) => {
// Override Actions environment variables that change `core`’s behavior
const {
GITHUB_OUTPUT,
GITHUB_STATE,
HTTP_PROXY,
HTTPS_PROXY,
http_proxy,
https_proxy,
NO_PROXY,
no_proxy,
NODE_OPTIONS,
NODE_USE_ENV_PROXY,
...env
} = process.env;
let stderr, stdout;
try {
// Omit stack traces so snapshots don't change with Node.js or dependency updates
({ stderr, stdout } = await execFileAsync(
"node",
["--stack-trace-limit=0", `tests/${file}`],
{ env },
));
} catch (error) {
if (!(error instanceof Error) || !("stderr" in error) || !("stdout" in error)) {
throw error;
}
({ stderr, stdout } = error);
}
const trimmedStderr = stderr.replace(/\r?\n$/, "");
const trimmedStdout = stdout.replace(/\r?\n$/, "");
await t.test("stderr", (t) => {
if (trimmedStderr) t.assert.snapshot(trimmedStderr);
else t.assert.strictEqual(trimmedStderr, "");
});
await t.test("stdout", (t) => {
if (trimmedStdout) t.assert.snapshot(trimmedStdout);
else t.assert.strictEqual(trimmedStdout, "");
});
});
}