-
Notifications
You must be signed in to change notification settings - Fork 34
feat: Surface latest upload error for latest commit in a branch for tests tab #3722
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
203 changes: 203 additions & 0 deletions
203
...age/FailedTestsTab/FailedTestsPage/FailedTestsErrorBanner/FailedTestsErrorBanner.test.tsx
This file contains hidden or 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,203 @@ | ||
| import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | ||
| import { render, screen, waitFor } from '@testing-library/react' | ||
| import { graphql, HttpResponse } from 'msw' | ||
| import { setupServer } from 'msw/node' | ||
| import { Suspense } from 'react' | ||
| import { MemoryRouter, Route } from 'react-router-dom' | ||
|
|
||
| import { ErrorCodeEnum } from 'shared/utils/commit' | ||
|
|
||
| import { FailedTestsErrorBanner } from '../FailedTestsErrorBanner' | ||
|
|
||
| const server = setupServer() | ||
|
|
||
| const queryClient = new QueryClient({ | ||
| defaultOptions: { queries: { retry: false } }, | ||
| }) | ||
|
|
||
| beforeAll(() => { | ||
| server.listen() | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| vi.clearAllMocks() | ||
| queryClient.clear() | ||
| server.resetHandlers() | ||
| }) | ||
|
|
||
| afterAll(() => { | ||
| server.close() | ||
| }) | ||
|
|
||
| const mockRepoOverview = { | ||
| owner: { | ||
| isCurrentUserActivated: true, | ||
| repository: { | ||
| __typename: 'Repository', | ||
| private: false, | ||
| defaultBranch: 'main', | ||
| oldestCommitAt: '2022-10-10T11:59:59', | ||
| coverageEnabled: true, | ||
| bundleAnalysisEnabled: true, | ||
| testAnalyticsEnabled: false, | ||
| languages: ['javascript'], | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| const mockTestResultsTestSuites = ({ | ||
| errorCode, | ||
| errorMessage, | ||
| }: { | ||
| errorCode: string | ||
| errorMessage: string | ||
| }) => ({ | ||
| owner: { | ||
| repository: { | ||
| __typename: 'Repository', | ||
| testAnalytics: { | ||
| testSuites: ['java', 'script'], | ||
| }, | ||
| branch: { | ||
| head: { | ||
| latestUploadError: { errorCode, errorMessage }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
|
|
||
| const wrapper = | ||
| ( | ||
| initialEntries = ['/repo/codecov/gazebo/branch/test'] | ||
| ): React.FC<React.PropsWithChildren> => | ||
| ({ children }) => ( | ||
| <QueryClientProvider client={queryClient}> | ||
| <MemoryRouter initialEntries={initialEntries}> | ||
| <Route path="/repo/:owner/:repo/branch/:branch"> | ||
| <Suspense fallback={<div>Loading...</div>}>{children}</Suspense> | ||
| </Route> | ||
| </MemoryRouter> | ||
| </QueryClientProvider> | ||
| ) | ||
|
|
||
| describe('FailedTestsErrorBanner', () => { | ||
| function setup({ | ||
| errorCode, | ||
| errorMessage = 'File not found', | ||
| }: { | ||
| errorCode: string | ||
| errorMessage?: string | ||
| }) { | ||
| server.use( | ||
| graphql.query('GetRepoOverview', () => { | ||
| return HttpResponse.json({ | ||
| data: mockRepoOverview, | ||
| }) | ||
| }), | ||
| graphql.query('GetTestResultsTestSuites', () => { | ||
| return HttpResponse.json({ | ||
| data: mockTestResultsTestSuites({ errorCode, errorMessage }), | ||
| }) | ||
| }) | ||
| ) | ||
| } | ||
|
|
||
| it('renders nothing when unexpected error is provided', async () => { | ||
| setup({ errorCode: ErrorCodeEnum.unknownProcessing }) | ||
| const { container } = render(<FailedTestsErrorBanner />, { | ||
| wrapper: wrapper(), | ||
| }) | ||
|
|
||
| await waitFor(() => queryClient.isFetching) | ||
| await waitFor(() => !queryClient.isFetching) | ||
|
|
||
| expect(container).toBeEmptyDOMElement() | ||
| }) | ||
|
|
||
| it('renders file not found in storage error', async () => { | ||
| setup({ errorCode: ErrorCodeEnum.fileNotFoundInStorage }) | ||
| render(<FailedTestsErrorBanner />, { wrapper: wrapper() }) | ||
| const banner = await screen.findByRole('heading', { | ||
| name: 'JUnit XML file not found', | ||
| }) | ||
| expect(banner).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('renders processing timeout error', async () => { | ||
| setup({ errorCode: ErrorCodeEnum.processingTimeout }) | ||
| render(<FailedTestsErrorBanner />, { wrapper: wrapper() }) | ||
| const banner = await screen.findByRole('heading', { | ||
| name: 'Upload timeout', | ||
| }) | ||
| expect(banner).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('renders unsupported file format error', async () => { | ||
| setup({ errorCode: ErrorCodeEnum.unsupportedFileFormat }) | ||
| render(<FailedTestsErrorBanner />, { wrapper: wrapper() }) | ||
| const banner = await screen.findByRole('heading', { | ||
| name: 'Unsupported file format', | ||
| }) | ||
| const content = await screen.findByText( | ||
| /Please review the parser error message:/ | ||
| ) | ||
| const troubleshootingLink = await screen.findByRole('link', { | ||
| name: 'troubleshooting guide', | ||
| }) | ||
|
|
||
| expect(banner).toBeInTheDocument() | ||
| expect(content).toBeInTheDocument() | ||
| expect(troubleshootingLink).toBeInTheDocument() | ||
| expect(troubleshootingLink).toHaveAttribute( | ||
| 'href', | ||
| 'https://docs.codecov.com/docs/test-analytics#troubleshooting' | ||
| ) | ||
| }) | ||
|
|
||
| describe('when error message is not provided for unsupported file format', () => { | ||
| it('hides the review parser error message', async () => { | ||
| setup({ | ||
| errorCode: ErrorCodeEnum.unsupportedFileFormat, | ||
| errorMessage: '', | ||
| }) | ||
| render(<FailedTestsErrorBanner />, { wrapper: wrapper() }) | ||
|
|
||
| await waitFor(() => queryClient.isFetching) | ||
| await waitFor(() => !queryClient.isFetching) | ||
|
|
||
| const banner = screen.queryByText( | ||
| 'Please review the parser error message:' | ||
| ) | ||
| expect(banner).not.toBeInTheDocument() | ||
| }) | ||
| }) | ||
|
|
||
| describe('when no branch is provided', () => { | ||
| it('renders nothing', async () => { | ||
| setup({ errorCode: ErrorCodeEnum.fileNotFoundInStorage }) | ||
|
|
||
| await waitFor(() => queryClient.isFetching) | ||
| await waitFor(() => !queryClient.isFetching) | ||
|
|
||
| const { container } = render(<FailedTestsErrorBanner />, { | ||
| wrapper: wrapper(['/repo/owner/repo/']), | ||
| }) | ||
| expect(container).toBeEmptyDOMElement() | ||
| }) | ||
| }) | ||
|
|
||
| describe('when branch is the default branch', () => { | ||
| it('renders nothing', async () => { | ||
| setup({ errorCode: ErrorCodeEnum.fileNotFoundInStorage }) | ||
|
|
||
| await waitFor(() => queryClient.isFetching) | ||
| await waitFor(() => !queryClient.isFetching) | ||
|
|
||
| const { container } = render(<FailedTestsErrorBanner />, { | ||
| wrapper: wrapper(['/repo/owner/repo/main']), | ||
| }) | ||
| expect(container).toBeEmptyDOMElement() | ||
| }) | ||
| }) | ||
| }) | ||
136 changes: 136 additions & 0 deletions
136
...RepoPage/FailedTestsTab/FailedTestsPage/FailedTestsErrorBanner/FailedTestsErrorBanner.tsx
This file contains hidden or 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,136 @@ | ||
| import { useParams } from 'react-router-dom' | ||
|
|
||
| import { useRepoOverview } from 'services/repo' | ||
| import { ErrorCodeEnum } from 'shared/utils/commit' | ||
| import A from 'ui/A' | ||
| import Banner from 'ui/Banner' | ||
| import BannerContent from 'ui/Banner/BannerContent' | ||
| import BannerHeading from 'ui/Banner/BannerHeading' | ||
| import Icon from 'ui/Icon' | ||
|
|
||
| import { useTestResultsTestSuites } from '../hooks/useTestResultsTestSuites/useTestResultsTestSuites' | ||
|
|
||
| const CodeSnippet: React.FC<React.PropsWithChildren> = ({ children }) => ( | ||
| <code className="rounded-md border border-ds-gray-secondary bg-ds-gray-primary p-1 text-xs text-ds-primary-red"> | ||
| {children} | ||
| </code> | ||
| ) | ||
|
|
||
| const FileNotFoundBanner = () => ( | ||
| <Banner variant="warning"> | ||
| <BannerHeading> | ||
| <div className="flex items-center gap-2"> | ||
| <Icon name="exclamation" className="text-orange-500" /> | ||
| <h3 className="font-semibold">JUnit XML file not found</h3> | ||
| </div> | ||
| </BannerHeading> | ||
| <BannerContent> | ||
| <p> | ||
| No result to display due to Test Analytics couldn't locate a JUnit | ||
| XML file. Please rename the file to include{' '} | ||
| <CodeSnippet>junit</CodeSnippet>, ensure CLI file search is enabled, or | ||
| use the <CodeSnippet>file</CodeSnippet> or{' '} | ||
| <CodeSnippet>search_dir</CodeSnippet> arguments to specify the file(s) | ||
| for upload. | ||
| </p> | ||
| </BannerContent> | ||
| </Banner> | ||
| ) | ||
|
|
||
| const ProcessingTimeoutBanner = () => ( | ||
| <Banner variant="warning"> | ||
| <BannerHeading> | ||
| <div className="flex items-center gap-2"> | ||
| <Icon name="exclamation" className="text-orange-500" /> | ||
| <h3 className="font-semibold">Upload timeout</h3> | ||
| </div> | ||
| </BannerHeading> | ||
| <BannerContent> | ||
| Your upload failed due to timeout. Please try it again. | ||
| </BannerContent> | ||
| </Banner> | ||
| ) | ||
|
|
||
| const UnsupportedFormatBanner = ({ | ||
| errorMessage, | ||
| }: { | ||
| errorMessage: string | ||
| }) => ( | ||
| <Banner variant="warning"> | ||
| <BannerHeading> | ||
| <div className="flex items-center gap-2"> | ||
| <Icon name="exclamation" className="text-orange-500" /> | ||
| <h3 className="font-semibold">Unsupported file format</h3> | ||
| </div> | ||
| </BannerHeading> | ||
| <BannerContent> | ||
| Upload processing failed due to unusable file format. | ||
| {errorMessage ? ( | ||
| <> | ||
| {' '} | ||
| Please review the parser error message:{' '} | ||
| <CodeSnippet>{errorMessage}</CodeSnippet> <br />{' '} | ||
| </> | ||
| ) : ( | ||
| ' ' | ||
| )} | ||
| For more help, visit our{' '} | ||
| <A | ||
| to={{ | ||
| pageName: 'testAnalyticsTroubleshooting', | ||
| }} | ||
| hook="trouble shooting guide" | ||
| isExternal={true} | ||
| > | ||
| troubleshooting guide | ||
| </A> | ||
| . | ||
| </BannerContent> | ||
| </Banner> | ||
| ) | ||
|
|
||
| interface URLParams { | ||
| provider: string | ||
| owner: string | ||
| repo: string | ||
| branch?: string | ||
| } | ||
|
|
||
| function FailedTestsErrorBanner() { | ||
| const { provider, owner, repo, branch } = useParams<URLParams>() | ||
| const { data: overview } = useRepoOverview({ | ||
| provider, | ||
| owner, | ||
| repo, | ||
| }) | ||
|
|
||
| const { data } = useTestResultsTestSuites({ branch }) | ||
| const latestUploadError = data?.latestUploadError ?? { | ||
| errorCode: ErrorCodeEnum.fileNotFoundInStorage, | ||
| errorMessage: 'File not found', | ||
| } | ||
|
|
||
| if (!latestUploadError || branch === overview?.defaultBranch) { | ||
| return null | ||
| } | ||
|
|
||
| const errorCode = latestUploadError.errorCode | ||
|
|
||
| if (errorCode === ErrorCodeEnum.fileNotFoundInStorage) { | ||
| return <FileNotFoundBanner /> | ||
| } | ||
|
|
||
| if (errorCode === ErrorCodeEnum.processingTimeout) { | ||
| return <ProcessingTimeoutBanner /> | ||
| } | ||
|
|
||
| if (errorCode === ErrorCodeEnum.unsupportedFileFormat) { | ||
| return ( | ||
| <UnsupportedFormatBanner errorMessage={latestUploadError.errorMessage} /> | ||
| ) | ||
| } | ||
|
|
||
| return null | ||
| } | ||
|
|
||
| export default FailedTestsErrorBanner |
1 change: 1 addition & 0 deletions
1
src/pages/RepoPage/FailedTestsTab/FailedTestsPage/FailedTestsErrorBanner/index.ts
This file contains hidden or 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 @@ | ||
| export { default as FailedTestsErrorBanner } from './FailedTestsErrorBanner' |
This file contains hidden or 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
6 changes: 5 additions & 1 deletion
6
src/pages/RepoPage/FailedTestsTab/FailedTestsPage/FailedTestsPage.tsx
This file contains hidden or 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
Oops, something went wrong.
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.
I think we wanna use v5 of the library right?
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.
Oh JK I guess we'd also have to update the hook as well