Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer verbose failure message in exec annotations #910

Merged
merged 2 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rich-spoons-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'skuba': patch
---

test: Prefer verbose failure message in execution error annotations
33 changes: 33 additions & 0 deletions src/cli/test/reporters/github/annotations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ it('should create annotation from Jest exec error', () => {
'\x1B[7m \x1B[0m \x1B[91m ~~~\x1B[0m',
} as SerializableError;

// Prefer `failureMessage` for its "Test suite failed to run" headline
const testResult: TestResult = {
...COMMON_TEST_RESULT_FIELDS,
failureMessage:
Expand All @@ -173,6 +174,38 @@ it('should create annotation from Jest exec error', () => {

const annotations = createAnnotations([testResult]);
expect(annotations).toMatchInlineSnapshot(`
Array [
Object {
"annotation_level": "failure",
"end_line": 1,
"message": " ● Test suite failed to run

src/test.ts:1:1 - error TS6133: 'a' is declared but its value is never read.

1 import { a } from 'b';
~~~~~~~~~~~~~~~~~~~~~~
src/test.ts:1:19 - error TS2307: Cannot find module 'b' or its corresponding type declarations.

1 import { a } from 'b';
~~~
",
"path": "src/test.test.ts",
"start_line": 1,
"title": "Jest",
},
]
`);

// Fall back on the off chance we have no `failureMessage`
const testResultWithoutFailureMessage: TestResult = {
...testResult,
failureMessage: null,
};

const annotationsForNoFailureMessage = createAnnotations([
testResultWithoutFailureMessage,
]);
expect(annotationsForNoFailureMessage).toMatchInlineSnapshot(`
Array [
Object {
"annotation_level": "failure",
Expand Down
4 changes: 3 additions & 1 deletion src/cli/test/reporters/github/annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ export const createAnnotations = (
path: path.relative(cwd, testResult.testFilePath),
start_line: 1,
end_line: 1,
message: stripAnsi(testResult.testExecError.message),
message: stripAnsi(
testResult.failureMessage ?? testResult.testExecError.message,
),
title: 'Jest',
};
}
Expand Down