From 70827824bbc9a2cbfe9209d84b8ea6ebea61ac05 Mon Sep 17 00:00:00 2001 From: Alan Greene Date: Wed, 29 May 2024 14:40:41 +0100 Subject: [PATCH] Fix tests that were intermittently failing in CI 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. --- .../HeaderBarContent.test.jsx | 1 + .../PipelineRun/PipelineRun.test.jsx | 35 ++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/containers/HeaderBarContent/HeaderBarContent.test.jsx b/src/containers/HeaderBarContent/HeaderBarContent.test.jsx index dc0df2061..17dab5f24 100644 --- a/src/containers/HeaderBarContent/HeaderBarContent.test.jsx +++ b/src/containers/HeaderBarContent/HeaderBarContent.test.jsx @@ -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 diff --git a/src/containers/PipelineRun/PipelineRun.test.jsx b/src/containers/PipelineRun/PipelineRun.test.jsx index fc4398e44..7c32c5714 100644 --- a/src/containers/PipelineRun/PipelineRun.test.jsx +++ b/src/containers/PipelineRun/PipelineRun.test.jsx @@ -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({ @@ -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( , @@ -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( ,