-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
fix(jest-reporters): print out console log for GHA reporter and group by test file #15864
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
Changes from 5 commits
3eafb97
18d897c
5048ef2
f09cbb9
e2dfd80
96ba394
b1bf034
a386875
49842f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ export default function getConsoleOutput( | |
| globalConfig: Config.GlobalConfig, | ||
| ): string { | ||
| const TITLE_INDENT = | ||
| globalConfig.verbose === true ? ' '.repeat(2) : ' '.repeat(4); | ||
| globalConfig?.verbose === true ? ' '.repeat(2) : ' '.repeat(4); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have to add
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when is it missing? types says it shouldn't be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My bad, I was doing nullish check on |
||
| const CONSOLE_INDENT = TITLE_INDENT + ' '.repeat(2); | ||
|
|
||
| const logEntries = buffer.reduce((output, {type, message, origin}) => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -687,5 +687,108 @@ describe('logs', () => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(mockedStderrWrite.mock.calls).toMatchSnapshot(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| test('onTestResult last with console output for failed test', () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const mockTest = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| context: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| config: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| rootDir: '/testDir', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const mockTestResult = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| message: 'bar', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| origin: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ' at Object.log (/tmp/jest-test/a.test.js:2:13)\n at Promise.finally.completed (/github.com/jestjs/jest/packages/jest-circus/build/jestAdapterInit.js:1557:28)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: 'log', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| failureMessage: 'Failure message', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| perfStats: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| runtime: 20, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| slow: false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| testFilePath: '/testDir/test1.js', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| testResults: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ancestorTitles: [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| duration: 10, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| status: 'passed', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| title: 'test1', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const mockResults = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| numFailedTestSuites: 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| numPassedTestSuites: 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| numTotalTestSuites: 3, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| testResults: [mockTestResult], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const gha = new GitHubActionsReporter({} as Config.GlobalConfig, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| silent: false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can use helpers from jest/packages/test-utils/src/config.ts Lines 141 to 175 in 6813dfa
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| gha.generateAnnotations = jest.fn(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| gha.onTestResult( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mockTest as Test, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mockTestResult as unknown as TestResult, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mockResults as unknown as AggregatedResult, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(mockedStderrWrite.mock.calls).toMatchSnapshot(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| test('onTestResult last with console output for success test', () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const mockTest = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| context: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| config: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| rootDir: '/testDir', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const mockTestResult = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| message: 'bar', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| origin: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ' at Object.log (/tmp/jest-test/a.test.js:2:13)\n at Promise.finally.completed (/github.com/jestjs/jest/packages/jest-circus/build/jestAdapterInit.js:1557:28)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: 'log', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| perfStats: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| runtime: 20, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| slow: false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| testFilePath: '/testDir/test1.js', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| testResults: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ancestorTitles: [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| duration: 10, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| status: 'passed', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| title: 'test1', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const mockResults = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| numFailedTestSuites: 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| numPassedTestSuites: 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| numTotalTestSuites: 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| testResults: [mockTestResult], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const gha = new GitHubActionsReporter({} as Config.GlobalConfig, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| silent: false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| gha.generateAnnotations = jest.fn(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| gha.onTestResult( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mockTest as Test, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mockTestResult as unknown as TestResult, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mockResults as unknown as AggregatedResult, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(mockedStderrWrite.mock.calls).toMatchSnapshot(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
mind putting the entries alphabetically?