Skip to content

Commit 74311f9

Browse files
authored
Fix CI tests by using jest timers (#1943)
1 parent 94021ef commit 74311f9

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

webview/src/experiments/components/App.test.tsx

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,14 @@ describe('App', () => {
672672
})
673673

674674
describe('Row Context Menu', () => {
675-
it('should be available when there is data and no running experiments', async () => {
675+
beforeAll(() => {
676+
jest.useFakeTimers()
677+
})
678+
afterAll(() => {
679+
jest.useRealTimers()
680+
})
681+
682+
it('should be available when there is data and no running experiments', () => {
676683
render(<App />)
677684

678685
fireEvent(
@@ -691,11 +698,12 @@ describe('App', () => {
691698
const target = screen.getByTestId('workspace-row')
692699
fireEvent.contextMenu(target, { bubbles: true })
693700

694-
const menu = await screen.findByTestId('messages-menu')
701+
jest.advanceTimersByTime(100)
702+
const menu = screen.getByTestId('messages-menu')
695703
expect(menu).toBeDefined()
696704
})
697705

698-
it('should present the correct options for the workspace row with no checkpoints', async () => {
706+
it('should present the correct options for the workspace row with no checkpoints', () => {
699707
render(<App />)
700708

701709
fireEvent(
@@ -711,12 +719,13 @@ describe('App', () => {
711719
const target = screen.getByTestId('workspace-row')
712720
fireEvent.contextMenu(target, { bubbles: true })
713721

714-
const menuitems = await screen.findAllByRole('menuitem')
722+
jest.advanceTimersByTime(100)
723+
const menuitems = screen.getAllByRole('menuitem')
715724
const itemLabels = menuitems.map(item => item.textContent)
716725
expect(itemLabels).toStrictEqual(['Modify and Run', 'Modify and Queue'])
717726
})
718727

719-
it('should present the correct options for the main row with checkpoints', async () => {
728+
it('should present the correct options for the main row with checkpoints', () => {
720729
render(<App />)
721730

722731
fireEvent(
@@ -735,7 +744,8 @@ describe('App', () => {
735744
const target = screen.getByText('main')
736745
fireEvent.contextMenu(target, { bubbles: true })
737746

738-
const menuitems = await screen.findAllByRole('menuitem')
747+
jest.advanceTimersByTime(100)
748+
const menuitems = screen.getAllByRole('menuitem')
739749
const itemLabels = menuitems.map(item => item.textContent)
740750
expect(itemLabels).toStrictEqual([
741751
'Modify and Resume',
@@ -744,7 +754,7 @@ describe('App', () => {
744754
])
745755
})
746756

747-
it('should present the Remove experiment option for the checkpoint tips', async () => {
757+
it('should present the Remove experiment option for the checkpoint tips', () => {
748758
render(<App />)
749759

750760
fireEvent(
@@ -763,12 +773,13 @@ describe('App', () => {
763773
const target = screen.getByText('4fb124a')
764774
fireEvent.contextMenu(target, { bubbles: true })
765775

766-
const menuitems = await screen.findAllByRole('menuitem')
776+
jest.advanceTimersByTime(100)
777+
const menuitems = screen.getAllByRole('menuitem')
767778
const itemLabels = menuitems.map(item => item.textContent)
768779
expect(itemLabels).toContain('Remove')
769780
})
770781

771-
it('should present the Remove option if multiple checkpoint tip rows are selected', async () => {
782+
it('should present the Remove option if multiple checkpoint tip rows are selected', () => {
772783
render(<App />)
773784

774785
fireEvent(
@@ -790,10 +801,11 @@ describe('App', () => {
790801
const secondRow = screen.getByTestId('timestamp___1.test-branch')
791802
fireEvent.click(secondRow)
792803

793-
const target = await screen.findByText('4fb124a')
804+
const target = screen.getByText('4fb124a')
794805
fireEvent.contextMenu(target, { bubbles: true })
795806

796-
const menuitems = await screen.findAllByRole('menuitem')
807+
jest.advanceTimersByTime(100)
808+
const menuitems = screen.getAllByRole('menuitem')
797809
const itemLabels = menuitems.map(item => item.textContent)
798810
expect(itemLabels).toContain('Remove Selected Rows')
799811
})

0 commit comments

Comments
 (0)