-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
refactor(@jest/reporters): improve annotation formatting of GitHubActionsReporter
#12826
Merged
SimenB
merged 22 commits into
jestjs:main
from
mrazauskas:feat-github-actions-annotations
May 9, 2022
Merged
Changes from 9 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
d71c5c1
refactor(@jest/reporters): improve annotations
mrazauskas 814db33
check paths
mrazauskas 7c116a7
remove @actions/core
mrazauskas ae036a7
relative?
mrazauskas e6c5d54
slash and done?
mrazauskas 300e7eb
remove examples
mrazauskas e594bcb
clean up
mrazauskas fadd5f2
add change log entry
mrazauskas 1022130
remove snap
mrazauskas 172a41e
Restart CI
mrazauskas f1a1e97
handle more paths
mrazauskas e95b5e5
fix ansi
mrazauskas ebd0bf8
fix filename
mrazauskas 7171272
clean up
mrazauskas cc02d0b
Restart CI
mrazauskas 87fb028
annotate retried tests
mrazauskas 74c3f74
rootDir again
mrazauskas 8f60aa1
use rootDir
mrazauskas 8e6e9ef
log retries first
mrazauskas fe273cd
unit test
mrazauskas 40b847d
reshape
mrazauskas a5ac9e0
clean up
mrazauskas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 0 additions & 118 deletions
118
packages/jest-reporters/src/__tests__/GitHubActionsReporter.test.js
This file was deleted.
Oops, something went wrong.
103 changes: 103 additions & 0 deletions
103
packages/jest-reporters/src/__tests__/GitHubActionsReporter.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import type {Test, TestCaseResult} from '@jest/test-result'; | ||
import GitHubActionsReporter from '../GitHubActionsReporter'; | ||
|
||
jest.mock('path', () => ({ | ||
relative: () => '__tests__/example.test.js', | ||
})); | ||
|
||
jest.spyOn(process.stderr, 'write').mockImplementation(jest.fn()); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
const reporter = new GitHubActionsReporter(); | ||
|
||
const testMeta = { | ||
context: {config: {rootDir: '/user/project'}}, | ||
path: '/user/project/__tests__/example.test.js', | ||
} as Test; | ||
|
||
const expectationsErrorMessage = | ||
'Error: \x1B[2mexpect(\x1B[22m\x1B[31mreceived\x1B[39m\x1B[2m).\x1B[22mtoBe\x1B[2m(\x1B[22m\x1B[32mexpected\x1B[39m\x1B[2m) // Object.is equality\x1B[22m\n' + | ||
'\n' + | ||
'Expected: \x1B[32m1\x1B[39m\n' + | ||
'Received: \x1B[31m10\x1B[39m\n' + | ||
' at Object.toBe (/user/project/__tests__/example.test.js:20:14)\n' + | ||
' at Promise.then.completed (/user/project/jest/packages/jest-circus/build/utils.js:333:28)\n' + | ||
' at new Promise (<anonymous>)\n' + | ||
' at callAsyncCircusFn (/user/project/jest/packages/jest-circus/build/utils.js:259:10)\n' + | ||
' at _callCircusTest (/user/project/jest/packages/jest-circus/build/run.js:276:40)\n' + | ||
' at processTicksAndRejections (node:internal/process/task_queues:95:5)\n' + | ||
' at _runTest (/user/project/jest/packages/jest-circus/build/run.js:208:3)\n' + | ||
' at _runTestsForDescribeBlock (/user/project/jest/packages/jest-circus/build/run.js:96:9)\n' + | ||
' at run (/user/project/jest/packages/jest-circus/build/run.js:31:3)\n' + | ||
' at runAndTransformResultsToJestFormat (/user/project/jest/packages/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:135:21)'; | ||
|
||
const referenceErrorMessage = | ||
'ReferenceError: abc is not defined\n' + | ||
' at Object.abc (/user/project/__tests__/example.test.js:25:12)\n' + | ||
' at Promise.then.completed (/user/project/jest/packages/jest-circus/build/utils.js:333:28)\n' + | ||
' at new Promise (<anonymous>)\n' + | ||
' at callAsyncCircusFn (/user/project/jest/packages/jest-circus/build/utils.js:259:10)\n' + | ||
' at _callCircusTest (/user/project/jest/packages/jest-circus/build/run.js:276:40)\n' + | ||
' at processTicksAndRejections (node:internal/process/task_queues:95:5)\n' + | ||
' at _runTest (/user/project/jest/packages/jest-circus/build/run.js:208:3)\n' + | ||
' at _runTestsForDescribeBlock (/user/project/jest/packages/jest-circus/build/run.js:96:9)\n' + | ||
' at _runTestsForDescribeBlock (/user/project/jest/packages/jest-circus/build/run.js:90:9)\n' + | ||
' at run (/user/project/jest/packages/jest-circus/build/run.js:31:3)'; | ||
|
||
const testCaseResult = { | ||
ancestorTitles: [] as Array<string>, | ||
failureMessages: [expectationsErrorMessage], | ||
title: 'some test', | ||
} as TestCaseResult; | ||
|
||
describe("passes test case report to '@actions/core'", () => { | ||
test('when expect returns an error', () => { | ||
reporter.onTestCaseResult(testMeta, { | ||
...testCaseResult, | ||
failureMessages: [expectationsErrorMessage], | ||
}); | ||
|
||
expect(jest.mocked(process.stderr.write)).toBeCalledTimes(1); | ||
expect(jest.mocked(process.stderr.write).mock.calls[0]).toMatchSnapshot(); | ||
}); | ||
|
||
test('when a test has reference error', () => { | ||
reporter.onTestCaseResult( | ||
{...testMeta, path: '/user/project/__tests__/example.test.js:25:12'}, | ||
{ | ||
...testCaseResult, | ||
failureMessages: [referenceErrorMessage], | ||
}, | ||
); | ||
|
||
expect(jest.mocked(process.stderr.write)).toBeCalledTimes(1); | ||
expect(jest.mocked(process.stderr.write).mock.calls[0]).toMatchSnapshot(); | ||
}); | ||
|
||
test('when test is wrapped in describe block', () => { | ||
reporter.onTestCaseResult(testMeta, { | ||
...testCaseResult, | ||
ancestorTitles: ['describe'], | ||
}); | ||
|
||
expect(jest.mocked(process.stderr.write)).toBeCalledTimes(1); | ||
expect(jest.mocked(process.stderr.write).mock.calls[0]).toMatchSnapshot(); | ||
}); | ||
|
||
test('when test not is wrapped in describe block', () => { | ||
reporter.onTestCaseResult(testMeta, testCaseResult); | ||
|
||
expect(jest.mocked(process.stderr.write)).toBeCalledTimes(1); | ||
expect(jest.mocked(process.stderr.write).mock.calls[0]).toMatchSnapshot(); | ||
}); | ||
}); |
7 changes: 0 additions & 7 deletions
7
packages/jest-reporters/src/__tests__/__snapshots__/GitHubActionsReporter.test.js.snap
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
packages/jest-reporters/src/__tests__/__snapshots__/GitHubActionsReporter.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`passes test case report to '@actions/core' when a test has reference error 1`] = ` | ||
Array [ | ||
" | ||
::error file=/user/project/__tests__/example.test.js:25:12,line=25,title=some test::ReferenceError: abc is not defined%0A%0A at Object.abc (__tests__/example.test.js) | ||
", | ||
] | ||
`; | ||
|
||
exports[`passes test case report to '@actions/core' when expect returns an error 1`] = ` | ||
Array [ | ||
" | ||
::error file=/user/project/__tests__/example.test.js,line=20,title=some test::expect(received).toBe(expected) // Object.is equality%0A%0AExpected: 1%0AReceived: 10%0A%0A at Object.toBe (__tests__/example.test.js:20:14) | ||
", | ||
] | ||
`; | ||
|
||
exports[`passes test case report to '@actions/core' when test is wrapped in describe block 1`] = ` | ||
Array [ | ||
" | ||
::error file=/user/project/__tests__/example.test.js,line=20,title=describe › some test::expect(received).toBe(expected) // Object.is equality%0A%0AExpected: 1%0AReceived: 10%0A%0A at Object.toBe (__tests__/example.test.js:20:14) | ||
", | ||
] | ||
`; | ||
|
||
exports[`passes test case report to '@actions/core' when test not is wrapped in describe block 1`] = ` | ||
Array [ | ||
" | ||
::error file=/user/project/__tests__/example.test.js,line=20,title=some test::expect(received).toBe(expected) // Object.is equality%0A%0AExpected: 1%0AReceived: 10%0A%0A at Object.toBe (__tests__/example.test.js:20:14) | ||
", | ||
] | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason,
rootDir
is not pointing to the right place. See #12822 (comment).In the other hand, in CI it feels right to keep paths relative to root of the repo.