Skip to content

Commit

Permalink
Add test for rendering commit comment
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin940726 committed Nov 16, 2022
1 parent e4abe51 commit 88c5940
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
52 changes: 52 additions & 0 deletions packages/report-flaky-tests/src/__tests__/markdown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import {
renderIssueBody,
parseFormattedTestResults,
parseIssueBody,
renderCommitComment,
isReportComment,
} from '../markdown';
import { ReportedIssue } from '../types';

jest.useFakeTimers( 'modern' ).setSystemTime( new Date( '2020-05-10' ) );

Expand Down Expand Up @@ -226,6 +229,55 @@ describe( 'parseIssueBody', () => {
} );
} );

describe( 'renderCommitComment', () => {
it( 'render the commit comment', () => {
const runURL = 'runURL';
const reportedIssues: ReportedIssue[] = [
{
testTitle: 'title1',
testPath: 'path1',
issueNumber: 1,
issueUrl: 'url1',
},
{
testTitle: 'title2',
testPath: 'path2',
issueNumber: 2,
issueUrl: 'url2',
},
];

const commentBody = renderCommitComment( {
reportedIssues,
runURL,
} );

expect( commentBody ).toMatchInlineSnapshot( `
"<!-- flaky-tests-report-comment -->
**Flaky tests detected.**
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See [the documentation](https://github.com/WordPress/gutenberg/blob/HEAD/docs/contributors/code/testing-overview.md#flaky-tests) for more information.
🔍 Workflow run URL: runURL
📝 Reported issues:
- #1 in \`path1\`
- #2 in \`path2\`"
` );
} );
} );

describe( 'isReportComment', () => {
it( 'matches the report comment', () => {
const commentBody = renderCommitComment( {
reportedIssues: [],
runURL: '',
} );

expect( isReportComment( commentBody ) ).toBe( true );

expect( isReportComment( 'random string' ) ).toBe( false );
} );
} );

function renderToDisplayText( html: string ) {
const container = document.createElement( 'div' );
container.innerHTML = html;
Expand Down
2 changes: 1 addition & 1 deletion packages/report-flaky-tests/src/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ function renderCommitComment( {
runURL: string;
} ) {
return `<!-- ${ FLAKY_TESTS_REPORT_COMMENT_TOKEN } -->
**Flaky test${ reportedIssues.length > 1 ? 's' : '' } detected.**
**Flaky tests detected.**
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See [the documentation](https://github.com/WordPress/gutenberg/blob/HEAD/docs/contributors/code/testing-overview.md#flaky-tests) for more information.
🔍 Workflow run URL: ${ runURL }
Expand Down

0 comments on commit 88c5940

Please sign in to comment.