Skip to content

Commit

Permalink
Fix tests that were intermittently failing in CI
Browse files Browse the repository at this point in the history
These tests have been failing intermittently in CI for about a year
now but until now had been unable to reproduce locally. For some
unknown reason (suspect dependency updates) they became consistently
reproducible locally this week, but were consistently passing in CI
:shrug:

Ensure all expected API calls are mocked for the error cases in the
affected tests so that they behave predictably.
  • Loading branch information
AlanGreene committed May 29, 2024
1 parent e76b377 commit 7082782
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/containers/HeaderBarContent/HeaderBarContent.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ describe('HeaderBarContent', () => {
const tenantNamespace2 = 'fake_tenantNamespace2';
const path = '/namespaces/:namespace/fake/path';
const selectNamespace = vi.fn();
vi.spyOn(API, 'useNamespaces').mockImplementation(() => []);
vi.spyOn(API, 'useTenantNamespaces').mockImplementation(() => [
tenantNamespace1,
tenantNamespace2
Expand Down
35 changes: 34 additions & 1 deletion src/containers/PipelineRun/PipelineRun.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ import { createIntl } from 'react-intl';
import { paths, urls } from '@tektoncd/dashboard-utils';

import { renderWithRouter } from '../../utils/test';
import * as ClusterTasksAPI from '../../api/clusterTasks';
import * as PipelineRunsAPI from '../../api/pipelineRuns';
import * as PipelinesAPI from '../../api/pipelines';
import * as TaskRunsAPI from '../../api/taskRuns';
import * as TasksAPI from '../../api/tasks';
import * as ClusterTasksAPI from '../../api/clusterTasks';
import { PipelineRunContainer } from './PipelineRun';

const intl = createIntl({
Expand Down Expand Up @@ -55,6 +56,22 @@ it('PipelineRunContainer renders not found state', async () => {
data: null,
error: null
}));
vi.spyOn(TaskRunsAPI, 'useTaskRuns').mockImplementation(() => ({
data: [],
error: null
}));
vi.spyOn(TasksAPI, 'useTasks').mockImplementation(() => ({
data: [],
error: null
}));
vi.spyOn(ClusterTasksAPI, 'useClusterTasks').mockImplementation(() => ({
data: [],
error: null
}));
vi.spyOn(PipelinesAPI, 'usePipeline').mockImplementation(() => ({
data: null,
error: null
}));

const { findByText } = renderWithRouter(
<PipelineRunContainer intl={intl} />,
Expand All @@ -73,6 +90,22 @@ it('PipelineRunContainer renders error state', async () => {
data: null,
error: 'some error'
}));
vi.spyOn(TaskRunsAPI, 'useTaskRuns').mockImplementation(() => ({
data: [],
error: null
}));
vi.spyOn(TasksAPI, 'useTasks').mockImplementation(() => ({
data: [],
error: null
}));
vi.spyOn(ClusterTasksAPI, 'useClusterTasks').mockImplementation(() => ({
data: [],
error: null
}));
vi.spyOn(PipelinesAPI, 'usePipeline').mockImplementation(() => ({
data: null,
error: null
}));

const { findByText } = renderWithRouter(
<PipelineRunContainer intl={intl} />,
Expand Down

0 comments on commit 7082782

Please sign in to comment.