Skip to content

Commit

Permalink
Log last check run on error (#841)
Browse files Browse the repository at this point in the history
This should help to troubleshoot validation failures.

Suggested by @samchungy in #832.

Co-authored-by: Sam Chung <[email protected]>
  • Loading branch information
72636c and samchungy authored Apr 14, 2022
1 parent 7653184 commit cded9f0
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
23 changes: 22 additions & 1 deletion src/cli/test/reporters/github/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,5 +378,26 @@ it('should log a warning when it fails to create annotations', async () => {

await reporter.onRunComplete(context, failResults);

expect(log.warn).toBeCalled();
const logs = [
null,
jest.mocked(log.warn).mock.calls,
jest
.mocked(log.subtle)
.mock.calls[0]?.join('\n')
.replace(/(at Object\.\<anonymous\>)[\s\S]+$/, '$1...'),
jest.mocked(log.subtle).mock.calls.slice(1),
null,
]
.flat()
.join('\n');

expect(logs).toMatchInlineSnapshot(`
"
Failed to report test results to GitHub.
Error: Badness!
at Object.<anonymous>...
Last request:
{\\"name\\":\\"skuba/test\\",\\"annotations\\":[{\\"annotation_level\\":\\"failure\\",\\"path\\":\\"src/test.test.ts\\",\\"start_line\\":2,\\"end_line\\":2,\\"start_column\\":15,\\"end_column\\":15,\\"message\\":\\"Error: expect(received).toBe(expected) // Object.is equality\\\\n\\\\nExpected: \\\\\\"a\\\\\\"\\\\nReceived: \\\\\\"b\\\\\\"\\\\n at Object.<anonymous> (/workdir/skuba/src/test.test.ts:2:15)\\\\n at Promise.then.completed (/workdir/skuba/node_modules/jest-circus/build/utils.js:390:28)\\\\n at new Promise (<anonymous>)\\\\n at callAsyncCircusFn (/workdir/skuba/node_modules/jest-circus/build/utils.js:315:10)\\\\n at _callCircusTest (/workdir/skuba/node_modules/jest-circus/build/run.js:218:40)\\\\n at processTicksAndRejections (node:internal/process/task_queues:96:5)\\\\n at _runTest (/workdir/skuba/node_modules/jest-circus/build/run.js:155:3)\\\\n at _runTestsForDescribeBlock (/workdir/skuba/node_modules/jest-circus/build/run.js:66:9)\\\\n at run (/workdir/skuba/node_modules/jest-circus/build/run.js:25:3)\\\\n at runAndTransformResultsToJestFormat (/workdir/skuba/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:167:21)\\",\\"title\\":\\"Jest\\"}],\\"conclusion\\":\\"failure\\",\\"summary\\":\\"\`skuba test\` found issues that require triage.\\",\\"title\\":\\"Test #123 failed\\"}
"
`);
});
32 changes: 22 additions & 10 deletions src/cli/test/reporters/github/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export default class GitHubReporter implements Pick<Reporter, 'onRunComplete'> {
return;
}

type CheckRun = Parameters<typeof GitHub.createCheckRun>[0];

let lastCheckRun: CheckRun | undefined;

try {
const entries = generateAnnotationEntries(testResults);

Expand All @@ -38,20 +42,28 @@ export default class GitHubReporter implements Pick<Reporter, 'onRunComplete'> {
? '`skuba test` passed.'
: '`skuba test` found issues that require triage.';

await throwOnTimeout(
GitHub.createCheckRun({
name,
annotations,
conclusion: isOk ? 'success' : 'failure',
summary,
title: `${build} ${isOk ? 'passed' : 'failed'}`,
}),
{ s: 30 },
);
const checkRun: CheckRun = {
name,
annotations,
conclusion: isOk ? 'success' : 'failure',
summary,
title: `${build} ${isOk ? 'passed' : 'failed'}`,
};

lastCheckRun = checkRun;

await throwOnTimeout(GitHub.createCheckRun(checkRun), {
s: 30,
});
}
} catch (err) {
log.warn('Failed to report test results to GitHub.');
log.subtle(inspect(err));

if (lastCheckRun) {
log.subtle('Last request:');
log.subtle(JSON.stringify(lastCheckRun));
}
}
}
}

0 comments on commit cded9f0

Please sign in to comment.