mirror of
https://github.com/actions/create-github-app-token.git
synced 2026-12-01 14:55:26 +00:00
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 <223556219+Copilot@users.noreply.github.com> Copilot-Session: b91f96b7-a7f3-4ff3-8f52-3a617307ede2
This commit is contained in:
1 parent
9419396df4
commit
e85f677b44
2 files changed
+14
-70
No files matched your search
+7
-11
@@ -11,13 +11,6 @@ snapshot.setDefaultSnapshotSerializers([
|
||||
(value) => (typeof value === "string" ? value : undefined),
|
||||
]);
|
||||
|
||||
function normalizeStderr(stderr) {
|
||||
return stderr
|
||||
.replaceAll(/\u001B\[[0-9;]*m/g, "")
|
||||
.replaceAll(process.cwd(), "<cwd>")
|
||||
.replaceAll(/:\d+:\d+/g, ":<line>:<column>");
|
||||
}
|
||||
|
||||
// Get all files in tests directory
|
||||
const files = readdirSync("tests");
|
||||
|
||||
@@ -54,9 +47,12 @@ for (const file of testFiles) {
|
||||
} = process.env;
|
||||
let stderr, stdout;
|
||||
try {
|
||||
({ stderr, stdout } = await execFileAsync("node", [`tests/${file}`], {
|
||||
env,
|
||||
}));
|
||||
// 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;
|
||||
@@ -64,7 +60,7 @@ for (const file of testFiles) {
|
||||
|
||||
({ stderr, stdout } = error);
|
||||
}
|
||||
const trimmedStderr = normalizeStderr(stderr).replace(/\r?\n$/, "");
|
||||
const trimmedStderr = stderr.replace(/\r?\n$/, "");
|
||||
const trimmedStdout = stdout.replace(/\r?\n$/, "");
|
||||
await t.test("stderr", (t) => {
|
||||
if (trimmedStderr) t.assert.snapshot(trimmedStderr);
|
||||
|
||||
+7
-59
@@ -74,13 +74,7 @@ null
|
||||
`;
|
||||
|
||||
exports[`main-enterprise-installation-not-found.test.js > stderr 1`] = `
|
||||
Error: No enterprise installation found matching the enterprise slug "test-enterprise".
|
||||
at getTokenFromEnterprise (file://<cwd>/lib/main.js:<line>:<column>)
|
||||
at process.processTicksAndRejections (node:internal/process/task_queues:<line>:<column>)
|
||||
at async pRetry (file://<cwd>/node_modules/p-retry/index.js:<line>:<column>)
|
||||
at async main (file://<cwd>/lib/main.js:<line>:<column>)
|
||||
at async test (file://<cwd>/tests/main.js:<line>:<column>)
|
||||
at async file://<cwd>/tests/main-enterprise-installation-not-found.test.js:<line>:<column>
|
||||
[Error: No enterprise installation found matching the enterprise slug "test-enterprise".]
|
||||
`;
|
||||
|
||||
exports[`main-enterprise-installation-not-found.test.js > stdout 1`] = `
|
||||
@@ -92,13 +86,7 @@ GET /enterprises/test-enterprise/installation
|
||||
`;
|
||||
|
||||
exports[`main-enterprise-mutual-exclusivity-owner.test.js > stderr 1`] = `
|
||||
Error: Cannot use 'enterprise' input with 'owner' or 'repositories' inputs
|
||||
at main (file://<cwd>/lib/main.js:<line>:<column>)
|
||||
at run (file://<cwd>/main.js:<line>:<column>)
|
||||
at file://<cwd>/main.js:<line>:<column>
|
||||
at ModuleJob.run (node:internal/modules/esm/module_job:<line>:<column>)
|
||||
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:<line>:<column>)
|
||||
at async file://<cwd>/tests/main-enterprise-mutual-exclusivity-owner.test.js:<line>:<column>
|
||||
[Error: Cannot use 'enterprise' input with 'owner' or 'repositories' inputs]
|
||||
`;
|
||||
|
||||
exports[`main-enterprise-mutual-exclusivity-owner.test.js > stdout 1`] = `
|
||||
@@ -106,13 +94,7 @@ exports[`main-enterprise-mutual-exclusivity-owner.test.js > stdout 1`] = `
|
||||
`;
|
||||
|
||||
exports[`main-enterprise-mutual-exclusivity-repositories.test.js > stderr 1`] = `
|
||||
Error: Cannot use 'enterprise' input with 'owner' or 'repositories' inputs
|
||||
at main (file://<cwd>/lib/main.js:<line>:<column>)
|
||||
at run (file://<cwd>/main.js:<line>:<column>)
|
||||
at file://<cwd>/main.js:<line>:<column>
|
||||
at ModuleJob.run (node:internal/modules/esm/module_job:<line>:<column>)
|
||||
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:<line>:<column>)
|
||||
at async file://<cwd>/tests/main-enterprise-mutual-exclusivity-repositories.test.js:<line>:<column>
|
||||
[Error: Cannot use 'enterprise' input with 'owner' or 'repositories' inputs]
|
||||
`;
|
||||
|
||||
exports[`main-enterprise-mutual-exclusivity-repositories.test.js > stdout 1`] = `
|
||||
@@ -227,15 +209,7 @@ POST /app/installations/123456/access_tokens
|
||||
`;
|
||||
|
||||
exports[`main-token-get-owner-set-client-error.test.js > stderr 1`] = `
|
||||
RequestError [HttpError]: Forbidden
|
||||
at fetchWrapper (file://<cwd>/node_modules/@octokit/request/dist-bundle/index.js:<line>:<column>)
|
||||
at process.processTicksAndRejections (node:internal/process/task_queues:<line>:<column>)
|
||||
at async hook (file://<cwd>/node_modules/@octokit/auth-app/dist-node/index.js:<line>:<column>)
|
||||
at async getTokenFromOwner (file://<cwd>/lib/main.js:<line>:<column>)
|
||||
at async pRetry (file://<cwd>/node_modules/p-retry/index.js:<line>:<column>)
|
||||
at async main (file://<cwd>/lib/main.js:<line>:<column>)
|
||||
at async test (file://<cwd>/tests/main.js:<line>:<column>)
|
||||
at async file://<cwd>/tests/main-token-get-owner-set-client-error.test.js:<line>:<column> {
|
||||
[RequestError [HttpError]: Forbidden] {
|
||||
status: 403,
|
||||
request: {
|
||||
method: 'GET',
|
||||
@@ -323,17 +297,7 @@ POST /app/installations/123456/access_tokens
|
||||
`;
|
||||
|
||||
exports[`main-token-get-owner-set-repo-invalid-format.test.js > stderr 1`] = `
|
||||
Error: Invalid repository 'octocat/hello-world/extra'. Expected 'repository' or 'owner/repository'.
|
||||
at parseRepositoryInput (file://<cwd>/lib/main.js:<line>:<column>)
|
||||
at Array.map (<anonymous>)
|
||||
at normalizeRepositoryTarget (file://<cwd>/lib/main.js:<line>:<column>)
|
||||
at resolveInstallationTarget (file://<cwd>/lib/main.js:<line>:<column>)
|
||||
at main (file://<cwd>/lib/main.js:<line>:<column>)
|
||||
at run (file://<cwd>/main.js:<line>:<column>)
|
||||
at file://<cwd>/main.js:<line>:<column>
|
||||
at ModuleJob.run (node:internal/modules/esm/module_job:<line>:<column>)
|
||||
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:<line>:<column>)
|
||||
at async file://<cwd>/tests/main-token-get-owner-set-repo-invalid-format.test.js:<line>:<column>
|
||||
[Error: Invalid repository 'octocat/hello-world/extra'. Expected 'repository' or 'owner/repository'.]
|
||||
`;
|
||||
|
||||
exports[`main-token-get-owner-set-repo-invalid-format.test.js > stdout 1`] = `
|
||||
@@ -380,15 +344,7 @@ POST /app/installations/123456/access_tokens
|
||||
`;
|
||||
|
||||
exports[`main-token-get-owner-set-repo-owner-mismatch.test.js > stderr 1`] = `
|
||||
Error: Repository 'octocat/hello-world' includes owner 'octocat', which does not match the resolved owner 'actions'.
|
||||
at normalizeRepositoryTarget (file://<cwd>/lib/main.js:<line>:<column>)
|
||||
at resolveInstallationTarget (file://<cwd>/lib/main.js:<line>:<column>)
|
||||
at main (file://<cwd>/lib/main.js:<line>:<column>)
|
||||
at run (file://<cwd>/main.js:<line>:<column>)
|
||||
at file://<cwd>/main.js:<line>:<column>
|
||||
at ModuleJob.run (node:internal/modules/esm/module_job:<line>:<column>)
|
||||
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:<line>:<column>)
|
||||
at async file://<cwd>/tests/main-token-get-owner-set-repo-owner-mismatch.test.js:<line>:<column>
|
||||
[Error: Repository 'octocat/hello-world' includes owner 'octocat', which does not match the resolved owner 'actions'.]
|
||||
`;
|
||||
|
||||
exports[`main-token-get-owner-set-repo-owner-mismatch.test.js > stdout 1`] = `
|
||||
@@ -490,15 +446,7 @@ POST /app/installations/123456/access_tokens
|
||||
`;
|
||||
|
||||
exports[`main-token-get-owner-unset-repo-owner-mismatch.test.js > stderr 1`] = `
|
||||
Error: Repository 'octocat/hello-world' includes owner 'octocat', which does not match the resolved owner 'actions'.
|
||||
at normalizeRepositoryTarget (file://<cwd>/lib/main.js:<line>:<column>)
|
||||
at resolveInstallationTarget (file://<cwd>/lib/main.js:<line>:<column>)
|
||||
at main (file://<cwd>/lib/main.js:<line>:<column>)
|
||||
at run (file://<cwd>/main.js:<line>:<column>)
|
||||
at file://<cwd>/main.js:<line>:<column>
|
||||
at ModuleJob.run (node:internal/modules/esm/module_job:<line>:<column>)
|
||||
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:<line>:<column>)
|
||||
at async file://<cwd>/tests/main-token-get-owner-unset-repo-owner-mismatch.test.js:<line>:<column>
|
||||
[Error: Repository 'octocat/hello-world' includes owner 'octocat', which does not match the resolved owner 'actions'.]
|
||||
`;
|
||||
|
||||
exports[`main-token-get-owner-unset-repo-owner-mismatch.test.js > stdout 1`] = `
|
||||
|
||||
Reference in new issue
Block a user