From 3b5247f519fbcba83162608f78f87c99cbe84b3c Mon Sep 17 00:00:00 2001 From: Jamey Huffnagle Date: Thu, 22 Feb 2024 17:08:57 -0500 Subject: [PATCH] refactor(app): migrate redux jest tests to vitest --- app/package.json | 2 + .../redux/alerts/__tests__/actions.test.ts | 2 + app/src/redux/alerts/__tests__/epic.test.ts | 19 +- .../redux/alerts/__tests__/reducer.test.ts | 3 +- .../redux/alerts/__tests__/selectors.test.ts | 12 +- .../redux/analytics/__tests__/actions.test.ts | 2 + .../analytics/__tests__/alerts-events.test.ts | 2 + .../__tests__/custom-labware-events.test.ts | 2 + .../redux/analytics/__tests__/epic.test.ts | 16 +- .../redux/analytics/__tests__/hooks.test.tsx | 2 + .../analytics/__tests__/make-event.test.ts | 26 ++- .../analytics/__tests__/selectors.test.ts | 4 +- .../__tests__/system-info-events.test.ts | 30 ++-- .../calibration/__tests__/actions.test.ts | 2 + .../calibration/__tests__/reducer.test.ts | 2 + .../calibration/__tests__/selectors.test.ts | 2 + .../fetchCalibrationStatusEpic.test.ts | 6 +- .../pipette-offset/__tests__/actions.test.ts | 2 + .../__tests__/selectors.test.ts | 2 + ...fetchPipetteOffsetCalibrationsEpic.test.ts | 6 +- .../tip-length/__tests__/actions.test.ts | 3 + .../tip-length/__tests__/selectors.test.ts | 2 + .../fetchTipLengthCalibrationsEpic.test.ts | 6 +- app/src/redux/config/__tests__/config.test.ts | 7 +- app/src/redux/config/__tests__/hooks.test.tsx | 2 + .../redux/config/__tests__/selectors.test.ts | 2 + .../custom-labware/__tests__/actions.test.ts | 2 + .../custom-labware/__tests__/reducer.test.ts | 2 + .../__tests__/selectors.test.ts | 2 + .../redux/discovery/__tests__/actions.test.ts | 3 +- .../redux/discovery/__tests__/epic.test.ts | 1 + .../redux/discovery/__tests__/reducer.test.ts | 7 +- .../discovery/__tests__/selectors.test.ts | 3 +- .../redux/modules/__tests__/actions.test.ts | 2 + .../epic/__tests__/updateModuleEpic.test.ts | 34 ++-- .../networking/__tests__/actions.test.ts | 2 + .../networking/__tests__/reducer.test.ts | 2 + .../networking/__tests__/selectors.test.ts | 10 +- .../epic/__tests__/disconnectEpic.test.ts | 6 +- .../__tests__/fetchEapOptionsEpic.test.ts | 6 +- .../epic/__tests__/fetchWifiKeysEpic.test.ts | 6 +- .../epic/__tests__/postWifiKeysEpic.test.ts | 6 +- .../epic/__tests__/statusEpic.test.ts | 6 +- .../epic/__tests__/wifiConfigureEpic.test.ts | 6 +- .../redux/pipettes/__tests__/actions.test.ts | 2 + .../redux/pipettes/__tests__/reducer.test.ts | 2 + .../pipettes/__tests__/selectors.test.ts | 4 + .../fetchPipetteSettingsEpic.test.ts | 32 ++-- .../epic/__tests__/fetchPipettesEpic.test.ts | 43 ++--- .../updatePipetteSettingsEpic.test.ts | 32 ++-- .../__tests__/protocol-analysis.test.ts | 2 + .../__tests__/actions.test.ts | 2 + .../__tests__/reducer.test.ts | 2 + .../__tests__/selectors.test.ts | 2 + .../robot-admin/__tests__/actions.test.ts | 2 + .../robot-admin/__tests__/reducer.test.ts | 2 + .../robot-admin/__tests__/selectors.test.ts | 2 + .../__tests__/fetchResetOptionsEpic.test.ts | 6 +- .../epic/__tests__/resetConfigEpic.test.ts | 6 +- .../epic/__tests__/restartEpic.test.ts | 16 +- .../epic/__tests__/syncSystemTimeEpic.test.ts | 31 ++-- .../epic/__tests__/trackRestartsEpic.test.ts | 45 ++--- .../redux/robot-api/__tests__/actions.test.ts | 2 + .../redux/robot-api/__tests__/hooks.test.tsx | 2 + .../redux/robot-api/__tests__/http.test.ts | 7 +- .../redux/robot-api/__tests__/reducer.test.ts | 2 + .../robot-api/__tests__/selectors.test.ts | 2 + .../robot-api/__utils__/epic-test-mocks.ts | 34 ++-- .../robot-controls/__tests__/actions.test.ts | 2 + .../robot-controls/__tests__/reducer.test.ts | 2 + .../__tests__/selectors.test.ts | 2 + .../epic/__tests__/fetchLightsEpic.test.ts | 34 ++-- .../epic/__tests__/homeEpic.test.ts | 43 +++-- .../epic/__tests__/moveEpic.test.ts | 68 ++++---- .../epic/__tests__/updateLightsEpic.test.ts | 34 ++-- .../robot-settings/__tests__/actions.test.ts | 2 + .../robot-settings/__tests__/reducer.test.ts | 2 + .../__tests__/selectors.test.ts | 2 + .../__tests__/clearRestartPathEpic.test.ts | 25 +-- .../epic/__tests__/fetchSettingsEpic.test.ts | 42 ++--- .../epic/__tests__/updateSettingEpic.test.ts | 42 ++--- .../robot-update/__tests__/actions.test.ts | 2 + .../redux/robot-update/__tests__/epic.test.ts | 144 +++++++-------- .../robot-update/__tests__/hooks.test.ts | 35 ---- .../robot-update/__tests__/hooks.test.tsx | 41 +++++ .../robot-update/__tests__/reducer.test.ts | 2 + .../robot-update/__tests__/selectors.test.ts | 165 +++++++++--------- .../__fixtures__/calibration-check.ts | 4 +- .../sessions/__fixtures__/deck-calibration.ts | 4 +- .../pipette-offset-calibration.ts | 4 +- .../__fixtures__/tip-length-calibration.ts | 13 +- .../redux/sessions/__tests__/actions.test.ts | 2 + .../redux/sessions/__tests__/reducer.test.ts | 2 + .../createSessionCommandEpic.test.ts | 24 ++- .../epic/__tests__/createSessionEpic.test.ts | 6 +- .../epic/__tests__/deleteSessionEpic.test.ts | 6 +- .../epic/__tests__/ensureSessionEpic.test.ts | 18 +- .../__tests__/fetchAllSessionsEpic.test.ts | 6 +- .../epic/__tests__/fetchSessionEpic.test.ts | 6 +- app/src/redux/shell/__mocks__/remote.ts | 3 +- app/src/redux/shell/__tests__/actions.test.ts | 2 + app/src/redux/shell/__tests__/epics.test.ts | 34 ++-- app/src/redux/shell/__tests__/update.test.ts | 2 +- .../system-info/__tests__/actions.test.ts | 2 +- .../redux/system-info/__tests__/epic.test.ts | 23 +-- .../system-info/__tests__/reducer.test.ts | 2 +- .../system-info/__tests__/selectors.test.ts | 8 +- .../redux/system-info/__tests__/utils.test.ts | 2 + pnpm-lock.yaml | 6 + 109 files changed, 694 insertions(+), 728 deletions(-) delete mode 100644 app/src/redux/robot-update/__tests__/hooks.test.ts create mode 100644 app/src/redux/robot-update/__tests__/hooks.test.tsx diff --git a/app/package.json b/app/package.json index 0f37105cc8d..6b2bbd0029a 100644 --- a/app/package.json +++ b/app/package.json @@ -42,6 +42,7 @@ "lodash": "4.17.21", "mixpanel-browser": "2.22.1", "netmask": "2.0.2", + "node-fetch": "2.6.7", "path-to-regexp": "3.0.0", "react": "18.2.0", "react-dom": "18.2.0", @@ -71,6 +72,7 @@ "@types/file-saver": "2.0.1", "@types/jszip": "3.1.7", "@types/mixpanel-browser": "^2.35.6", + "@types/node-fetch": "2.6.11", "@types/styled-components": "^5.1.26", "axios": "^0.21.1" } diff --git a/app/src/redux/alerts/__tests__/actions.test.ts b/app/src/redux/alerts/__tests__/actions.test.ts index 9f93ab2f413..be6b9ace018 100644 --- a/app/src/redux/alerts/__tests__/actions.test.ts +++ b/app/src/redux/alerts/__tests__/actions.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import * as Config from '../../config' import * as Actions from '../actions' diff --git a/app/src/redux/alerts/__tests__/epic.test.ts b/app/src/redux/alerts/__tests__/epic.test.ts index 00c9d420fe0..90081bc21cd 100644 --- a/app/src/redux/alerts/__tests__/epic.test.ts +++ b/app/src/redux/alerts/__tests__/epic.test.ts @@ -1,3 +1,4 @@ +import { vi, describe, it, expect, beforeEach } from 'vitest' import { TestScheduler } from 'rxjs/testing' import * as Cfg from '../../config' @@ -7,9 +8,7 @@ import { alertsEpic } from '../epic' import type { Action, State } from '../../types' import type { AlertId } from '../types' -jest.mock('../../config/selectors') - -const getConfig = Cfg.getConfig as jest.MockedFunction +vi.mock('../../config/selectors') const MOCK_STATE: State = { mockState: true } as any const MOCK_ALERT_1: AlertId = 'mockAlert1' as any @@ -24,15 +23,13 @@ describe('alerts epic', () => { }) }) - afterEach(() => { - jest.resetAllMocks() - }) - it('should trigger a config:ADD_UNIQUE_VALUE to save persistent alert ignores', () => { - getConfig.mockImplementation((state: State) => { - expect(state).toEqual(MOCK_STATE) - return { alerts: { ignored: [MOCK_ALERT_1] } } as any - }) + vi.mocked( + (Cfg as any).getConfig((state: State) => { + expect(state).toEqual(MOCK_STATE) + return { alerts: { ignored: [MOCK_ALERT_1] } } + }) + ) testScheduler.run(({ hot, expectObservable }) => { const action$ = hot('-a', { diff --git a/app/src/redux/alerts/__tests__/reducer.test.ts b/app/src/redux/alerts/__tests__/reducer.test.ts index 2f9e896ea31..6412af56c28 100644 --- a/app/src/redux/alerts/__tests__/reducer.test.ts +++ b/app/src/redux/alerts/__tests__/reducer.test.ts @@ -1,5 +1,6 @@ -import * as Actions from '../actions' +import { describe, it, expect } from 'vitest' import { alertsReducer } from '../reducer' +import * as Actions from '../actions' import type { AlertId, AlertsState } from '../types' diff --git a/app/src/redux/alerts/__tests__/selectors.test.ts b/app/src/redux/alerts/__tests__/selectors.test.ts index 2e5ced3df3d..3ebb37a24bc 100644 --- a/app/src/redux/alerts/__tests__/selectors.test.ts +++ b/app/src/redux/alerts/__tests__/selectors.test.ts @@ -1,3 +1,5 @@ +import { vi, describe, it, expect } from 'vitest' + import * as Cfg from '../../config' import * as Selectors from '../selectors' @@ -5,9 +7,7 @@ import type { State } from '../../types' import type { Config } from '../../config/types' import type { AlertId } from '../types' -jest.mock('../../config/selectors') - -const getConfig = Cfg.getConfig as jest.MockedFunction +vi.mock('../../config/selectors') const MOCK_ALERT_1: AlertId = 'mockAlert1' as any const MOCK_ALERT_2: AlertId = 'mockAlert2' as any @@ -19,16 +19,12 @@ const MOCK_CONFIG: Config = { describe('alerts selectors', () => { const stubGetConfig = (state: State, value = MOCK_CONFIG) => { - getConfig.mockImplementation((s: State) => { + vi.mocked(Cfg.getConfig).mockImplementation((s: State) => { expect(s).toEqual(state) return value }) } - afterEach(() => { - jest.resetAllMocks() - }) - it('should be able to get a list of active alerts', () => { const state: State = { alerts: { active: [MOCK_ALERT_1, MOCK_ALERT_2], ignored: [] }, diff --git a/app/src/redux/analytics/__tests__/actions.test.ts b/app/src/redux/analytics/__tests__/actions.test.ts index 9aa834d9c7a..caac1c1338a 100644 --- a/app/src/redux/analytics/__tests__/actions.test.ts +++ b/app/src/redux/analytics/__tests__/actions.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import * as Actions from '../actions' import * as Constants from '../constants' diff --git a/app/src/redux/analytics/__tests__/alerts-events.test.ts b/app/src/redux/analytics/__tests__/alerts-events.test.ts index 5bfeeb75f24..b86952cdd77 100644 --- a/app/src/redux/analytics/__tests__/alerts-events.test.ts +++ b/app/src/redux/analytics/__tests__/alerts-events.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import { makeEvent } from '../make-event' import * as Alerts from '../../alerts' diff --git a/app/src/redux/analytics/__tests__/custom-labware-events.test.ts b/app/src/redux/analytics/__tests__/custom-labware-events.test.ts index 6a19b5f7b22..4075e75d857 100644 --- a/app/src/redux/analytics/__tests__/custom-labware-events.test.ts +++ b/app/src/redux/analytics/__tests__/custom-labware-events.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import { makeEvent } from '../make-event' import * as CustomLabware from '../../custom-labware' diff --git a/app/src/redux/analytics/__tests__/epic.test.ts b/app/src/redux/analytics/__tests__/epic.test.ts index 796c6f8564b..2989d7bcb84 100644 --- a/app/src/redux/analytics/__tests__/epic.test.ts +++ b/app/src/redux/analytics/__tests__/epic.test.ts @@ -1,4 +1,4 @@ -// analytics epics tests +import { vi, describe, it, expect, beforeEach, afterEach } from 'vitest' import { TestScheduler } from 'rxjs/testing' import * as Cfg from '../../config' @@ -12,10 +12,8 @@ import { analyticsEpic } from '../epic' import type { Action, State } from '../../types' -jest.mock('../make-event') -jest.mock('../mixpanel') - -const makeEventMock = makeEvent as jest.MockedFunction +vi.mock('../make-event') +vi.mock('../mixpanel') describe('analytics epics', () => { let testScheduler: TestScheduler @@ -26,7 +24,7 @@ describe('analytics epics', () => { }) }) afterEach(() => { - jest.resetAllMocks() + vi.resetAllMocks() }) describe('initializeAnalyticsEpic', () => { @@ -60,7 +58,7 @@ describe('analytics epics', () => { const event = { name: 'fooEvent', properties: {} } testScheduler.run(({ hot, expectObservable, flush }) => { - makeEventMock.mockReturnValueOnce([event] as any) + vi.mocked(makeEvent).mockReturnValueOnce([event] as any) const action$ = hot('-a', { a: action } as any) const state$ = hot('s-', { s: state } as any) @@ -77,7 +75,7 @@ describe('analytics epics', () => { const state = { config: { analytics: { optedIn: true } } } testScheduler.run(({ hot, expectObservable, flush }) => { - makeEventMock.mockReturnValueOnce([null] as any) + vi.mocked(makeEvent).mockReturnValueOnce([null] as any) const action$ = hot('-a', { a: action } as any) const state$ = hot('s-', { s: state } as any) @@ -94,7 +92,7 @@ describe('analytics epics', () => { const state = { config: null } testScheduler.run(({ hot, expectObservable, flush }) => { - makeEventMock.mockReturnValueOnce([null] as any) + vi.mocked(makeEvent).mockReturnValueOnce([null] as any) const action$ = hot('-a', { a: action } as any) const state$ = hot('s-', { s: state } as any) diff --git a/app/src/redux/analytics/__tests__/hooks.test.tsx b/app/src/redux/analytics/__tests__/hooks.test.tsx index 80edf2fa40d..1e612f7190f 100644 --- a/app/src/redux/analytics/__tests__/hooks.test.tsx +++ b/app/src/redux/analytics/__tests__/hooks.test.tsx @@ -1,3 +1,5 @@ +import { describe, it } from 'vitest' + describe('analytics hooks', () => { it.todo('replace deprecated enzyme test') }) diff --git a/app/src/redux/analytics/__tests__/make-event.test.ts b/app/src/redux/analytics/__tests__/make-event.test.ts index c7906c72de8..bd938292d5a 100644 --- a/app/src/redux/analytics/__tests__/make-event.test.ts +++ b/app/src/redux/analytics/__tests__/make-event.test.ts @@ -1,23 +1,17 @@ -// events map tests +import { vi, describe, it, expect, beforeEach } from 'vitest' + import { makeEvent } from '../make-event' import * as selectors from '../selectors' -jest.mock('../selectors') -jest.mock('../../sessions/selectors') -jest.mock('../../discovery/selectors') -jest.mock('../../pipettes/selectors') -jest.mock('../../calibration/selectors') - -const getAnalyticsSessionExitDetails = selectors.getAnalyticsSessionExitDetails as jest.MockedFunction< - typeof selectors.getAnalyticsSessionExitDetails -> -const getSessionInstrumentAnalyticsData = selectors.getSessionInstrumentAnalyticsData as jest.MockedFunction< - typeof selectors.getSessionInstrumentAnalyticsData -> +vi.mock('../selectors') +vi.mock('../../sessions/selectors') +vi.mock('../../discovery/selectors') +vi.mock('../../pipettes/selectors') +vi.mock('../../calibration/selectors') describe('analytics events map', () => { beforeEach(() => { - jest.resetAllMocks() + vi.resetAllMocks() }) describe('events with protocol data', () => { @@ -85,7 +79,7 @@ describe('analytics events map', () => { command: { command: 'calibration.exitSession' }, }, } as any - getAnalyticsSessionExitDetails.mockReturnValue({ + vi.mocked(selectors.getAnalyticsSessionExitDetails).mockReturnValue({ sessionType: 'my-session-type', step: 'session-step', }) @@ -113,7 +107,7 @@ describe('analytics events map', () => { }, }, } as any - getSessionInstrumentAnalyticsData.mockReturnValue({ + vi.mocked(selectors.getSessionInstrumentAnalyticsData).mockReturnValue({ sessionType: 'my-session-type', pipetteModel: 'my-pipette-model', }) diff --git a/app/src/redux/analytics/__tests__/selectors.test.ts b/app/src/redux/analytics/__tests__/selectors.test.ts index 63b539748d8..549da3de811 100644 --- a/app/src/redux/analytics/__tests__/selectors.test.ts +++ b/app/src/redux/analytics/__tests__/selectors.test.ts @@ -1,10 +1,12 @@ +import { vi, describe, it, expect } from 'vitest' + import * as Selectors from '../selectors' import * as SessionsSelectors from '../../sessions/selectors' import type { State } from '../../types' import type { DeckCalibrationSessionDetails } from '../../sessions/deck-calibration/types' -jest.mock('../../sessions/selectors') +vi.mock('../../sessions/selectors') describe('analytics selectors', () => { describe('analytics config selectors', () => { diff --git a/app/src/redux/analytics/__tests__/system-info-events.test.ts b/app/src/redux/analytics/__tests__/system-info-events.test.ts index 785b273a928..2529c2726bd 100644 --- a/app/src/redux/analytics/__tests__/system-info-events.test.ts +++ b/app/src/redux/analytics/__tests__/system-info-events.test.ts @@ -1,3 +1,5 @@ +import { vi, describe, it, expect, beforeEach } from 'vitest' + import { makeEvent } from '../make-event' import * as SystemInfo from '../../system-info' @@ -5,11 +7,7 @@ import * as Fixtures from '../../system-info/__fixtures__' import type { State } from '../../types' -jest.mock('../../system-info/selectors') - -const getU2EDeviceAnalyticsProps = SystemInfo.getU2EDeviceAnalyticsProps as jest.MockedFunction< - typeof SystemInfo.getU2EDeviceAnalyticsProps -> +vi.mock('../../system-info/selectors') const MOCK_STATE: State = { mockState: true } as any const MOCK_ANALYTICS_PROPS = { @@ -23,14 +21,12 @@ const MOCK_ANALYTICS_PROPS = { describe('system info analytics events', () => { beforeEach(() => { - getU2EDeviceAnalyticsProps.mockImplementation(state => { - expect(state).toBe(MOCK_STATE) - return MOCK_ANALYTICS_PROPS - }) - }) - - afterEach(() => { - jest.resetAllMocks() + vi.mocked(SystemInfo.getU2EDeviceAnalyticsProps).mockImplementation( + state => { + expect(state).toBe(MOCK_STATE) + return MOCK_ANALYTICS_PROPS + } + ) }) it('should trigger an event on systemInfo:INITIALIZED', () => { @@ -63,7 +59,7 @@ describe('system info analytics events', () => { }) it('maps no assigned IPv4 address to false', () => { - getU2EDeviceAnalyticsProps.mockReturnValue({ + vi.mocked(SystemInfo.getU2EDeviceAnalyticsProps).mockReturnValue({ ...MOCK_ANALYTICS_PROPS, 'U2E IPv4 Address': null, }) @@ -77,7 +73,7 @@ describe('system info analytics events', () => { }) it('should not trigger on systemInfo:INITIALIZED if selector returns null', () => { - getU2EDeviceAnalyticsProps.mockReturnValue(null) + vi.mocked(SystemInfo.getU2EDeviceAnalyticsProps).mockReturnValue(null) const action = SystemInfo.initialized([Fixtures.mockRealtekDevice], []) const result = makeEvent(action, MOCK_STATE) @@ -86,7 +82,7 @@ describe('system info analytics events', () => { }) it('should not trigger on systemInfo:USB_DEVICE_ADDED if selector returns null', () => { - getU2EDeviceAnalyticsProps.mockReturnValue(null) + vi.mocked(SystemInfo.getU2EDeviceAnalyticsProps).mockReturnValue(null) const action = SystemInfo.usbDeviceAdded(Fixtures.mockRealtekDevice) const result = makeEvent(action, MOCK_STATE) @@ -95,7 +91,7 @@ describe('system info analytics events', () => { }) it('should not trigger on systemInfo:NETWORK_INTERFACES_CHANGED if selector returns null', () => { - getU2EDeviceAnalyticsProps.mockReturnValue(null) + vi.mocked(SystemInfo.getU2EDeviceAnalyticsProps).mockReturnValue(null) const action = SystemInfo.networkInterfacesChanged([ Fixtures.mockNetworkInterface, diff --git a/app/src/redux/calibration/__tests__/actions.test.ts b/app/src/redux/calibration/__tests__/actions.test.ts index c0cda12a40e..30765ffb9c8 100644 --- a/app/src/redux/calibration/__tests__/actions.test.ts +++ b/app/src/redux/calibration/__tests__/actions.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import * as Fixtures from '../__fixtures__' import * as Actions from '../actions' import type { CalibrationAction } from '../types' diff --git a/app/src/redux/calibration/__tests__/reducer.test.ts b/app/src/redux/calibration/__tests__/reducer.test.ts index 8803b94fbd2..b77fbde2676 100644 --- a/app/src/redux/calibration/__tests__/reducer.test.ts +++ b/app/src/redux/calibration/__tests__/reducer.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import * as Fixtures from '../__fixtures__' import * as PipetteOffset from '../pipette-offset' import * as PipetteOffsetFixtures from '../pipette-offset/__fixtures__' diff --git a/app/src/redux/calibration/__tests__/selectors.test.ts b/app/src/redux/calibration/__tests__/selectors.test.ts index 0e849adc2fc..ce2fef807ff 100644 --- a/app/src/redux/calibration/__tests__/selectors.test.ts +++ b/app/src/redux/calibration/__tests__/selectors.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import * as Fixtures from '../__fixtures__' import * as Selectors from '../selectors' diff --git a/app/src/redux/calibration/epic/__tests__/fetchCalibrationStatusEpic.test.ts b/app/src/redux/calibration/epic/__tests__/fetchCalibrationStatusEpic.test.ts index 16339e7cdf0..2da624a8c79 100644 --- a/app/src/redux/calibration/epic/__tests__/fetchCalibrationStatusEpic.test.ts +++ b/app/src/redux/calibration/epic/__tests__/fetchCalibrationStatusEpic.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import { setupEpicTestMocks, runEpicTest } from '../../../robot-api/__utils__' import * as Fixtures from '../../__fixtures__' import * as Actions from '../../actions' @@ -9,10 +11,6 @@ const makeTriggerAction = (robotName: string) => Actions.fetchCalibrationStatus(robotName) describe('fetch calibration status epic', () => { - afterEach(() => { - jest.resetAllMocks() - }) - it('calls GET /calibration/status', () => { const mocks = setupEpicTestMocks( makeTriggerAction, diff --git a/app/src/redux/calibration/pipette-offset/__tests__/actions.test.ts b/app/src/redux/calibration/pipette-offset/__tests__/actions.test.ts index de732c2850c..d2afbea51ba 100644 --- a/app/src/redux/calibration/pipette-offset/__tests__/actions.test.ts +++ b/app/src/redux/calibration/pipette-offset/__tests__/actions.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import * as Fixtures from '../__fixtures__' import * as Actions from '../actions' import type { PipetteOffsetCalibrationsAction } from '../types' diff --git a/app/src/redux/calibration/pipette-offset/__tests__/selectors.test.ts b/app/src/redux/calibration/pipette-offset/__tests__/selectors.test.ts index fc9cd4d0c35..949b6bf0436 100644 --- a/app/src/redux/calibration/pipette-offset/__tests__/selectors.test.ts +++ b/app/src/redux/calibration/pipette-offset/__tests__/selectors.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import * as Selectors from '../selectors' import * as Fixtures from '../__fixtures__' diff --git a/app/src/redux/calibration/pipette-offset/epic/__tests__/fetchPipetteOffsetCalibrationsEpic.test.ts b/app/src/redux/calibration/pipette-offset/epic/__tests__/fetchPipetteOffsetCalibrationsEpic.test.ts index d6f1848e874..f379cbf0f6b 100644 --- a/app/src/redux/calibration/pipette-offset/epic/__tests__/fetchPipetteOffsetCalibrationsEpic.test.ts +++ b/app/src/redux/calibration/pipette-offset/epic/__tests__/fetchPipetteOffsetCalibrationsEpic.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import { setupEpicTestMocks, runEpicTest, @@ -12,10 +14,6 @@ const makeTriggerActionAllCalibrations = (robotName: string) => Actions.fetchPipetteOffsetCalibrations(robotName) describe('fetch pipette offset calibration epics', () => { - afterEach(() => { - jest.resetAllMocks() - }) - it('calls GET /calibrations/pipette_offset', () => { const mocks = setupEpicTestMocks( makeTriggerActionAllCalibrations, diff --git a/app/src/redux/calibration/tip-length/__tests__/actions.test.ts b/app/src/redux/calibration/tip-length/__tests__/actions.test.ts index af569375e19..44f09ae9f1e 100644 --- a/app/src/redux/calibration/tip-length/__tests__/actions.test.ts +++ b/app/src/redux/calibration/tip-length/__tests__/actions.test.ts @@ -1,5 +1,8 @@ +import { describe, it, expect } from 'vitest' + import * as Fixtures from '../__fixtures__' import * as Actions from '../actions' + import type { TipLengthCalibrationsAction } from '../types' interface ActionSpec { diff --git a/app/src/redux/calibration/tip-length/__tests__/selectors.test.ts b/app/src/redux/calibration/tip-length/__tests__/selectors.test.ts index 03b0f68413c..d1c11a115b8 100644 --- a/app/src/redux/calibration/tip-length/__tests__/selectors.test.ts +++ b/app/src/redux/calibration/tip-length/__tests__/selectors.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import * as Selectors from '../selectors' import * as Fixtures from '../__fixtures__' diff --git a/app/src/redux/calibration/tip-length/epic/__tests__/fetchTipLengthCalibrationsEpic.test.ts b/app/src/redux/calibration/tip-length/epic/__tests__/fetchTipLengthCalibrationsEpic.test.ts index 66afe22d64c..849c57fc37e 100644 --- a/app/src/redux/calibration/tip-length/epic/__tests__/fetchTipLengthCalibrationsEpic.test.ts +++ b/app/src/redux/calibration/tip-length/epic/__tests__/fetchTipLengthCalibrationsEpic.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import { setupEpicTestMocks, runEpicTest, @@ -12,10 +14,6 @@ const makeTriggerActionAllCalibrations = (robotName: string) => Actions.fetchTipLengthCalibrations(robotName) describe('fetch pipette offset calibration epics', () => { - afterEach(() => { - jest.resetAllMocks() - }) - it('calls GET /calibrations/tip_length', () => { const mocks = setupEpicTestMocks( makeTriggerActionAllCalibrations, diff --git a/app/src/redux/config/__tests__/config.test.ts b/app/src/redux/config/__tests__/config.test.ts index 96d088fcff9..d99eb95c36e 100644 --- a/app/src/redux/config/__tests__/config.test.ts +++ b/app/src/redux/config/__tests__/config.test.ts @@ -1,10 +1,11 @@ -// config tests +import { vi, describe, it, expect, beforeEach } from 'vitest' + import * as Cfg from '..' import { configReducer } from '../reducer' import type { State } from '../../types' -jest.mock('../../shell/remote', () => ({ +vi.mock('../../shell/remote', () => ({ remote: { INITIAL_CONFIG: { isConfig: true } }, })) @@ -12,8 +13,6 @@ describe('config', () => { let state: State beforeEach(() => { - jest.clearAllMocks() - state = { config: { devtools: true, diff --git a/app/src/redux/config/__tests__/hooks.test.tsx b/app/src/redux/config/__tests__/hooks.test.tsx index 2f41d231183..e5a9ae800c9 100644 --- a/app/src/redux/config/__tests__/hooks.test.tsx +++ b/app/src/redux/config/__tests__/hooks.test.tsx @@ -1,3 +1,5 @@ +import { describe, it } from 'vitest' + describe('config hooks', () => { it.todo('replace deprecated enzyme test') }) diff --git a/app/src/redux/config/__tests__/selectors.test.ts b/app/src/redux/config/__tests__/selectors.test.ts index 0c79c83a316..812fb7e21af 100644 --- a/app/src/redux/config/__tests__/selectors.test.ts +++ b/app/src/redux/config/__tests__/selectors.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import * as Selectors from '../selectors' import type { State } from '../../types' diff --git a/app/src/redux/custom-labware/__tests__/actions.test.ts b/app/src/redux/custom-labware/__tests__/actions.test.ts index 3ab34681602..b83e3d691e6 100644 --- a/app/src/redux/custom-labware/__tests__/actions.test.ts +++ b/app/src/redux/custom-labware/__tests__/actions.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import * as Fixtures from '../__fixtures__' import * as actions from '../actions' diff --git a/app/src/redux/custom-labware/__tests__/reducer.test.ts b/app/src/redux/custom-labware/__tests__/reducer.test.ts index 814c2257d6c..206206eb42e 100644 --- a/app/src/redux/custom-labware/__tests__/reducer.test.ts +++ b/app/src/redux/custom-labware/__tests__/reducer.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import * as Fixtures from '../__fixtures__' import { INITIAL_STATE, customLabwareReducer } from '../reducer' diff --git a/app/src/redux/custom-labware/__tests__/selectors.test.ts b/app/src/redux/custom-labware/__tests__/selectors.test.ts index acaabe26096..a3226bcbb48 100644 --- a/app/src/redux/custom-labware/__tests__/selectors.test.ts +++ b/app/src/redux/custom-labware/__tests__/selectors.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import * as Fixtures from '../__fixtures__' import * as selectors from '../selectors' diff --git a/app/src/redux/discovery/__tests__/actions.test.ts b/app/src/redux/discovery/__tests__/actions.test.ts index 7d4ff4eeca8..86ff5b71560 100644 --- a/app/src/redux/discovery/__tests__/actions.test.ts +++ b/app/src/redux/discovery/__tests__/actions.test.ts @@ -1,4 +1,5 @@ -// discovery actions test +import { describe, it, expect } from 'vitest' + import * as actions from '../actions' import type { Action } from '../../types' diff --git a/app/src/redux/discovery/__tests__/epic.test.ts b/app/src/redux/discovery/__tests__/epic.test.ts index 59527b566ca..51c12634ca0 100644 --- a/app/src/redux/discovery/__tests__/epic.test.ts +++ b/app/src/redux/discovery/__tests__/epic.test.ts @@ -1,3 +1,4 @@ +import { describe, it, expect, beforeEach } from 'vitest' import { TestScheduler } from 'rxjs/testing' import * as Shell from '../../shell' diff --git a/app/src/redux/discovery/__tests__/reducer.test.ts b/app/src/redux/discovery/__tests__/reducer.test.ts index 27571a52e5e..8b36267250c 100644 --- a/app/src/redux/discovery/__tests__/reducer.test.ts +++ b/app/src/redux/discovery/__tests__/reducer.test.ts @@ -1,14 +1,11 @@ -// discovery reducer test +import { describe, it, expect } from 'vitest' + import { discoveryReducer } from '../reducer' import type { Action } from '../../types' import type { DiscoveryState } from '../types' describe('discoveryReducer', () => { - afterEach(() => { - jest.clearAllMocks() - }) - const SPECS: Array<{ name: string action: Action diff --git a/app/src/redux/discovery/__tests__/selectors.test.ts b/app/src/redux/discovery/__tests__/selectors.test.ts index 0ce9dd1abc4..daf1c542f70 100644 --- a/app/src/redux/discovery/__tests__/selectors.test.ts +++ b/app/src/redux/discovery/__tests__/selectors.test.ts @@ -1,4 +1,5 @@ -// discovery selectors tests +import { describe, it, expect } from 'vitest' + import { mockLegacyHealthResponse, mockLegacyServerHealthResponse, diff --git a/app/src/redux/modules/__tests__/actions.test.ts b/app/src/redux/modules/__tests__/actions.test.ts index 5b1973c89f9..98f7dd07dde 100644 --- a/app/src/redux/modules/__tests__/actions.test.ts +++ b/app/src/redux/modules/__tests__/actions.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import * as Actions from '../actions' import type { ModulesAction } from '../types' diff --git a/app/src/redux/modules/epic/__tests__/updateModuleEpic.test.ts b/app/src/redux/modules/epic/__tests__/updateModuleEpic.test.ts index 0972a82babf..8a7676aff66 100644 --- a/app/src/redux/modules/epic/__tests__/updateModuleEpic.test.ts +++ b/app/src/redux/modules/epic/__tests__/updateModuleEpic.test.ts @@ -1,3 +1,4 @@ +import { vi, describe, it, expect, beforeEach } from 'vitest' import { TestScheduler } from 'rxjs/testing' import * as RobotApiHttp from '../../../robot-api/http' @@ -10,20 +11,12 @@ import { modulesEpic } from '../../epic' import type { Action, State } from '../../../types' -jest.mock('../../../robot-api/http') -jest.mock('../../../discovery/selectors') +vi.mock('../../../robot-api/http') +vi.mock('../../../discovery/selectors') const mockState: State = { state: true } as any const { mockRobot } = Fixtures -const mockFetchRobotApi = RobotApiHttp.fetchRobotApi as jest.MockedFunction< - typeof RobotApiHttp.fetchRobotApi -> - -const mockGetRobotByName = DiscoverySelectors.getRobotByName as jest.MockedFunction< - typeof DiscoverySelectors.getRobotByName -> - describe('updateModuleEpic', () => { let testScheduler: TestScheduler @@ -34,20 +27,18 @@ describe('updateModuleEpic', () => { } beforeEach(() => { - mockGetRobotByName.mockReturnValue(mockRobot as any) + vi.mocked(DiscoverySelectors.getRobotByName).mockReturnValue( + mockRobot as any + ) testScheduler = new TestScheduler((actual, expected) => { expect(actual).toEqual(expected) }) }) - afterEach(() => { - jest.resetAllMocks() - }) - it('calls POST /modules/{serial}/update', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('r', { r: Fixtures.mockUpdateModuleSuccess }) ) @@ -58,8 +49,11 @@ describe('updateModuleEpic', () => { expectObservable(output$) flush() - expect(mockGetRobotByName).toHaveBeenCalledWith(mockState, mockRobot.name) - expect(mockFetchRobotApi).toHaveBeenCalledWith(mockRobot, { + expect(DiscoverySelectors.getRobotByName).toHaveBeenCalledWith( + mockState, + mockRobot.name + ) + expect(RobotApiHttp.fetchRobotApi).toHaveBeenCalledWith(mockRobot, { method: 'POST', path: '/modules/abc123/update', }) @@ -68,7 +62,7 @@ describe('updateModuleEpic', () => { it('maps successful response to SEND_MODULE_COMMAND_SUCCESS', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('r', { r: Fixtures.mockUpdateModuleSuccess }) ) @@ -89,7 +83,7 @@ describe('updateModuleEpic', () => { it('maps failed response to SEND_MODULE_COMMAND_FAILURE', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('r', { r: Fixtures.mockUpdateModuleFailure }) ) diff --git a/app/src/redux/networking/__tests__/actions.test.ts b/app/src/redux/networking/__tests__/actions.test.ts index 2c343fb8162..46cfd124520 100644 --- a/app/src/redux/networking/__tests__/actions.test.ts +++ b/app/src/redux/networking/__tests__/actions.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import { mockRobot, mockRequestMeta } from '../../robot-api/__fixtures__' import * as Actions from '../actions' import * as Fixtures from '../__fixtures__' diff --git a/app/src/redux/networking/__tests__/reducer.test.ts b/app/src/redux/networking/__tests__/reducer.test.ts index 187a30b31a7..bfe9a1191fd 100644 --- a/app/src/redux/networking/__tests__/reducer.test.ts +++ b/app/src/redux/networking/__tests__/reducer.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import * as Fixtures from '../__fixtures__' import { networkingReducer } from '../reducer' import * as Actions from '../actions' diff --git a/app/src/redux/networking/__tests__/selectors.test.ts b/app/src/redux/networking/__tests__/selectors.test.ts index 53a02cddcfd..6b2ba5c9e68 100644 --- a/app/src/redux/networking/__tests__/selectors.test.ts +++ b/app/src/redux/networking/__tests__/selectors.test.ts @@ -1,3 +1,5 @@ +import { vi, describe, it, expect } from 'vitest' + import noop from 'lodash/noop' import * as Selectors from '../selectors' import * as Constants from '../constants' @@ -5,8 +7,8 @@ import * as Fixtures from '../__fixtures__' import type { State } from '../../types' -jest.mock('../../config/selectors') -jest.mock('../../discovery/selectors') +vi.mock('../../config/selectors') +vi.mock('../../discovery/selectors') interface SelectorSpec { name: string @@ -18,10 +20,6 @@ interface SelectorSpec { } describe('robot settings selectors', () => { - afterEach(() => { - jest.resetAllMocks() - }) - const SPECS: SelectorSpec[] = [ { name: 'getInternetStatus returns null if unavailable', diff --git a/app/src/redux/networking/epic/__tests__/disconnectEpic.test.ts b/app/src/redux/networking/epic/__tests__/disconnectEpic.test.ts index 3453f876aa4..06d211cad62 100644 --- a/app/src/redux/networking/epic/__tests__/disconnectEpic.test.ts +++ b/app/src/redux/networking/epic/__tests__/disconnectEpic.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import { setupEpicTestMocks, runEpicTest } from '../../../robot-api/__utils__' import * as Fixtures from '../../__fixtures__' import * as Actions from '../../actions' @@ -9,10 +11,6 @@ const makeTriggerAction = (robotName: string) => Actions.postWifiDisconnect(robotName, 'network-name') describe('networking disconnectEpic', () => { - afterEach(() => { - jest.resetAllMocks() - }) - it('calls POST /wifi/disconnect', () => { const mocks = setupEpicTestMocks( makeTriggerAction, diff --git a/app/src/redux/networking/epic/__tests__/fetchEapOptionsEpic.test.ts b/app/src/redux/networking/epic/__tests__/fetchEapOptionsEpic.test.ts index 7ef7b7db242..1508be07bd4 100644 --- a/app/src/redux/networking/epic/__tests__/fetchEapOptionsEpic.test.ts +++ b/app/src/redux/networking/epic/__tests__/fetchEapOptionsEpic.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import { setupEpicTestMocks, runEpicTest } from '../../../robot-api/__utils__' import * as Fixtures from '../../__fixtures__' import * as Actions from '../../actions' @@ -9,10 +11,6 @@ const makeTriggerAction = (robotName: string) => Actions.fetchEapOptions(robotName) describe('networking fetch eap option epic', () => { - afterEach(() => { - jest.resetAllMocks() - }) - it('calls GET /wifi/eap-options', () => { const mocks = setupEpicTestMocks( makeTriggerAction, diff --git a/app/src/redux/networking/epic/__tests__/fetchWifiKeysEpic.test.ts b/app/src/redux/networking/epic/__tests__/fetchWifiKeysEpic.test.ts index 2ef826c5b98..4a594167794 100644 --- a/app/src/redux/networking/epic/__tests__/fetchWifiKeysEpic.test.ts +++ b/app/src/redux/networking/epic/__tests__/fetchWifiKeysEpic.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import { setupEpicTestMocks, runEpicTest } from '../../../robot-api/__utils__' import * as Fixtures from '../../__fixtures__' import * as Actions from '../../actions' @@ -9,10 +11,6 @@ const makeTriggerAction = (robotName: string) => Actions.fetchWifiKeys(robotName) describe('networking fetch wifi keys epic', () => { - afterEach(() => { - jest.resetAllMocks() - }) - it('calls GET /wifi/keys', () => { const mocks = setupEpicTestMocks( makeTriggerAction, diff --git a/app/src/redux/networking/epic/__tests__/postWifiKeysEpic.test.ts b/app/src/redux/networking/epic/__tests__/postWifiKeysEpic.test.ts index f1009a7407b..6edbfe5aa0c 100644 --- a/app/src/redux/networking/epic/__tests__/postWifiKeysEpic.test.ts +++ b/app/src/redux/networking/epic/__tests__/postWifiKeysEpic.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import { setupEpicTestMocks, runEpicTest } from '../../../robot-api/__utils__' import * as Fixtures from '../../__fixtures__' import * as Actions from '../../actions' @@ -10,10 +12,6 @@ const makeTriggerAction = (robotName: string) => Actions.postWifiKeys(robotName, keyFile) describe('networking post wifi keys epic', () => { - afterEach(() => { - jest.resetAllMocks() - }) - it('calls POST /wifi/keys', () => { const mocks = setupEpicTestMocks( makeTriggerAction, diff --git a/app/src/redux/networking/epic/__tests__/statusEpic.test.ts b/app/src/redux/networking/epic/__tests__/statusEpic.test.ts index 16a09cba35a..c32357cce86 100644 --- a/app/src/redux/networking/epic/__tests__/statusEpic.test.ts +++ b/app/src/redux/networking/epic/__tests__/statusEpic.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import { setupEpicTestMocks, runEpicTest } from '../../../robot-api/__utils__' import * as Fixtures from '../../__fixtures__' import * as Actions from '../../actions' @@ -8,10 +10,6 @@ import type { Action } from '../../../types' const makeTriggerAction = (robotName: string) => Actions.fetchStatus(robotName) describe('networking statusEpic', () => { - afterEach(() => { - jest.resetAllMocks() - }) - it('calls GET /networking/status', () => { const mocks = setupEpicTestMocks( makeTriggerAction, diff --git a/app/src/redux/networking/epic/__tests__/wifiConfigureEpic.test.ts b/app/src/redux/networking/epic/__tests__/wifiConfigureEpic.test.ts index f2588331893..48b4a5b8ef5 100644 --- a/app/src/redux/networking/epic/__tests__/wifiConfigureEpic.test.ts +++ b/app/src/redux/networking/epic/__tests__/wifiConfigureEpic.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import { setupEpicTestMocks, runEpicTest } from '../../../robot-api/__utils__' import * as Discovery from '../../../discovery' @@ -14,10 +16,6 @@ const makeTriggerAction = (robotName: string) => }) describe('networking wifiConfigureEpic', () => { - afterEach(() => { - jest.resetAllMocks() - }) - it('calls POST /wifi/configure with options', () => { const mocks = setupEpicTestMocks( makeTriggerAction, diff --git a/app/src/redux/pipettes/__tests__/actions.test.ts b/app/src/redux/pipettes/__tests__/actions.test.ts index d37161a9e7c..7cd91876d5c 100644 --- a/app/src/redux/pipettes/__tests__/actions.test.ts +++ b/app/src/redux/pipettes/__tests__/actions.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import * as Actions from '../actions' import * as Fixtures from '../__fixtures__' diff --git a/app/src/redux/pipettes/__tests__/reducer.test.ts b/app/src/redux/pipettes/__tests__/reducer.test.ts index 42abb4af91d..619a8b4350b 100644 --- a/app/src/redux/pipettes/__tests__/reducer.test.ts +++ b/app/src/redux/pipettes/__tests__/reducer.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import * as Fixtures from '../__fixtures__' import { pipettesReducer } from '../reducer' diff --git a/app/src/redux/pipettes/__tests__/selectors.test.ts b/app/src/redux/pipettes/__tests__/selectors.test.ts index 9e136f3ce74..b751b374788 100644 --- a/app/src/redux/pipettes/__tests__/selectors.test.ts +++ b/app/src/redux/pipettes/__tests__/selectors.test.ts @@ -1,8 +1,12 @@ +import { describe, it, expect } from 'vitest' + import { getPipetteModelSpecs } from '@opentrons/shared-data' + import * as POCFixtures from '../../calibration/pipette-offset/__fixtures__' import * as TLCFixtures from '../../calibration/tip-length/__fixtures__' import * as Selectors from '../selectors' import * as Fixtures from '../__fixtures__' + import type { State } from '../../types' interface SelectorSpec { diff --git a/app/src/redux/pipettes/epic/__tests__/fetchPipetteSettingsEpic.test.ts b/app/src/redux/pipettes/epic/__tests__/fetchPipetteSettingsEpic.test.ts index 5b52c0ab445..6f5c6d1fd8b 100644 --- a/app/src/redux/pipettes/epic/__tests__/fetchPipetteSettingsEpic.test.ts +++ b/app/src/redux/pipettes/epic/__tests__/fetchPipetteSettingsEpic.test.ts @@ -1,3 +1,5 @@ +import { vi, describe, it, expect, beforeEach } from 'vitest' + import { TestScheduler } from 'rxjs/testing' import * as RobotApiHttp from '../../../robot-api/http' @@ -11,35 +13,25 @@ import { pipettesEpic } from '../../epic' import type { Action, State } from '../../../types' import type { RobotApiRequestMeta } from '../../../robot-api/types' -jest.mock('../../../robot-api/http') -jest.mock('../../../discovery/selectors') +vi.mock('../../../robot-api/http') +vi.mock('../../../discovery/selectors') const mockState: State = { state: true } as any const { mockRobot } = Fixtures -const mockFetchRobotApi = RobotApiHttp.fetchRobotApi as jest.MockedFunction< - typeof RobotApiHttp.fetchRobotApi -> - -const mockGetRobotByName = DiscoverySelectors.getRobotByName as jest.MockedFunction< - typeof DiscoverySelectors.getRobotByName -> - describe('fetchPipetteSettingsEpic', () => { let testScheduler: TestScheduler beforeEach(() => { - mockGetRobotByName.mockReturnValue(mockRobot as any) + vi.mocked(DiscoverySelectors.getRobotByName).mockReturnValue( + mockRobot as any + ) testScheduler = new TestScheduler((actual, expected) => { expect(actual).toEqual(expected) }) }) - afterEach(() => { - jest.resetAllMocks() - }) - describe('handles FETCH_PIPETTE_SETTINGS', () => { const meta: RobotApiRequestMeta = { requestId: '1234' } as any const action: Types.FetchPipetteSettingsAction = { @@ -49,7 +41,7 @@ describe('fetchPipetteSettingsEpic', () => { it('calls GET /settings/pipettes', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('r', { r: Fixtures.mockFetchPipetteSettingsSuccess }) ) @@ -60,11 +52,11 @@ describe('fetchPipetteSettingsEpic', () => { expectObservable(output$) flush() - expect(mockGetRobotByName).toHaveBeenCalledWith( + expect(DiscoverySelectors.getRobotByName).toHaveBeenCalledWith( mockState, mockRobot.name ) - expect(mockFetchRobotApi).toHaveBeenCalledWith(mockRobot, { + expect(RobotApiHttp.fetchRobotApi).toHaveBeenCalledWith(mockRobot, { method: 'GET', path: '/settings/pipettes', }) @@ -73,7 +65,7 @@ describe('fetchPipetteSettingsEpic', () => { it('maps successful response to FETCH_PIPETTE_SETTINGS_SUCCESS', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('r', { r: Fixtures.mockFetchPipetteSettingsSuccess }) ) @@ -93,7 +85,7 @@ describe('fetchPipetteSettingsEpic', () => { it('maps failed response to FETCH_PIPETTE_SETTINGS_FAILURE', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('r', { r: Fixtures.mockFetchPipetteSettingsFailure }) ) diff --git a/app/src/redux/pipettes/epic/__tests__/fetchPipettesEpic.test.ts b/app/src/redux/pipettes/epic/__tests__/fetchPipettesEpic.test.ts index 83aa5de61ff..ee07b47a82e 100644 --- a/app/src/redux/pipettes/epic/__tests__/fetchPipettesEpic.test.ts +++ b/app/src/redux/pipettes/epic/__tests__/fetchPipettesEpic.test.ts @@ -1,3 +1,5 @@ +import { vi, describe, it, expect, beforeEach } from 'vitest' + import { TestScheduler } from 'rxjs/testing' import * as RobotApiHttp from '../../../robot-api/http' @@ -11,35 +13,25 @@ import { pipettesEpic } from '../../epic' import type { Action, State } from '../../../types' import type { RobotApiResponse } from '../../../robot-api/types' -jest.mock('../../../robot-api/http') -jest.mock('../../../discovery/selectors') +vi.mock('../../../robot-api/http') +vi.mock('../../../discovery/selectors') const mockState: State = { state: true } as any const { mockRobot } = Fixtures -const mockFetchRobotApi = RobotApiHttp.fetchRobotApi as jest.MockedFunction< - typeof RobotApiHttp.fetchRobotApi -> - -const mockGetRobotByName = DiscoverySelectors.getRobotByName as jest.MockedFunction< - typeof DiscoverySelectors.getRobotByName -> - describe('fetchPipettesEpic', () => { let testScheduler: TestScheduler beforeEach(() => { - mockGetRobotByName.mockReturnValue(mockRobot as any) + vi.mocked(DiscoverySelectors.getRobotByName).mockReturnValue( + mockRobot as any + ) testScheduler = new TestScheduler((actual, expected) => { expect(actual).toEqual(expected) }) }) - afterEach(() => { - jest.resetAllMocks() - }) - describe('handles FETCH_PIPETTES', () => { const meta = { requestId: '1234' } as any const action: Types.FetchPipettesAction = { @@ -49,7 +41,7 @@ describe('fetchPipettesEpic', () => { it('calls GET /pipettes', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('r', { r: Fixtures.mockFetchPipettesSuccess }) ) @@ -60,21 +52,24 @@ describe('fetchPipettesEpic', () => { expectObservable(output$) flush() - expect(mockGetRobotByName).toHaveBeenCalledWith( + expect(DiscoverySelectors.getRobotByName).toHaveBeenCalledWith( mockState, mockRobot.name ) - expect(mockFetchRobotApi).toHaveBeenCalledWith(mockRobot, { - method: 'GET', - path: '/pipettes', - query: { refresh: true }, - }) + expect(vi.mocked(RobotApiHttp.fetchRobotApi)).toHaveBeenCalledWith( + mockRobot, + { + method: 'GET', + path: '/pipettes', + query: { refresh: true }, + } + ) }) }) it('maps successful response to FETCH_PIPETTES_SUCCESS', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('r', { r: Fixtures.mockFetchPipettesSuccess }) ) @@ -94,7 +89,7 @@ describe('fetchPipettesEpic', () => { it('maps failed response to FETCH_PIPETTES_FAILURE', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('r', { r: Fixtures.mockFetchPipettesFailure }) ) diff --git a/app/src/redux/pipettes/epic/__tests__/updatePipetteSettingsEpic.test.ts b/app/src/redux/pipettes/epic/__tests__/updatePipetteSettingsEpic.test.ts index ed55c7c3e78..1133ba82360 100644 --- a/app/src/redux/pipettes/epic/__tests__/updatePipetteSettingsEpic.test.ts +++ b/app/src/redux/pipettes/epic/__tests__/updatePipetteSettingsEpic.test.ts @@ -1,3 +1,5 @@ +import { vi, describe, it, expect, beforeEach } from 'vitest' + import { TestScheduler } from 'rxjs/testing' import * as RobotApiHttp from '../../../robot-api/http' @@ -11,35 +13,25 @@ import { pipettesEpic } from '../../epic' import type { Action, State } from '../../../types' import type { RobotApiRequestMeta } from '../../../robot-api/types' -jest.mock('../../../robot-api/http') -jest.mock('../../../discovery/selectors') +vi.mock('../../../robot-api/http') +vi.mock('../../../discovery/selectors') const mockState: State = { state: true } as any const { mockRobot, mockAttachedPipette: mockPipette } = Fixtures -const mockFetchRobotApi = RobotApiHttp.fetchRobotApi as jest.MockedFunction< - typeof RobotApiHttp.fetchRobotApi -> - -const mockGetRobotByName = DiscoverySelectors.getRobotByName as jest.MockedFunction< - typeof DiscoverySelectors.getRobotByName -> - describe('updatePipetteSettingsEpic', () => { let testScheduler: TestScheduler beforeEach(() => { - mockGetRobotByName.mockReturnValue(mockRobot as any) + vi.mocked(DiscoverySelectors.getRobotByName).mockReturnValue( + mockRobot as any + ) testScheduler = new TestScheduler((actual, expected) => { expect(actual).toEqual(expected) }) }) - afterEach(() => { - jest.resetAllMocks() - }) - describe('handles UPDATE_PIPETTE_SETTINGS', () => { const meta: RobotApiRequestMeta = { requestId: '1234' } as any const action: Types.UpdatePipetteSettingsAction = { @@ -52,7 +44,7 @@ describe('updatePipetteSettingsEpic', () => { it('calls PATCH /settings/pipettes/:pipetteId', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('r', { r: Fixtures.mockFetchPipetteSettingsSuccess }) ) @@ -63,11 +55,11 @@ describe('updatePipetteSettingsEpic', () => { expectObservable(output$) flush() - expect(mockGetRobotByName).toHaveBeenCalledWith( + expect(DiscoverySelectors.getRobotByName).toHaveBeenCalledWith( mockState, mockRobot.name ) - expect(mockFetchRobotApi).toHaveBeenCalledWith(mockRobot, { + expect(RobotApiHttp.fetchRobotApi).toHaveBeenCalledWith(mockRobot, { method: 'PATCH', path: `/settings/pipettes/${mockPipette.id}`, body: { fields: { fieldA: { value: 42 }, fieldB: null } }, @@ -77,7 +69,7 @@ describe('updatePipetteSettingsEpic', () => { it('maps successful response to UPDATE_PIPETTE_SETTINGS_SUCCESS', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('r', { r: Fixtures.mockUpdatePipetteSettingsSuccess }) ) @@ -98,7 +90,7 @@ describe('updatePipetteSettingsEpic', () => { it('maps failed response to UPDATE_PIPETTE_SETTINGS_FAILURE', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('r', { r: Fixtures.mockUpdatePipetteSettingsFailure }) ) diff --git a/app/src/redux/protocol-analysis/__tests__/protocol-analysis.test.ts b/app/src/redux/protocol-analysis/__tests__/protocol-analysis.test.ts index 10085570388..1a2f612ea50 100644 --- a/app/src/redux/protocol-analysis/__tests__/protocol-analysis.test.ts +++ b/app/src/redux/protocol-analysis/__tests__/protocol-analysis.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import * as ProtocolAnalysis from '..' describe('config', () => { diff --git a/app/src/redux/protocol-storage/__tests__/actions.test.ts b/app/src/redux/protocol-storage/__tests__/actions.test.ts index 1fa2cebe1b7..63c62959ec9 100644 --- a/app/src/redux/protocol-storage/__tests__/actions.test.ts +++ b/app/src/redux/protocol-storage/__tests__/actions.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import * as Fixtures from '../__fixtures__' import * as actions from '../actions' diff --git a/app/src/redux/protocol-storage/__tests__/reducer.test.ts b/app/src/redux/protocol-storage/__tests__/reducer.test.ts index fd8e9907e3c..f8e9e9b0301 100644 --- a/app/src/redux/protocol-storage/__tests__/reducer.test.ts +++ b/app/src/redux/protocol-storage/__tests__/reducer.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import * as Fixtures from '../__fixtures__' import { INITIAL_STATE, protocolStorageReducer } from '../reducer' diff --git a/app/src/redux/protocol-storage/__tests__/selectors.test.ts b/app/src/redux/protocol-storage/__tests__/selectors.test.ts index 88f34d22296..a5f06cbd313 100644 --- a/app/src/redux/protocol-storage/__tests__/selectors.test.ts +++ b/app/src/redux/protocol-storage/__tests__/selectors.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import * as Fixtures from '../__fixtures__' import * as selectors from '../selectors' diff --git a/app/src/redux/robot-admin/__tests__/actions.test.ts b/app/src/redux/robot-admin/__tests__/actions.test.ts index e353ed792ce..1d4903756bb 100644 --- a/app/src/redux/robot-admin/__tests__/actions.test.ts +++ b/app/src/redux/robot-admin/__tests__/actions.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import * as Actions from '../actions' import type { RobotAdminAction } from '../types' diff --git a/app/src/redux/robot-admin/__tests__/reducer.test.ts b/app/src/redux/robot-admin/__tests__/reducer.test.ts index 01bd8e76d0d..816ec30b3f4 100644 --- a/app/src/redux/robot-admin/__tests__/reducer.test.ts +++ b/app/src/redux/robot-admin/__tests__/reducer.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import { robotAdminReducer } from '../reducer' import type { PerRobotAdminState } from '../types' diff --git a/app/src/redux/robot-admin/__tests__/selectors.test.ts b/app/src/redux/robot-admin/__tests__/selectors.test.ts index 2259581dca3..77d1e24950c 100644 --- a/app/src/redux/robot-admin/__tests__/selectors.test.ts +++ b/app/src/redux/robot-admin/__tests__/selectors.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import { CONNECTABLE, REACHABLE } from '../../discovery' import { getRobotRestarting, diff --git a/app/src/redux/robot-admin/epic/__tests__/fetchResetOptionsEpic.test.ts b/app/src/redux/robot-admin/epic/__tests__/fetchResetOptionsEpic.test.ts index 76b087dfd16..fc52d12b39f 100644 --- a/app/src/redux/robot-admin/epic/__tests__/fetchResetOptionsEpic.test.ts +++ b/app/src/redux/robot-admin/epic/__tests__/fetchResetOptionsEpic.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import { setupEpicTestMocks, runEpicTest } from '../../../robot-api/__utils__' import * as Fixtures from '../../__fixtures__' import * as Actions from '../../actions' @@ -6,10 +8,6 @@ import { fetchResetOptionsEpic } from '../fetchResetOptionsEpic' import type { Action } from '../../../types' describe('robotAdminEpic handles fetching "factory reset" options', () => { - afterEach(() => { - jest.resetAllMocks() - }) - it('calls GET /settings/reset/options on FETCH_RESET_CONFIG_OPTIONS', () => { const mocks = setupEpicTestMocks( robotName => Actions.fetchResetConfigOptions(robotName), diff --git a/app/src/redux/robot-admin/epic/__tests__/resetConfigEpic.test.ts b/app/src/redux/robot-admin/epic/__tests__/resetConfigEpic.test.ts index 619df83abd5..a79f1c674ae 100644 --- a/app/src/redux/robot-admin/epic/__tests__/resetConfigEpic.test.ts +++ b/app/src/redux/robot-admin/epic/__tests__/resetConfigEpic.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import { setupEpicTestMocks, runEpicTest } from '../../../robot-api/__utils__' import * as Fixtures from '../../__fixtures__' import * as Actions from '../../actions' @@ -12,10 +14,6 @@ const makeResetConfigAction = (robotName: string) => }) describe('robotAdminEpic handles performing a "factory reset"', () => { - afterEach(() => { - jest.resetAllMocks() - }) - it('calls POST /settings/reset on RESET_CONFIG', () => { const mocks = setupEpicTestMocks( makeResetConfigAction, diff --git a/app/src/redux/robot-admin/epic/__tests__/restartEpic.test.ts b/app/src/redux/robot-admin/epic/__tests__/restartEpic.test.ts index b83c7db22af..2c3f1fef0c2 100644 --- a/app/src/redux/robot-admin/epic/__tests__/restartEpic.test.ts +++ b/app/src/redux/robot-admin/epic/__tests__/restartEpic.test.ts @@ -1,3 +1,5 @@ +import { vi, describe, it, expect } from 'vitest' + import { setupEpicTestMocks, runEpicTest } from '../../../robot-api/__utils__' import * as SettingsSelectors from '../../../robot-settings/selectors' @@ -8,17 +10,9 @@ import { restartEpic, startDiscoveryOnRestartEpic } from '../restartEpic' import type { Action } from '../../../types' -jest.mock('../../../robot-settings/selectors') - -const mockGetRestartPath = SettingsSelectors.getRobotRestartPath as jest.MockedFunction< - typeof SettingsSelectors.getRobotRestartPath -> +vi.mock('../../../robot-settings/selectors') describe('robotAdminEpic handles restarting', () => { - afterEach(() => { - jest.resetAllMocks() - }) - it('calls POST /server/restart', () => { const mocks = setupEpicTestMocks( robotName => Actions.restartRobot(robotName), @@ -46,7 +40,7 @@ describe('robotAdminEpic handles restarting', () => { Fixtures.mockRestartSuccess ) - mockGetRestartPath.mockReturnValue('/restart') + vi.mocked(SettingsSelectors.getRobotRestartPath).mockReturnValue('/restart') runEpicTest(mocks, ({ hot, expectObservable, flush }) => { const action$ = hot('--a', { a: mocks.action }) @@ -56,7 +50,7 @@ describe('robotAdminEpic handles restarting', () => { expectObservable(output$) flush() - expect(mockGetRestartPath).toHaveBeenCalledWith( + expect(SettingsSelectors.getRobotRestartPath).toHaveBeenCalledWith( mocks.state, mocks.robot.name ) diff --git a/app/src/redux/robot-admin/epic/__tests__/syncSystemTimeEpic.test.ts b/app/src/redux/robot-admin/epic/__tests__/syncSystemTimeEpic.test.ts index afad1465fb5..9d3f4cab788 100644 --- a/app/src/redux/robot-admin/epic/__tests__/syncSystemTimeEpic.test.ts +++ b/app/src/redux/robot-admin/epic/__tests__/syncSystemTimeEpic.test.ts @@ -1,3 +1,5 @@ +import { vi, describe, it, expect, afterEach } from 'vitest' + import cloneDeep from 'lodash/cloneDeep' import set from 'lodash/set' import get from 'lodash/get' @@ -33,7 +35,7 @@ const createEpicOutput = ( describe('syncSystemTimeEpic', () => { afterEach(() => { - jest.resetAllMocks() + vi.resetAllMocks() }) it("should fetch the robot's time on sync system time request", () => { @@ -59,18 +61,20 @@ describe('syncSystemTimeEpic', () => { const mocks = setupEpicTestMocks(syncSystemTime) runEpicTest(mocks, ({ hot, cold, expectObservable, flush }) => { - mocks.fetchRobotApi.mockImplementation((robot, request) => { - if (request.method === GET && request.path === '/system/time') { - const robotDate = subSeconds(new Date(), 61) - return cold('r', { r: createTimeSuccessResponse(robotDate) }) - } - - if (request.method === PUT && request.path === '/system/time') { - return cold('r', { r: createTimeSuccessResponse(new Date()) }) + ;(mocks as any).fetchRobotApi.mockImplementation( + (robot: any, request: any) => { + if (request.method === GET && request.path === '/system/time') { + const robotDate = subSeconds(new Date(), 61) + return cold('r', { r: createTimeSuccessResponse(robotDate) }) + } + + if (request.method === PUT && request.path === '/system/time') { + return cold('r', { r: createTimeSuccessResponse(new Date()) }) + } + + return cold('#') } - - return cold('#') - }) + ) const output$ = createEpicOutput(mocks, hot) expectObservable(output$, '---') @@ -88,12 +92,11 @@ describe('syncSystemTimeEpic', () => { }) const updatedTime = get( - mocks.fetchRobotApi.mock.calls[1][1], + (mocks as any).fetchRobotApi.mock.calls[1][1], 'body.data.systemTime' ) expect( - // @ts-expect-error Math.abs(differenceInSeconds(new Date(), parseISO(updatedTime))) ).toBe(0) }) diff --git a/app/src/redux/robot-admin/epic/__tests__/trackRestartsEpic.test.ts b/app/src/redux/robot-admin/epic/__tests__/trackRestartsEpic.test.ts index 6cf000a7da4..c4ed86d5c0e 100644 --- a/app/src/redux/robot-admin/epic/__tests__/trackRestartsEpic.test.ts +++ b/app/src/redux/robot-admin/epic/__tests__/trackRestartsEpic.test.ts @@ -1,4 +1,5 @@ -import { when } from 'jest-when' +import { vi, describe, it, expect, beforeEach } from 'vitest' +import { when } from 'vitest-when' import { setupEpicTestMocks, runEpicTest } from '../../../robot-api/__utils__' import * as Actions from '../../actions' @@ -13,23 +14,13 @@ import type { } from '../../../discovery/types' import type { Action } from '../../../types' -jest.mock('../../../discovery/selectors') -jest.mock('../../selectors') +vi.mock('../../../discovery/selectors') +vi.mock('../../selectors') -const getNextRestartStatus = robotAdminSelectors.getNextRestartStatus as jest.MockedFunction< - typeof robotAdminSelectors.getNextRestartStatus -> -const getDiscoveredRobots = discoverySelectors.getDiscoveredRobots as jest.MockedFunction< - typeof discoverySelectors.getDiscoveredRobots -> describe('robotAdminEpic tracks restarting state', () => { beforeEach(() => { - getNextRestartStatus.mockReturnValue(null) - getDiscoveredRobots.mockReturnValue([]) - }) - - afterEach(() => { - jest.resetAllMocks() + vi.mocked(robotAdminSelectors.getNextRestartStatus).mockReturnValue(null) + vi.mocked(discoverySelectors.getDiscoveredRobots).mockReturnValue([]) }) it('dispatches a RESTART_STATUS_CHANGED action on restart success', () => { @@ -38,8 +29,8 @@ describe('robotAdminEpic tracks restarting state', () => { ) when(mocks.getRobotByName) - .calledWith(mocks.state, mocks.robot.name) - .mockReturnValue(mocks.robot as any) + .calledWith((mocks as any).state, (mocks as any).robot.name) + .thenReturn(mocks.robot as any) runEpicTest(mocks, ({ hot, expectObservable }) => { const action$ = hot('--a', { a: mocks.action }) @@ -63,8 +54,8 @@ describe('robotAdminEpic tracks restarting state', () => { ) when(mocks.getRobotByName) - .calledWith(mocks.state, mocks.robot.name) - .mockReturnValue({ + .calledWith((mocks as any).state, (mocks as any).robot.name) + .thenReturn({ ...mocks.robot, serverHealth: { bootId: 'previous-boot-id' }, } as any) @@ -109,15 +100,15 @@ describe('robotAdminEpic tracks restarting state', () => { serverHealth: { bootId: 'robot-3-boot' }, } - when(getDiscoveredRobots) + when(vi.mocked(discoverySelectors.getDiscoveredRobots)) .calledWith(mocks.state) - .mockReturnValue([ + .thenReturn([ robot1 as DiscoveredRobot, robot2 as DiscoveredRobot, robot3 as DiscoveredRobot, ]) - when(getNextRestartStatus) + when(vi.mocked(robotAdminSelectors.getNextRestartStatus)) .calledWith( mocks.state, robot1.name, @@ -125,9 +116,9 @@ describe('robotAdminEpic tracks restarting state', () => { 'robot-1-boot', expect.any(Date) ) - .mockReturnValue('restart-in-progress') + .thenReturn('restart-in-progress') - when(getNextRestartStatus) + when(vi.mocked(robotAdminSelectors.getNextRestartStatus)) .calledWith( mocks.state, robot2.name, @@ -135,9 +126,9 @@ describe('robotAdminEpic tracks restarting state', () => { 'robot-2-boot', expect.any(Date) ) - .mockReturnValue(null) + .thenReturn(null) - when(getNextRestartStatus) + when(vi.mocked(robotAdminSelectors.getNextRestartStatus)) .calledWith( mocks.state, robot3.name, @@ -145,7 +136,7 @@ describe('robotAdminEpic tracks restarting state', () => { 'robot-3-boot', expect.any(Date) ) - .mockReturnValue('restart-timed-out') + .thenReturn('restart-timed-out') runEpicTest(mocks, ({ hot, expectObservable }) => { const action$ = hot('--') diff --git a/app/src/redux/robot-api/__tests__/actions.test.ts b/app/src/redux/robot-api/__tests__/actions.test.ts index 060e4abdf16..1594a8f1ea8 100644 --- a/app/src/redux/robot-api/__tests__/actions.test.ts +++ b/app/src/redux/robot-api/__tests__/actions.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import * as Actions from '../actions' import type { RobotApiAction } from '../types' diff --git a/app/src/redux/robot-api/__tests__/hooks.test.tsx b/app/src/redux/robot-api/__tests__/hooks.test.tsx index 351a34b5898..32ce3ec0fd3 100644 --- a/app/src/redux/robot-api/__tests__/hooks.test.tsx +++ b/app/src/redux/robot-api/__tests__/hooks.test.tsx @@ -1,3 +1,5 @@ +import { describe, it } from 'vitest' + describe('useDispatchApiRequest', () => { it.todo('replace deprecated enzyme test') }) diff --git a/app/src/redux/robot-api/__tests__/http.test.ts b/app/src/redux/robot-api/__tests__/http.test.ts index 264b1e540d7..eda27070a27 100644 --- a/app/src/redux/robot-api/__tests__/http.test.ts +++ b/app/src/redux/robot-api/__tests__/http.test.ts @@ -1,4 +1,4 @@ -// tests for the robot-api fetch wrapper +import { vi, describe, it, expect, beforeAll, afterAll } from 'vitest' import { promisify } from 'util' import express from 'express' @@ -13,7 +13,7 @@ import { HTTP_API_VERSION, GET, POST, PATCH, DELETE } from '../constants' import type { Application } from 'express' import type { RobotHost } from '../types' -jest.unmock('node-fetch') +vi.unmock('node-fetch') describe('robot-api http client', () => { let testApp: Application @@ -22,8 +22,7 @@ describe('robot-api http client', () => { let robot: RobotHost beforeAll(() => { - // @ts-expect-error(sa, 2021-6-28): global.fetch and node fetch have different interfaces - global.fetch = fetch + ;(global as any).fetch = fetch testApp = express() testApp.use((express as any).json()) diff --git a/app/src/redux/robot-api/__tests__/reducer.test.ts b/app/src/redux/robot-api/__tests__/reducer.test.ts index 3c76392c26f..d4c64fa3852 100644 --- a/app/src/redux/robot-api/__tests__/reducer.test.ts +++ b/app/src/redux/robot-api/__tests__/reducer.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import { robotApiReducer } from '../reducer' import type { RobotApiState } from '../types' diff --git a/app/src/redux/robot-api/__tests__/selectors.test.ts b/app/src/redux/robot-api/__tests__/selectors.test.ts index a255e508063..cdac69f0246 100644 --- a/app/src/redux/robot-api/__tests__/selectors.test.ts +++ b/app/src/redux/robot-api/__tests__/selectors.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import * as Selectors from '../selectors' import type { State } from '../../types' diff --git a/app/src/redux/robot-api/__utils__/epic-test-mocks.ts b/app/src/redux/robot-api/__utils__/epic-test-mocks.ts index 98772e3e067..30150e83408 100644 --- a/app/src/redux/robot-api/__utils__/epic-test-mocks.ts +++ b/app/src/redux/robot-api/__utils__/epic-test-mocks.ts @@ -1,3 +1,4 @@ +import { vi, expect } from 'vitest' import { TestScheduler } from 'rxjs/testing' import * as RobotApiHttp from '../http' @@ -7,15 +8,8 @@ import { mockRobot, mockRequestMeta } from '../__fixtures__' import type { State } from '../../types' import type { RobotHost, RobotApiResponse } from '../types' -jest.mock('../http') -jest.mock('../../discovery/selectors') - -const mockFetchRobotApi = RobotApiHttp.fetchRobotApi as jest.MockedFunction< - typeof RobotApiHttp.fetchRobotApi -> -const mockGetRobotByName = DiscoverySelectors.getRobotByName as jest.MockedFunction< - typeof DiscoverySelectors.getRobotByName -> +vi.mock('../http') +vi.mock('../../discovery/selectors') export interface EpicTestMocks { state: State @@ -23,8 +17,8 @@ export interface EpicTestMocks { response: R | undefined robot: RobotHost meta: typeof mockRequestMeta - getRobotByName: typeof mockGetRobotByName - fetchRobotApi: typeof mockFetchRobotApi + getRobotByName: typeof RobotApiHttp.fetchRobotApi + fetchRobotApi: typeof DiscoverySelectors.getRobotByName testScheduler: TestScheduler } @@ -52,12 +46,14 @@ export const setupEpicTestMocks = ( ...triggerAction, meta: { ...(triggerAction.meta || {}), ...mockRequestMeta }, } - mockGetRobotByName.mockImplementation((state: State, robotName: string) => { - expect(state).toBe(mockState) - expect(robotName).toBe(mockRobot.name) + vi.mocked(DiscoverySelectors.getRobotByName).mockImplementation( + (state: State, robotName: string) => { + expect(state).toBe(mockState) + expect(robotName).toBe(mockRobot.name) - return mockRobot - }) + return mockRobot + } + ) const testScheduler = new TestScheduler((actual, expected) => { expect(actual).toEqual(expected) @@ -69,8 +65,8 @@ export const setupEpicTestMocks = ( response: mockResponse, robot: mockRobot, meta: mockRequestMeta, - getRobotByName: mockGetRobotByName, - fetchRobotApi: mockFetchRobotApi, + getRobotByName: DiscoverySelectors.getRobotByName as any, + fetchRobotApi: RobotApiHttp.fetchRobotApi as any, testScheduler, } } @@ -85,7 +81,7 @@ export const runEpicTest = ( const { cold } = schedulerArgs if (response) { - fetchRobotApi.mockReturnValue( + vi.mocked(fetchRobotApi as any).mockReturnValue( cold('r', { r: response } as any) ) } diff --git a/app/src/redux/robot-controls/__tests__/actions.test.ts b/app/src/redux/robot-controls/__tests__/actions.test.ts index efda566b8fe..f51629cf55c 100644 --- a/app/src/redux/robot-controls/__tests__/actions.test.ts +++ b/app/src/redux/robot-controls/__tests__/actions.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import * as Actions from '../actions' import type { RobotControlsAction } from '../types' diff --git a/app/src/redux/robot-controls/__tests__/reducer.test.ts b/app/src/redux/robot-controls/__tests__/reducer.test.ts index 01c81994cb6..8e6ea51f46b 100644 --- a/app/src/redux/robot-controls/__tests__/reducer.test.ts +++ b/app/src/redux/robot-controls/__tests__/reducer.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import { robotControlsReducer } from '../reducer' import type { Action } from '../../types' diff --git a/app/src/redux/robot-controls/__tests__/selectors.test.ts b/app/src/redux/robot-controls/__tests__/selectors.test.ts index 8b83bb84925..36cc352bae9 100644 --- a/app/src/redux/robot-controls/__tests__/selectors.test.ts +++ b/app/src/redux/robot-controls/__tests__/selectors.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import * as Selectors from '../selectors' import type { State } from '../../types' diff --git a/app/src/redux/robot-controls/epic/__tests__/fetchLightsEpic.test.ts b/app/src/redux/robot-controls/epic/__tests__/fetchLightsEpic.test.ts index d008c311c09..4d92e26b217 100644 --- a/app/src/redux/robot-controls/epic/__tests__/fetchLightsEpic.test.ts +++ b/app/src/redux/robot-controls/epic/__tests__/fetchLightsEpic.test.ts @@ -1,3 +1,4 @@ +import { vi, describe, it, expect, beforeEach } from 'vitest' import { TestScheduler } from 'rxjs/testing' import { mockRobot } from '../../../robot-api/__fixtures__' @@ -10,34 +11,24 @@ import { robotControlsEpic } from '..' import type { Action, State } from '../../../types' -jest.mock('../../../robot-api/http') -jest.mock('../../../discovery/selectors') +vi.mock('../../../robot-api/http') +vi.mock('../../../discovery/selectors') const mockState: State = { state: true } as any -const mockFetchRobotApi = RobotApiHttp.fetchRobotApi as jest.MockedFunction< - typeof RobotApiHttp.fetchRobotApi -> - -const mockGetRobotByName = DiscoverySelectors.getRobotByName as jest.MockedFunction< - typeof DiscoverySelectors.getRobotByName -> - describe('fetchLightsEpic', () => { let testScheduler: TestScheduler beforeEach(() => { - mockGetRobotByName.mockReturnValue(mockRobot as any) + vi.mocked(DiscoverySelectors.getRobotByName).mockReturnValue( + mockRobot as any + ) testScheduler = new TestScheduler((actual, expected) => { expect(actual).toEqual(expected) }) }) - afterEach(() => { - jest.resetAllMocks() - }) - const meta = { requestId: '1234' } const action: Types.FetchLightsAction = { ...Actions.fetchLights(mockRobot.name), @@ -46,7 +37,7 @@ describe('fetchLightsEpic', () => { it('calls GET /robot/lights', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('r', { r: Fixtures.mockFetchLightsSuccess }) ) @@ -57,8 +48,11 @@ describe('fetchLightsEpic', () => { expectObservable(output$) flush() - expect(mockGetRobotByName).toHaveBeenCalledWith(mockState, mockRobot.name) - expect(mockFetchRobotApi).toHaveBeenCalledWith(mockRobot, { + expect(DiscoverySelectors.getRobotByName).toHaveBeenCalledWith( + mockState, + mockRobot.name + ) + expect(RobotApiHttp.fetchRobotApi).toHaveBeenCalledWith(mockRobot, { method: 'GET', path: '/robot/lights', }) @@ -67,7 +61,7 @@ describe('fetchLightsEpic', () => { it('maps successful response to FETCH_LIGHTS_SUCCESS', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('r', { r: Fixtures.mockFetchLightsSuccess }) ) @@ -87,7 +81,7 @@ describe('fetchLightsEpic', () => { it('maps failed response to FETCH_LIGHTS_FAILURE', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('r', { r: Fixtures.mockFetchLightsFailure }) ) diff --git a/app/src/redux/robot-controls/epic/__tests__/homeEpic.test.ts b/app/src/redux/robot-controls/epic/__tests__/homeEpic.test.ts index d5cd2a40730..987329abb30 100644 --- a/app/src/redux/robot-controls/epic/__tests__/homeEpic.test.ts +++ b/app/src/redux/robot-controls/epic/__tests__/homeEpic.test.ts @@ -1,3 +1,4 @@ +import { vi, describe, it, expect, beforeEach } from 'vitest' import { TestScheduler } from 'rxjs/testing' import { mockRobot } from '../../../robot-api/__fixtures__' @@ -10,34 +11,24 @@ import { robotControlsEpic } from '..' import type { Action, State } from '../../../types' -jest.mock('../../../robot-api/http') -jest.mock('../../../discovery/selectors') +vi.mock('../../../robot-api/http') +vi.mock('../../../discovery/selectors') const mockState: State = { state: true } as any -const mockFetchRobotApi = RobotApiHttp.fetchRobotApi as jest.MockedFunction< - typeof RobotApiHttp.fetchRobotApi -> - -const mockGetRobotByName = DiscoverySelectors.getRobotByName as jest.MockedFunction< - typeof DiscoverySelectors.getRobotByName -> - describe('homeEpic', () => { let testScheduler: TestScheduler beforeEach(() => { - mockGetRobotByName.mockReturnValue(mockRobot as any) + vi.mocked(DiscoverySelectors.getRobotByName).mockReturnValue( + mockRobot as any + ) testScheduler = new TestScheduler((actual, expected) => { expect(actual).toEqual(expected) }) }) - afterEach(() => { - jest.resetAllMocks() - }) - const meta = { requestId: '1234' } const action: Types.HomeAction = { ...Actions.home(mockRobot.name, 'robot'), @@ -46,7 +37,7 @@ describe('homeEpic', () => { it('calls POST /robot/home with target: robot', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('r', { r: Fixtures.mockHomeSuccess }) ) @@ -57,8 +48,11 @@ describe('homeEpic', () => { expectObservable(output$) flush() - expect(mockGetRobotByName).toHaveBeenCalledWith(mockState, mockRobot.name) - expect(mockFetchRobotApi).toHaveBeenCalledWith(mockRobot, { + expect(DiscoverySelectors.getRobotByName).toHaveBeenCalledWith( + mockState, + mockRobot.name + ) + expect(RobotApiHttp.fetchRobotApi).toHaveBeenCalledWith(mockRobot, { method: 'POST', path: '/robot/home', body: { target: 'robot' }, @@ -72,7 +66,7 @@ describe('homeEpic', () => { meta, } testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('r', { r: Fixtures.mockHomeSuccess }) ) @@ -83,8 +77,11 @@ describe('homeEpic', () => { expectObservable(output$) flush() - expect(mockGetRobotByName).toHaveBeenCalledWith(mockState, mockRobot.name) - expect(mockFetchRobotApi).toHaveBeenCalledWith(mockRobot, { + expect(DiscoverySelectors.getRobotByName).toHaveBeenCalledWith( + mockState, + mockRobot.name + ) + expect(RobotApiHttp.fetchRobotApi).toHaveBeenCalledWith(mockRobot, { method: 'POST', path: '/robot/home', body: { target: 'pipette', mount: 'right' }, @@ -94,7 +91,7 @@ describe('homeEpic', () => { it('maps successful response to HOME_SUCCESS', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('r', { r: Fixtures.mockHomeSuccess }) ) @@ -113,7 +110,7 @@ describe('homeEpic', () => { it('maps failed response to HOME_FAILURE', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('r', { r: Fixtures.mockHomeFailure }) ) diff --git a/app/src/redux/robot-controls/epic/__tests__/moveEpic.test.ts b/app/src/redux/robot-controls/epic/__tests__/moveEpic.test.ts index bd826f9237d..2825a07b5fd 100644 --- a/app/src/redux/robot-controls/epic/__tests__/moveEpic.test.ts +++ b/app/src/redux/robot-controls/epic/__tests__/moveEpic.test.ts @@ -1,3 +1,4 @@ +import { vi, describe, it, expect, beforeEach, afterEach } from 'vitest' import { TestScheduler } from 'rxjs/testing' import { mockRobot } from '../../../robot-api/__fixtures__' @@ -11,29 +12,19 @@ import { robotControlsEpic } from '..' import type { Action, State } from '../../../types' -jest.mock('../../../robot-api/http') -jest.mock('../../../discovery/selectors') -jest.mock('../../../pipettes/selectors') +vi.mock('../../../robot-api/http') +vi.mock('../../../discovery/selectors') +vi.mock('../../../pipettes/selectors') const mockState: State = { state: true } as any -const mockFetchRobotApi = RobotApiHttp.fetchRobotApi as jest.MockedFunction< - typeof RobotApiHttp.fetchRobotApi -> - -const mockGetRobotByName = DiscoverySelectors.getRobotByName as jest.MockedFunction< - typeof DiscoverySelectors.getRobotByName -> - -const mockGetAttachedPipettes = PipettesSelectors.getAttachedPipettes as jest.MockedFunction< - typeof PipettesSelectors.getAttachedPipettes -> - describe('moveEpic', () => { let testScheduler: TestScheduler beforeEach(() => { - mockGetRobotByName.mockReturnValue(mockRobot as any) + vi.mocked(DiscoverySelectors.getRobotByName).mockReturnValue( + mockRobot as any + ) testScheduler = new TestScheduler((actual, expected) => { expect(actual).toEqual(expected) @@ -41,7 +32,7 @@ describe('moveEpic', () => { }) afterEach(() => { - jest.resetAllMocks() + vi.resetAllMocks() }) const meta = { requestId: '1234' } @@ -53,7 +44,7 @@ describe('moveEpic', () => { } testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi + vi.mocked(RobotApiHttp.fetchRobotApi) .mockReturnValueOnce( cold('p', { p: Fixtures.mockFetchPositionsSuccess }) ) @@ -66,12 +57,15 @@ describe('moveEpic', () => { expectObservable(output$) flush() - expect(mockGetRobotByName).toHaveBeenCalledWith(mockState, mockRobot.name) - expect(mockFetchRobotApi).toHaveBeenNthCalledWith(1, mockRobot, { + expect(DiscoverySelectors.getRobotByName).toHaveBeenCalledWith( + mockState, + mockRobot.name + ) + expect(RobotApiHttp.fetchRobotApi).toHaveBeenNthCalledWith(1, mockRobot, { method: 'GET', path: '/robot/positions', }) - expect(mockFetchRobotApi).toHaveBeenNthCalledWith(2, mockRobot, { + expect(RobotApiHttp.fetchRobotApi).toHaveBeenNthCalledWith(2, mockRobot, { method: 'POST', path: '/robot/move', body: { @@ -90,13 +84,13 @@ describe('moveEpic', () => { } testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi + vi.mocked(RobotApiHttp.fetchRobotApi) .mockReturnValueOnce( cold('p', { p: Fixtures.mockFetchPositionsSuccess }) ) .mockReturnValueOnce(cold('m', { m: Fixtures.mockMoveSuccess })) - mockGetAttachedPipettes.mockReturnValue({ + vi.mocked(PipettesSelectors.getAttachedPipettes).mockReturnValue({ left: null, right: { model: 'p300_single_v2.0' } as any, }) @@ -108,12 +102,15 @@ describe('moveEpic', () => { expectObservable(output$) flush() - expect(mockGetRobotByName).toHaveBeenCalledWith(mockState, mockRobot.name) - expect(mockFetchRobotApi).toHaveBeenNthCalledWith(1, mockRobot, { + expect(DiscoverySelectors.getRobotByName).toHaveBeenCalledWith( + mockState, + mockRobot.name + ) + expect(RobotApiHttp.fetchRobotApi).toHaveBeenNthCalledWith(1, mockRobot, { method: 'GET', path: '/robot/positions', }) - expect(mockFetchRobotApi).toHaveBeenNthCalledWith(2, mockRobot, { + expect(RobotApiHttp.fetchRobotApi).toHaveBeenNthCalledWith(2, mockRobot, { method: 'POST', path: '/robot/move', body: { @@ -133,7 +130,7 @@ describe('moveEpic', () => { } testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi + vi.mocked(RobotApiHttp.fetchRobotApi) .mockReturnValueOnce( cold('p', { p: Fixtures.mockFetchPositionsSuccess }) ) @@ -149,8 +146,11 @@ describe('moveEpic', () => { expectObservable(output$) flush() - expect(mockGetRobotByName).toHaveBeenCalledWith(mockState, mockRobot.name) - expect(mockFetchRobotApi).toHaveBeenNthCalledWith(3, mockRobot, { + expect(DiscoverySelectors.getRobotByName).toHaveBeenCalledWith( + mockState, + mockRobot.name + ) + expect(RobotApiHttp.fetchRobotApi).toHaveBeenNthCalledWith(3, mockRobot, { method: 'POST', path: '/motors/disengage', body: { axes: ['a', 'b', 'c', 'z'] }, @@ -165,7 +165,7 @@ describe('moveEpic', () => { } testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi + vi.mocked(RobotApiHttp.fetchRobotApi) .mockReturnValueOnce( cold('p', { p: Fixtures.mockFetchPositionsSuccess }) ) @@ -194,7 +194,7 @@ describe('moveEpic', () => { } testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi + vi.mocked(RobotApiHttp.fetchRobotApi) .mockReturnValueOnce( cold('p', { p: Fixtures.mockFetchPositionsSuccess }) ) @@ -223,7 +223,7 @@ describe('moveEpic', () => { } testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi.mockReturnValueOnce( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValueOnce( cold('r', { r: Fixtures.mockFetchPositionsFailure }) ) @@ -248,7 +248,7 @@ describe('moveEpic', () => { } testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi + vi.mocked(RobotApiHttp.fetchRobotApi) .mockReturnValueOnce( cold('p', { p: Fixtures.mockFetchPositionsSuccess }) ) @@ -275,7 +275,7 @@ describe('moveEpic', () => { } testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi + vi.mocked(RobotApiHttp.fetchRobotApi) .mockReturnValueOnce( cold('p', { p: Fixtures.mockFetchPositionsSuccess }) ) diff --git a/app/src/redux/robot-controls/epic/__tests__/updateLightsEpic.test.ts b/app/src/redux/robot-controls/epic/__tests__/updateLightsEpic.test.ts index 4dc1f357fd3..8d4586fc4e5 100644 --- a/app/src/redux/robot-controls/epic/__tests__/updateLightsEpic.test.ts +++ b/app/src/redux/robot-controls/epic/__tests__/updateLightsEpic.test.ts @@ -1,3 +1,4 @@ +import { vi, describe, it, expect, beforeEach } from 'vitest' import { TestScheduler } from 'rxjs/testing' import { mockRobot } from '../../../robot-api/__fixtures__' @@ -11,34 +12,24 @@ import { robotControlsEpic } from '..' import type { Action, State } from '../../../types' import type { RobotApiRequestMeta } from '../../../robot-api/types' -jest.mock('../../../robot-api/http') -jest.mock('../../../discovery/selectors') +vi.mock('../../../robot-api/http') +vi.mock('../../../discovery/selectors') const mockState: State = { state: true } as any -const mockFetchRobotApi = RobotApiHttp.fetchRobotApi as jest.MockedFunction< - typeof RobotApiHttp.fetchRobotApi -> - -const mockGetRobotByName = DiscoverySelectors.getRobotByName as jest.MockedFunction< - typeof DiscoverySelectors.getRobotByName -> - describe('updateLightsEpic', () => { let testScheduler: TestScheduler beforeEach(() => { - mockGetRobotByName.mockReturnValue(mockRobot as any) + vi.mocked(DiscoverySelectors.getRobotByName).mockReturnValue( + mockRobot as any + ) testScheduler = new TestScheduler((actual, expected) => { expect(actual).toEqual(expected) }) }) - afterEach(() => { - jest.resetAllMocks() - }) - const meta = { requestId: '1234' } as RobotApiRequestMeta const action: Types.UpdateLightsAction = { ...Actions.updateLights(mockRobot.name, true), @@ -47,7 +38,7 @@ describe('updateLightsEpic', () => { it('calls POST /robot/lights', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('r', { r: Fixtures.mockUpdateLightsSuccess }) ) @@ -58,8 +49,11 @@ describe('updateLightsEpic', () => { expectObservable(output$) flush() - expect(mockGetRobotByName).toHaveBeenCalledWith(mockState, mockRobot.name) - expect(mockFetchRobotApi).toHaveBeenCalledWith(mockRobot, { + expect(DiscoverySelectors.getRobotByName).toHaveBeenCalledWith( + mockState, + mockRobot.name + ) + expect(RobotApiHttp.fetchRobotApi).toHaveBeenCalledWith(mockRobot, { method: 'POST', path: '/robot/lights', body: { on: true }, @@ -69,7 +63,7 @@ describe('updateLightsEpic', () => { it('maps successful response to UPDATE_LIGHTS_SUCCESS', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('r', { r: Fixtures.mockUpdateLightsSuccess }) ) @@ -89,7 +83,7 @@ describe('updateLightsEpic', () => { it('maps failed response to UPDATE_LIGHTS_FAILURE', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('r', { r: Fixtures.mockUpdateLightsFailure }) ) diff --git a/app/src/redux/robot-settings/__tests__/actions.test.ts b/app/src/redux/robot-settings/__tests__/actions.test.ts index c84dd5eb32b..1ad7530fee4 100644 --- a/app/src/redux/robot-settings/__tests__/actions.test.ts +++ b/app/src/redux/robot-settings/__tests__/actions.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import * as Actions from '../actions' import * as Fixtures from '../__fixtures__' import type { RobotSettingsAction } from '../types' diff --git a/app/src/redux/robot-settings/__tests__/reducer.test.ts b/app/src/redux/robot-settings/__tests__/reducer.test.ts index 8cbe5531d35..3724f3c6cbc 100644 --- a/app/src/redux/robot-settings/__tests__/reducer.test.ts +++ b/app/src/redux/robot-settings/__tests__/reducer.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import { robotSettingsReducer } from '../reducer' import * as Fixtures from '../__fixtures__' diff --git a/app/src/redux/robot-settings/__tests__/selectors.test.ts b/app/src/redux/robot-settings/__tests__/selectors.test.ts index c746a1eb99f..2312cbb4da5 100644 --- a/app/src/redux/robot-settings/__tests__/selectors.test.ts +++ b/app/src/redux/robot-settings/__tests__/selectors.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import * as Selectors from '../selectors' import type { State } from '../../types' diff --git a/app/src/redux/robot-settings/epic/__tests__/clearRestartPathEpic.test.ts b/app/src/redux/robot-settings/epic/__tests__/clearRestartPathEpic.test.ts index b8711c96f76..f30680647bd 100644 --- a/app/src/redux/robot-settings/epic/__tests__/clearRestartPathEpic.test.ts +++ b/app/src/redux/robot-settings/epic/__tests__/clearRestartPathEpic.test.ts @@ -1,3 +1,4 @@ +import { vi, describe, it, expect, beforeEach } from 'vitest' import { TestScheduler } from 'rxjs/testing' import * as RobotAdminSelectors from '../../../robot-admin/selectors' @@ -7,36 +8,24 @@ import { robotSettingsEpic } from '..' import type { Action, State } from '../../../types' -jest.mock('../../../robot-admin/selectors') -jest.mock('../../selectors') - -const mockGetRobotRestarting = RobotAdminSelectors.getRobotRestarting as jest.MockedFunction< - typeof RobotAdminSelectors.getRobotRestarting -> - -const mockGetAllRestartRequiredRobots = Selectors.getAllRestartRequiredRobots as jest.MockedFunction< - typeof Selectors.getAllRestartRequiredRobots -> +vi.mock('../../../robot-admin/selectors') +vi.mock('../../selectors') describe('clearRestartPathEpic', () => { let testScheduler: TestScheduler beforeEach(() => { - mockGetAllRestartRequiredRobots.mockReturnValue([]) - mockGetRobotRestarting.mockReturnValue(false) + vi.mocked(Selectors.getAllRestartRequiredRobots).mockReturnValue([]) + vi.mocked(RobotAdminSelectors.getRobotRestarting).mockReturnValue(false) testScheduler = new TestScheduler((actual, expected) => { expect(actual).toEqual(expected) }) }) - afterEach(() => { - jest.resetAllMocks() - }) - it('dispatches CLEAR_RESTART_PATH on robot restart', () => { - mockGetAllRestartRequiredRobots.mockReturnValue(['a', 'b']) - mockGetRobotRestarting.mockReturnValue(true) + vi.mocked(Selectors.getAllRestartRequiredRobots).mockReturnValue(['a', 'b']) + vi.mocked(RobotAdminSelectors.getRobotRestarting).mockReturnValue(true) testScheduler.run(({ hot, cold, expectObservable }) => { const action$ = cold('--') diff --git a/app/src/redux/robot-settings/epic/__tests__/fetchSettingsEpic.test.ts b/app/src/redux/robot-settings/epic/__tests__/fetchSettingsEpic.test.ts index c4acab1e528..9847f182ab3 100644 --- a/app/src/redux/robot-settings/epic/__tests__/fetchSettingsEpic.test.ts +++ b/app/src/redux/robot-settings/epic/__tests__/fetchSettingsEpic.test.ts @@ -1,3 +1,4 @@ +import { vi, describe, it, expect, beforeEach } from 'vitest' import { TestScheduler } from 'rxjs/testing' import { mockRobot } from '../../../robot-api/__fixtures__' @@ -12,40 +13,26 @@ import { robotSettingsEpic } from '..' import type { Action, State } from '../../../types' import type { RobotApiRequestMeta } from '../../../robot-api/types' -jest.mock('../../../robot-api/http') -jest.mock('../../../discovery/selectors') -jest.mock('../../selectors') +vi.mock('../../../robot-api/http') +vi.mock('../../../discovery/selectors') +vi.mock('../../selectors') const mockState: State = { state: true } as any -const mockFetchRobotApi = RobotApiHttp.fetchRobotApi as jest.MockedFunction< - typeof RobotApiHttp.fetchRobotApi -> - -const mockGetRobotByName = DiscoverySelectors.getRobotByName as jest.MockedFunction< - typeof DiscoverySelectors.getRobotByName -> - -const mockGetAllRestartRequiredRobots = Selectors.getAllRestartRequiredRobots as jest.MockedFunction< - typeof Selectors.getAllRestartRequiredRobots -> - describe('fetchSettingsEpic', () => { let testScheduler: TestScheduler beforeEach(() => { - mockGetRobotByName.mockReturnValue(mockRobot as any) - mockGetAllRestartRequiredRobots.mockReturnValue([]) + vi.mocked(DiscoverySelectors.getRobotByName).mockReturnValue( + mockRobot as any + ) + vi.mocked(Selectors.getAllRestartRequiredRobots).mockReturnValue([]) testScheduler = new TestScheduler((actual, expected) => { expect(actual).toEqual(expected) }) }) - afterEach(() => { - jest.resetAllMocks() - }) - const meta: RobotApiRequestMeta = { requestId: '1234' } as any const action: Types.FetchSettingsAction = { ...Actions.fetchSettings(mockRobot.name), @@ -54,7 +41,7 @@ describe('fetchSettingsEpic', () => { it('calls GET /settings', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('r', { r: Fixtures.mockFetchSettingsSuccess }) ) @@ -65,8 +52,11 @@ describe('fetchSettingsEpic', () => { expectObservable(output$) flush() - expect(mockGetRobotByName).toHaveBeenCalledWith(mockState, mockRobot.name) - expect(mockFetchRobotApi).toHaveBeenCalledWith(mockRobot, { + expect(DiscoverySelectors.getRobotByName).toHaveBeenCalledWith( + mockState, + mockRobot.name + ) + expect(RobotApiHttp.fetchRobotApi).toHaveBeenCalledWith(mockRobot, { method: 'GET', path: '/settings', }) @@ -75,7 +65,7 @@ describe('fetchSettingsEpic', () => { it('maps successful response to FETCH_SETTINGS_SUCCESS', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('r', { r: Fixtures.mockFetchSettingsSuccess }) ) @@ -96,7 +86,7 @@ describe('fetchSettingsEpic', () => { it('maps failed response to FETCH_SETTINGS_FAILURE', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('r', { r: Fixtures.mockFetchSettingsFailure }) ) diff --git a/app/src/redux/robot-settings/epic/__tests__/updateSettingEpic.test.ts b/app/src/redux/robot-settings/epic/__tests__/updateSettingEpic.test.ts index 877153b2892..26ed9bacc96 100644 --- a/app/src/redux/robot-settings/epic/__tests__/updateSettingEpic.test.ts +++ b/app/src/redux/robot-settings/epic/__tests__/updateSettingEpic.test.ts @@ -1,3 +1,4 @@ +import { vi, describe, it, expect, beforeEach } from 'vitest' import { TestScheduler } from 'rxjs/testing' import { mockRobot } from '../../../robot-api/__fixtures__' @@ -12,40 +13,26 @@ import { robotSettingsEpic } from '..' import type { Action, State } from '../../../types' import type { RobotApiRequestMeta } from '../../../robot-api/types' -jest.mock('../../../robot-api/http') -jest.mock('../../../discovery/selectors') -jest.mock('../../selectors') +vi.mock('../../../robot-api/http') +vi.mock('../../../discovery/selectors') +vi.mock('../../selectors') const mockState: State = { state: true } as any -const mockFetchRobotApi = RobotApiHttp.fetchRobotApi as jest.MockedFunction< - typeof RobotApiHttp.fetchRobotApi -> - -const mockGetRobotByName = DiscoverySelectors.getRobotByName as jest.MockedFunction< - typeof DiscoverySelectors.getRobotByName -> - -const mockGetAllRestartRequiredRobots = Selectors.getAllRestartRequiredRobots as jest.MockedFunction< - typeof Selectors.getAllRestartRequiredRobots -> - describe('updateSettingEpic', () => { let testScheduler: TestScheduler beforeEach(() => { - mockGetRobotByName.mockReturnValue(mockRobot as any) - mockGetAllRestartRequiredRobots.mockReturnValue([]) + vi.mocked(DiscoverySelectors.getRobotByName).mockReturnValue( + mockRobot as any + ) + vi.mocked(Selectors.getAllRestartRequiredRobots).mockReturnValue([]) testScheduler = new TestScheduler((actual, expected) => { expect(actual).toEqual(expected) }) }) - afterEach(() => { - jest.resetAllMocks() - }) - const meta: RobotApiRequestMeta = { requestId: '1234' } as any const action: Types.UpdateSettingAction = { ...Actions.updateSetting(mockRobot.name, 'setting-id', true), @@ -54,7 +41,7 @@ describe('updateSettingEpic', () => { it('calls POST /settings', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('r', { r: Fixtures.mockUpdateSettingSuccess }) ) @@ -65,8 +52,11 @@ describe('updateSettingEpic', () => { expectObservable(output$) flush() - expect(mockGetRobotByName).toHaveBeenCalledWith(mockState, mockRobot.name) - expect(mockFetchRobotApi).toHaveBeenCalledWith(mockRobot, { + expect(DiscoverySelectors.getRobotByName).toHaveBeenCalledWith( + mockState, + mockRobot.name + ) + expect(RobotApiHttp.fetchRobotApi).toHaveBeenCalledWith(mockRobot, { method: 'POST', path: '/settings', body: { id: 'setting-id', value: true }, @@ -76,7 +66,7 @@ describe('updateSettingEpic', () => { it('maps successful response to UPDATE_SETTING_SUCCESS', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('r', { r: Fixtures.mockUpdateSettingSuccess }) ) @@ -97,7 +87,7 @@ describe('updateSettingEpic', () => { it('maps failed response to UPDATE_SETTING_FAILURE', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('r', { r: Fixtures.mockUpdateSettingFailure }) ) diff --git a/app/src/redux/robot-update/__tests__/actions.test.ts b/app/src/redux/robot-update/__tests__/actions.test.ts index 2f73756b450..2d930f2d527 100644 --- a/app/src/redux/robot-update/__tests__/actions.test.ts +++ b/app/src/redux/robot-update/__tests__/actions.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import { mockRobot } from '../../robot-api/__fixtures__' import * as actions from '../actions' diff --git a/app/src/redux/robot-update/__tests__/epic.test.ts b/app/src/redux/robot-update/__tests__/epic.test.ts index 91141fa75ab..ea1066c0e62 100644 --- a/app/src/redux/robot-update/__tests__/epic.test.ts +++ b/app/src/redux/robot-update/__tests__/epic.test.ts @@ -1,3 +1,4 @@ +import { vi, describe, it, expect, beforeEach, afterEach } from 'vitest' import { TestScheduler } from 'rxjs/testing' import { mockRobot as robot } from '../../robot-api/__fixtures__' @@ -14,21 +15,8 @@ import { INITIAL_STATE } from '../reducer' import type { Action, State } from '../../types' import { RobotApiResponse } from '../../robot-api/types' -jest.mock('../selectors') -jest.mock('../../robot-api/http') - -const mockFetchRobotApi = RobotApiHttp.fetchRobotApi as jest.MockedFunction< - typeof RobotApiHttp.fetchRobotApi -> -const getRobotUpdateRobot = selectors.getRobotUpdateRobot as jest.MockedFunction< - typeof selectors.getRobotUpdateRobot -> -const getRobotUpdateSessionRobotName = selectors.getRobotUpdateSessionRobotName as jest.MockedFunction< - typeof selectors.getRobotUpdateSessionRobotName -> -const getRobotUpdateSession = selectors.getRobotUpdateSession as jest.MockedFunction< - typeof selectors.getRobotUpdateSession -> +vi.mock('../selectors') +vi.mock('../../robot-api/http') const balenaRobot = { ...robot, serverHealth: {} } as any @@ -76,13 +64,13 @@ describe('robot update epics', () => { }) afterEach(() => { - jest.resetAllMocks() + vi.resetAllMocks() }) describe('startUpdateEpic', () => { it('with ot2 system update robot and built-in system update sends read system file', () => { testScheduler.run(({ hot, cold, expectObservable }) => { - getRobotUpdateRobot.mockReturnValueOnce(brRobotOt2) + vi.mocked(selectors.getRobotUpdateRobot).mockReturnValueOnce(brRobotOt2) const action$ = hot('-a', { a: actions.startRobotUpdate(robot.name), @@ -98,7 +86,9 @@ describe('robot update epics', () => { it('with flex system update robot and built-in system update sends read system file', () => { testScheduler.run(({ hot, cold, expectObservable }) => { - getRobotUpdateRobot.mockReturnValueOnce(brRobotFlex) + vi.mocked(selectors.getRobotUpdateRobot).mockReturnValueOnce( + brRobotFlex + ) const action$ = hot('-a', { a: actions.startRobotUpdate(robot.name), @@ -114,7 +104,7 @@ describe('robot update epics', () => { it('with ot2 system update robot and user system update sends read user file', () => { testScheduler.run(({ hot, cold, expectObservable }) => { - getRobotUpdateRobot.mockReturnValueOnce(brRobotOt2) + vi.mocked(selectors.getRobotUpdateRobot).mockReturnValueOnce(brRobotOt2) const action$ = hot('-a', { a: actions.startRobotUpdate(robot.name, '/my/special/system/file'), @@ -130,7 +120,9 @@ describe('robot update epics', () => { it('with flex system update robot and user system update sends read user file', () => { testScheduler.run(({ hot, cold, expectObservable }) => { - getRobotUpdateRobot.mockReturnValueOnce(brRobotFlex) + vi.mocked(selectors.getRobotUpdateRobot).mockReturnValueOnce( + brRobotFlex + ) const action$ = hot('-a', { a: actions.startRobotUpdate(robot.name, '/my/special/file'), @@ -146,7 +138,9 @@ describe('robot update epics', () => { it('with ready-to-migrate robot sends read system file', () => { testScheduler.run(({ hot, cold, expectObservable }) => { - getRobotUpdateRobot.mockReturnValueOnce(brReadyRobot) + vi.mocked(selectors.getRobotUpdateRobot).mockReturnValueOnce( + brReadyRobot + ) const action$ = hot('-a', { a: actions.startRobotUpdate(robot.name), @@ -162,7 +156,9 @@ describe('robot update epics', () => { it('with ready-to-migrate robot and user system update sends read user file', () => { testScheduler.run(({ hot, cold, expectObservable }) => { - getRobotUpdateRobot.mockReturnValueOnce(brReadyRobot) + vi.mocked(selectors.getRobotUpdateRobot).mockReturnValueOnce( + brReadyRobot + ) const action$ = hot('-a', { a: actions.startRobotUpdate(robot.name, '/my/special/system/file'), @@ -180,7 +176,9 @@ describe('robot update epics', () => { testScheduler.run(({ hot, expectObservable }) => { const action = actions.startRobotUpdate(robot.name) - getRobotUpdateRobot.mockReturnValueOnce(balenaRobot) + vi.mocked(selectors.getRobotUpdateRobot).mockReturnValueOnce( + balenaRobot + ) const action$ = hot('-a', { a: action }) const state$ = hot('a-', { a: state } as any) @@ -199,7 +197,9 @@ describe('robot update epics', () => { '/my/special/system/file' ) - getRobotUpdateRobot.mockReturnValueOnce(balenaRobot) + vi.mocked(selectors.getRobotUpdateRobot).mockReturnValueOnce( + balenaRobot + ) const action$ = hot('-a', { a: action }) const state$ = hot('a-', { a: state } as any) @@ -217,7 +217,9 @@ describe('robot update epics', () => { testScheduler.run(({ hot, expectObservable }) => { const action = actions.startRobotUpdate(robot.name) - getRobotUpdateRobot.mockReturnValueOnce(robot as any) + vi.mocked(selectors.getRobotUpdateRobot).mockReturnValueOnce( + robot as any + ) const action$ = hot('-a', { a: action }) const state$ = hot('a-', { a: state } as any) @@ -237,7 +239,7 @@ describe('robot update epics', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { const action = actions.createSession(robot, '/server/update/begin') - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('r', { r: Fixtures.mockUpdateBeginSuccess }) ) @@ -254,7 +256,7 @@ describe('robot update epics', () => { }) flush() - expect(mockFetchRobotApi).toHaveBeenCalledWith(robot, { + expect(RobotApiHttp.fetchRobotApi).toHaveBeenCalledWith(robot, { method: 'POST', path: '/server/update/begin', }) @@ -265,7 +267,7 @@ describe('robot update epics', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { const action = actions.createSession(robot, '/server/update/begin') - mockFetchRobotApi + vi.mocked(RobotApiHttp.fetchRobotApi) .mockReturnValueOnce( cold('r', { r: Fixtures.mockUpdateBeginConflict }) ) @@ -279,7 +281,7 @@ describe('robot update epics', () => { expectObservable(output$).toBe('-a', { a: action }) flush() - expect(mockFetchRobotApi).toHaveBeenCalledWith(robot, { + expect(RobotApiHttp.fetchRobotApi).toHaveBeenCalledWith(robot, { method: 'POST', path: '/server/update/cancel', }) @@ -290,7 +292,7 @@ describe('robot update epics', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { const action = actions.createSession(robot, '/server/update/begin') - mockFetchRobotApi + vi.mocked(RobotApiHttp.fetchRobotApi) .mockReturnValueOnce( cold('r', { r: Fixtures.mockUpdateBeginFailure }) ) @@ -304,7 +306,7 @@ describe('robot update epics', () => { expectObservable(output$).toBe('-a', { a: action }) flush() - expect(mockFetchRobotApi).toHaveBeenCalledWith(robot, { + expect(RobotApiHttp.fetchRobotApi).toHaveBeenCalledWith(robot, { method: 'POST', path: '/server/update/cancel', }) @@ -315,7 +317,7 @@ describe('robot update epics', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { const action = actions.createSession(robot, '/server/update/begin') - mockFetchRobotApi + vi.mocked(RobotApiHttp.fetchRobotApi) .mockReturnValueOnce( cold('r', { r: Fixtures.mockUpdateBeginConflict }) ) @@ -340,7 +342,7 @@ describe('robot update epics', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { const action = actions.createSession(robot, '/server/update/begin') - mockFetchRobotApi + vi.mocked(RobotApiHttp.fetchRobotApi) .mockReturnValueOnce( cold('r', { r: Fixtures.mockUpdateBeginFailure }) ) @@ -365,7 +367,7 @@ describe('robot update epics', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { const action = actions.createSession(robot, '/server/update/begin') - mockFetchRobotApi + vi.mocked(RobotApiHttp.fetchRobotApi) .mockReturnValueOnce( cold('r', { r: Fixtures.mockUpdateBeginConflict }) ) @@ -389,13 +391,13 @@ describe('robot update epics', () => { describe('startUpdateAfterFileDownload', () => { it('should start the update after file download if the robot is a flex', () => { testScheduler.run(({ hot, cold, expectObservable }) => { - const session: ReturnType = { + const session: ReturnType = { stage: 'done', step: 'downloadFile', } as any - getRobotUpdateRobot.mockReturnValue(brRobotFlex) - getRobotUpdateSession.mockReturnValue(session) + vi.mocked(selectors.getRobotUpdateRobot).mockReturnValue(brRobotFlex) + vi.mocked(selectors.getRobotUpdateSession).mockReturnValue(session) const state$ = hot('-a', { a: state }) const output$ = epics.startUpdateAfterFileDownload(null as any, state$) @@ -408,13 +410,13 @@ describe('robot update epics', () => { it('should start the update after file download if the robot is a ot-2', () => { testScheduler.run(({ hot, cold, expectObservable }) => { - const session: ReturnType = { + const session: ReturnType = { stage: 'done', step: 'downloadFile', } as any - getRobotUpdateRobot.mockReturnValue(brRobotOt2) - getRobotUpdateSession.mockReturnValue(session) + vi.mocked(selectors.getRobotUpdateRobot).mockReturnValue(brRobotOt2) + vi.mocked(selectors.getRobotUpdateSession).mockReturnValue(session) const state$ = hot('-a', { a: state }) const output$ = epics.startUpdateAfterFileDownload(null as any, state$) @@ -428,9 +430,11 @@ describe('robot update epics', () => { it('retryAfterPremigrationEpic', () => { testScheduler.run(({ hot, expectObservable }) => { - getRobotUpdateRobot.mockReturnValueOnce(brReadyRobot) - getRobotUpdateSessionRobotName.mockReturnValueOnce(brReadyRobot.name) - getRobotUpdateSession.mockReturnValueOnce({ + vi.mocked(selectors.getRobotUpdateRobot).mockReturnValueOnce(brReadyRobot) + vi.mocked(selectors.getRobotUpdateSessionRobotName).mockReturnValueOnce( + brReadyRobot.name + ) + vi.mocked(selectors.getRobotUpdateSession).mockReturnValueOnce({ robot: brReadyRobot.name, step: 'premigrationRestart', } as any) @@ -456,11 +460,11 @@ describe('robot update epics', () => { }, } - getRobotUpdateSession + vi.mocked(selectors.getRobotUpdateSession) .mockReturnValue({ stage: 'ready-for-restart' } as any) .mockReturnValueOnce({ stage: null } as any) - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('r', { r: Fixtures.mockStatusSuccess }) ) @@ -484,12 +488,12 @@ describe('robot update epics', () => { flush() const request = { method: 'GET', path: '/server/update/foobar/status' } - expect(mockFetchRobotApi).toHaveBeenNthCalledWith( + expect(RobotApiHttp.fetchRobotApi).toHaveBeenNthCalledWith( 1, brRobotOt2, request ) - expect(mockFetchRobotApi).toHaveBeenNthCalledWith( + expect(RobotApiHttp.fetchRobotApi).toHaveBeenNthCalledWith( 2, brRobotOt2, request @@ -500,7 +504,7 @@ describe('robot update epics', () => { it('uploadFileEpic should work with migration', () => { testScheduler.run(({ hot, expectObservable }) => { - const session: ReturnType = { + const session: ReturnType = { pathPrefix: '/server/update/migration', token: 'tok', stage: 'awaiting-file', @@ -512,8 +516,8 @@ describe('robot update epics', () => { }, } as any - getRobotUpdateRobot.mockReturnValue(brReadyRobot) - getRobotUpdateSession.mockReturnValue(session) + vi.mocked(selectors.getRobotUpdateRobot).mockReturnValue(brReadyRobot) + vi.mocked(selectors.getRobotUpdateSession).mockReturnValue(session) const action$ = null as any const state$ = hot('-a', { a: state }) @@ -531,7 +535,7 @@ describe('robot update epics', () => { it('uploadFileEpic should work with ot2 normal updates', () => { testScheduler.run(({ hot, expectObservable }) => { - const session: ReturnType = { + const session: ReturnType = { pathPrefix: '/server/update', token: 'tok', stage: 'awaiting-file', @@ -543,8 +547,8 @@ describe('robot update epics', () => { }, } as any - getRobotUpdateRobot.mockReturnValue(brRobotOt2) - getRobotUpdateSession.mockReturnValue(session) + vi.mocked(selectors.getRobotUpdateRobot).mockReturnValue(brRobotOt2) + vi.mocked(selectors.getRobotUpdateSession).mockReturnValue(session) const action$ = null as any const state$ = hot('-a', { a: state }) @@ -562,7 +566,7 @@ describe('robot update epics', () => { it('uploadFileEpic should work with flex normal updates', () => { testScheduler.run(({ hot, expectObservable }) => { - const session: ReturnType = { + const session: ReturnType = { pathPrefix: '/server/update', token: 'tok', stage: 'awaiting-file', @@ -574,8 +578,8 @@ describe('robot update epics', () => { }, } as any - getRobotUpdateRobot.mockReturnValue(brRobotFlex) - getRobotUpdateSession.mockReturnValue(session) + vi.mocked(selectors.getRobotUpdateRobot).mockReturnValue(brRobotFlex) + vi.mocked(selectors.getRobotUpdateSession).mockReturnValue(session) const action$ = null as any const state$ = hot('-a', { a: state }) @@ -601,10 +605,10 @@ describe('robot update epics', () => { it('commit request success', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { - getRobotUpdateRobot.mockReturnValue(brRobotOt2) - getRobotUpdateSession.mockReturnValue(session) + vi.mocked(selectors.getRobotUpdateRobot).mockReturnValue(brRobotOt2) + vi.mocked(selectors.getRobotUpdateSession).mockReturnValue(session) - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('-r', { r: Fixtures.mockCommitSuccess }) ) @@ -617,7 +621,7 @@ describe('robot update epics', () => { }) flush() - expect(mockFetchRobotApi).toHaveBeenCalledWith(brRobotOt2, { + expect(RobotApiHttp.fetchRobotApi).toHaveBeenCalledWith(brRobotOt2, { method: 'POST', path: '/server/update/foobar/commit', }) @@ -626,10 +630,10 @@ describe('robot update epics', () => { it('commit request failure', () => { testScheduler.run(({ hot, cold, expectObservable }) => { - getRobotUpdateRobot.mockReturnValue(brRobotOt2) - getRobotUpdateSession.mockReturnValue(session) + vi.mocked(selectors.getRobotUpdateRobot).mockReturnValue(brRobotOt2) + vi.mocked(selectors.getRobotUpdateSession).mockReturnValue(session) - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('-r', { r: Fixtures.mockCommitFailure }) ) @@ -655,10 +659,10 @@ describe('robot update epics', () => { it('restart request success', () => { testScheduler.run(({ hot, cold, expectObservable, flush }) => { - getRobotUpdateRobot.mockReturnValue(brRobotFlex) - getRobotUpdateSession.mockReturnValue(session) + vi.mocked(selectors.getRobotUpdateRobot).mockReturnValue(brRobotFlex) + vi.mocked(selectors.getRobotUpdateSession).mockReturnValue(session) - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('-r', { r: Fixtures.mockRestartSuccess }) ) @@ -673,7 +677,7 @@ describe('robot update epics', () => { }) flush() - expect(mockFetchRobotApi).toHaveBeenCalledWith(brRobotFlex, { + expect(RobotApiHttp.fetchRobotApi).toHaveBeenCalledWith(brRobotFlex, { method: 'POST', path: '/server/restart', }) @@ -682,10 +686,10 @@ describe('robot update epics', () => { it('restart request failure', () => { testScheduler.run(({ hot, cold, expectObservable }) => { - getRobotUpdateRobot.mockReturnValue(brRobotOt2) - getRobotUpdateSession.mockReturnValue(session) + vi.mocked(selectors.getRobotUpdateRobot).mockReturnValue(brRobotOt2) + vi.mocked(selectors.getRobotUpdateSession).mockReturnValue(session) - mockFetchRobotApi.mockReturnValue( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValue( cold('-r', { r: Fixtures.mockRestartFailure }) ) diff --git a/app/src/redux/robot-update/__tests__/hooks.test.ts b/app/src/redux/robot-update/__tests__/hooks.test.ts deleted file mode 100644 index 9e26ddd521c..00000000000 --- a/app/src/redux/robot-update/__tests__/hooks.test.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { useDispatch } from 'react-redux' -import { renderHook } from '@testing-library/react' - -import { useDispatchStartRobotUpdate } from '../hooks' -import { startRobotUpdate, clearRobotUpdateSession } from '../actions' - -jest.mock('react-redux') - -const mockUseDispatch = useDispatch as jest.MockedFunction - -describe('useDispatchStartRobotUpdate', () => { - let mockDispatch: jest.Mock - const mockRobotName = 'robotName' - const mockSystemFile = 'systemFile' - - beforeEach(() => { - mockDispatch = jest.fn() - mockUseDispatch.mockReturnValue(mockDispatch) - }) - - afterEach(() => { - mockUseDispatch.mockClear() - jest.clearAllMocks() - }) - - it('clears the robot update session before dispatching a new session with the given robotName and systemFile', () => { - const { result } = renderHook(useDispatchStartRobotUpdate) - - result.current(mockRobotName, mockSystemFile) - expect(mockDispatch).toHaveBeenCalledWith(clearRobotUpdateSession()) - expect(mockDispatch).toHaveBeenCalledWith( - startRobotUpdate(mockRobotName, mockSystemFile) - ) - }) -}) diff --git a/app/src/redux/robot-update/__tests__/hooks.test.tsx b/app/src/redux/robot-update/__tests__/hooks.test.tsx new file mode 100644 index 00000000000..a6366b5566e --- /dev/null +++ b/app/src/redux/robot-update/__tests__/hooks.test.tsx @@ -0,0 +1,41 @@ +import * as React from 'react' +import { vi, describe, it, expect, beforeEach } from 'vitest' +import { createStore } from 'redux' +import { renderHook } from '@testing-library/react' +import { I18nextProvider } from 'react-i18next' +import { Provider } from 'react-redux' + +import { i18n } from '../../../i18n' +import { useDispatchStartRobotUpdate } from '../hooks' +import { startRobotUpdate, clearRobotUpdateSession } from '../actions' + +import type { Store } from 'redux' +import type { State } from '../../types' + +describe('useDispatchStartRobotUpdate', () => { + let wrapper: React.FunctionComponent<{ children: React.ReactNode }> + let store: Store + const mockRobotName = 'robotName' + const mockSystemFile = 'systemFile' + beforeEach(() => { + store = createStore(vi.fn(), {}) + store.dispatch = vi.fn() + wrapper = ({ children }) => ( + + {children} + + ) + }) + + it('clears the robot update session before dispatching a new session with the given robotName and systemFile', () => { + const { result } = renderHook(useDispatchStartRobotUpdate, { + wrapper, + }) + + result.current(mockRobotName, mockSystemFile) + expect(store.dispatch).toHaveBeenCalledWith(clearRobotUpdateSession()) + expect(store.dispatch).toHaveBeenCalledWith( + startRobotUpdate(mockRobotName, mockSystemFile) + ) + }) +}) diff --git a/app/src/redux/robot-update/__tests__/reducer.test.ts b/app/src/redux/robot-update/__tests__/reducer.test.ts index f681706c2b6..f174def2e83 100644 --- a/app/src/redux/robot-update/__tests__/reducer.test.ts +++ b/app/src/redux/robot-update/__tests__/reducer.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import { mockRobot } from '../../robot-api/__fixtures__' import { INITIAL_STATE, robotUpdateReducer } from '../reducer' import type { Action } from '../../types' diff --git a/app/src/redux/robot-update/__tests__/selectors.test.ts b/app/src/redux/robot-update/__tests__/selectors.test.ts index ea834b94c02..e4f3e8f8283 100644 --- a/app/src/redux/robot-update/__tests__/selectors.test.ts +++ b/app/src/redux/robot-update/__tests__/selectors.test.ts @@ -1,3 +1,5 @@ +import { vi, describe, it, expect, beforeEach } from 'vitest' + import * as selectors from '../selectors' import * as Constants from '../constants' import { mockReachableRobot } from '../../discovery/__fixtures__' @@ -6,31 +8,17 @@ import * as discoSelectors from '../../discovery/selectors' import type { State } from '../../types' -jest.mock('../../discovery/selectors') - -const getViewableRobots = discoSelectors.getViewableRobots as jest.MockedFunction< - typeof discoSelectors.getViewableRobots -> -const getRobotApiVersion = discoSelectors.getRobotApiVersion as jest.MockedFunction< - typeof discoSelectors.getRobotApiVersion -> -const getRobotByName = discoSelectors.getRobotByName as jest.MockedFunction< - typeof discoSelectors.getRobotByName -> +vi.mock('../../discovery/selectors') describe('robot update selectors', () => { beforeEach(() => { - getViewableRobots.mockReturnValue([]) - getRobotApiVersion.mockReturnValue(null) - getRobotByName.mockReturnValue(null) - }) - - afterEach(() => { - jest.resetAllMocks() + vi.mocked(discoSelectors.getViewableRobots).mockReturnValue([]) + vi.mocked(discoSelectors.getRobotApiVersion).mockReturnValue(null) + vi.mocked(discoSelectors.getRobotByName).mockReturnValue(null) }) it('should get robot update info for an ot2', () => { - getRobotByName.mockReturnValue({ + vi.mocked(discoSelectors.getRobotByName).mockReturnValue({ serverHealth: { robotModel: 'OT-2 Standard' }, } as any) const state: State = { @@ -48,7 +36,7 @@ describe('robot update selectors', () => { }) it('should get robot update info for an flex', () => { - getRobotByName.mockReturnValue({ + vi.mocked(discoSelectors.getRobotByName).mockReturnValue({ serverHealth: { robotModel: 'OT-3 Standard' }, } as any) const state: State = { @@ -67,7 +55,7 @@ describe('robot update selectors', () => { it('should get the update version from the auto-downloaded file for a flex', () => { const state: State = { robotUpdate: { flex: { version: '1.0.0' } } } as any - getRobotByName.mockReturnValue({ + vi.mocked(discoSelectors.getRobotByName).mockReturnValue({ serverHealth: { robotModel: 'OT-3 Standard' }, } as any) const result = selectors.getRobotUpdateTargetVersion(state, 'some-flex') @@ -77,7 +65,7 @@ describe('robot update selectors', () => { it('should get the update version from the auto-downloaded file for an ot2', () => { const state: State = { robotUpdate: { ot2: { version: '1.0.0' } } } as any - getRobotByName.mockReturnValue({ + vi.mocked(discoSelectors.getRobotByName).mockReturnValue({ serverHealth: { robotModel: 'OT-2 Standard' }, } as any) const result = selectors.getRobotUpdateTargetVersion(state, 'some-ot2') @@ -92,7 +80,7 @@ describe('robot update selectors', () => { session: { fileInfo: { version: '1.0.1' } }, }, } as any - getRobotByName.mockReturnValue({ + vi.mocked(discoSelectors.getRobotByName).mockReturnValue({ serverHealth: { robotModel: 'OT-3 Standard' }, } as any) const result = selectors.getRobotUpdateTargetVersion(state, 'some-flex') @@ -107,7 +95,7 @@ describe('robot update selectors', () => { session: { fileInfo: { version: '1.0.1' } }, }, } as any - getRobotByName.mockReturnValue({ + vi.mocked(discoSelectors.getRobotByName).mockReturnValue({ serverHealth: { robotModel: 'OT-2 Standard' }, } as any) const result = selectors.getRobotUpdateTargetVersion(state, 'some-ot2') @@ -119,7 +107,7 @@ describe('robot update selectors', () => { const state: State = { robotUpdate: { flex: { downloadError: 'error with download' } }, } as any - getRobotByName.mockReturnValue({ + vi.mocked(discoSelectors.getRobotByName).mockReturnValue({ serverHealth: { robotModel: 'OT-3 Standard' }, } as any) const result = selectors.getRobotUpdateDownloadError(state, 'some-flex') @@ -131,7 +119,7 @@ describe('robot update selectors', () => { const state: State = { robotUpdate: { ot2: { downloadError: 'error with download' } }, } as any - getRobotByName.mockReturnValue({ + vi.mocked(discoSelectors.getRobotByName).mockReturnValue({ serverHealth: { robotModel: 'OT-2 Standard' }, } as any) const result = selectors.getRobotUpdateDownloadError(state, 'some-ot2') @@ -143,7 +131,7 @@ describe('robot update selectors', () => { const state: State = { robotUpdate: { ot2: { downloadProgress: 10 } }, } as any - getRobotByName.mockReturnValue({ + vi.mocked(discoSelectors.getRobotByName).mockReturnValue({ serverHealth: { robotModel: 'OT-2 Standard' }, } as any) const result = selectors.getRobotUpdateDownloadProgress(state, 'some-ot2') @@ -155,7 +143,7 @@ describe('robot update selectors', () => { const state: State = { robotUpdate: { flex: { downloadProgress: 10 } }, } as any - getRobotByName.mockReturnValue({ + vi.mocked(discoSelectors.getRobotByName).mockReturnValue({ serverHealth: { robotModel: 'OT-3 Standard' }, } as any) const result = selectors.getRobotUpdateDownloadProgress(state, 'flex') @@ -164,16 +152,18 @@ describe('robot update selectors', () => { }) it('should return "upgrade" update type when an ot2 is behind the update', () => { - getRobotByName.mockReturnValue({ + vi.mocked(discoSelectors.getRobotByName).mockReturnValue({ serverHealth: { robotModel: 'OT-2 Standard' }, } as any) const state: State = { robotUpdate: { ot2: { version: '1.0.0' } } } as any const robot = { name: 'robot-name' } as any - getRobotApiVersion.mockImplementation(inputRobot => { - expect(inputRobot).toBe(robot) - return '0.9.9' - }) + vi.mocked(discoSelectors.getRobotApiVersion).mockImplementation( + inputRobot => { + expect(inputRobot).toBe(robot) + return '0.9.9' + } + ) const result = selectors.getRobotUpdateAvailable(state, robot) @@ -181,16 +171,18 @@ describe('robot update selectors', () => { }) it('should return "upgrade" update type when a flex is behind the update', () => { - getRobotByName.mockReturnValue({ + vi.mocked(discoSelectors.getRobotByName).mockReturnValue({ serverHealth: { robotModel: 'OT-3 Standard' }, } as any) const state: State = { robotUpdate: { flex: { version: '1.0.0' } } } as any const robot = { name: 'robot-name' } as any - getRobotApiVersion.mockImplementation(inputRobot => { - expect(inputRobot).toBe(robot) - return '0.9.9' - }) + vi.mocked(discoSelectors.getRobotApiVersion).mockImplementation( + inputRobot => { + expect(inputRobot).toBe(robot) + return '0.9.9' + } + ) const result = selectors.getRobotUpdateAvailable(state, robot) @@ -198,13 +190,13 @@ describe('robot update selectors', () => { }) it('should return "downgrade" update type when an ot2 is ahead of the update', () => { - getRobotByName.mockReturnValue({ + vi.mocked(discoSelectors.getRobotByName).mockReturnValue({ serverHealth: { robotModel: 'OT-2 Standard' }, } as any) const state: State = { robotUpdate: { ot2: { version: '1.0.0' } } } as any const robot = { name: 'robot-name' } as any - getRobotApiVersion.mockReturnValue('1.0.1') + vi.mocked(discoSelectors.getRobotApiVersion).mockReturnValue('1.0.1') const result = selectors.getRobotUpdateAvailable(state, robot) @@ -212,13 +204,13 @@ describe('robot update selectors', () => { }) it('should return "downgrade" update type when a flex is ahead of the update', () => { - getRobotByName.mockReturnValue({ + vi.mocked(discoSelectors.getRobotByName).mockReturnValue({ serverHealth: { robotModel: 'OT-3 Standard' }, } as any) const state: State = { robotUpdate: { flex: { version: '1.0.0' } } } as any const robot = { name: 'robot-name' } as any - getRobotApiVersion.mockReturnValue('1.0.1') + vi.mocked(discoSelectors.getRobotApiVersion).mockReturnValue('1.0.1') const result = selectors.getRobotUpdateAvailable(state, robot) @@ -226,13 +218,13 @@ describe('robot update selectors', () => { }) it('should get "reinstall" update type when ot-2 matches the update', () => { - getRobotByName.mockReturnValue({ + vi.mocked(discoSelectors.getRobotByName).mockReturnValue({ serverHealth: { robotModel: 'OT-2 Standard' }, } as any) const state: State = { robotUpdate: { ot2: { version: '1.0.0' } } } as any const robot = { name: 'robot-name' } as any - getRobotApiVersion.mockReturnValue('1.0.0') + vi.mocked(discoSelectors.getRobotApiVersion).mockReturnValue('1.0.0') const result = selectors.getRobotUpdateAvailable(state, robot) @@ -240,13 +232,13 @@ describe('robot update selectors', () => { }) it('should get "reinstall" update type when flex matches the update', () => { - getRobotByName.mockReturnValue({ + vi.mocked(discoSelectors.getRobotByName).mockReturnValue({ serverHealth: { robotModel: 'OT-3 Standard' }, } as any) const state: State = { robotUpdate: { flex: { version: '1.0.0' } } } as any const robot = { name: 'robot-name' } as any - getRobotApiVersion.mockReturnValue('1.0.0') + vi.mocked(discoSelectors.getRobotApiVersion).mockReturnValue('1.0.0') const result = selectors.getRobotUpdateAvailable(state, robot) @@ -254,13 +246,13 @@ describe('robot update selectors', () => { }) it('should return null update type when no update available for an ot2', () => { - getRobotByName.mockReturnValue({ + vi.mocked(discoSelectors.getRobotByName).mockReturnValue({ serverHealth: { robotModel: 'OT-2 Standard' }, } as any) const state: State = { robotUpdate: { ot2: { version: null } } } as any const robot = { name: 'robot-name' } as any - getRobotApiVersion.mockReturnValue('1.0.0') + vi.mocked(discoSelectors.getRobotApiVersion).mockReturnValue('1.0.0') const result = selectors.getRobotUpdateAvailable(state, robot) @@ -268,13 +260,13 @@ describe('robot update selectors', () => { }) it('should return null update type when no update available for a flex', () => { - getRobotByName.mockReturnValue({ + vi.mocked(discoSelectors.getRobotByName).mockReturnValue({ serverHealth: { robotModel: 'OT-3 Standard' }, } as any) const state: State = { robotUpdate: { flex: { version: null } } } as any const robot = { name: 'robot-name' } as any - getRobotApiVersion.mockReturnValue('1.0.0') + vi.mocked(discoSelectors.getRobotApiVersion).mockReturnValue('1.0.0') const result = selectors.getRobotUpdateAvailable(state, robot) @@ -282,13 +274,13 @@ describe('robot update selectors', () => { }) it('should return null update type when no robot version available for ot2', () => { - getRobotByName.mockReturnValue({ + vi.mocked(discoSelectors.getRobotByName).mockReturnValue({ serverHealth: { robotModel: 'OT-2 Standard' }, } as any) const state: State = { robotUpdate: { ot2: { version: '1.0.0' } } } as any const robot = { name: 'robot-name' } as any - getRobotApiVersion.mockReturnValue(null) + vi.mocked(discoSelectors.getRobotApiVersion).mockReturnValue(null) const result = selectors.getRobotUpdateAvailable(state, robot) @@ -296,13 +288,13 @@ describe('robot update selectors', () => { }) it('should return null update type when no robot version available for flex', () => { - getRobotByName.mockReturnValue({ + vi.mocked(discoSelectors.getRobotByName).mockReturnValue({ serverHealth: { robotModel: 'OT-3 Standard' }, } as any) const state: State = { robotUpdate: { flex: { version: '1.0.0' } } } as any const robot = { name: 'robot-name' } as any - getRobotApiVersion.mockReturnValue(null) + vi.mocked(discoSelectors.getRobotApiVersion).mockReturnValue(null) const result = selectors.getRobotUpdateAvailable(state, robot) @@ -342,14 +334,16 @@ describe('robot update selectors', () => { }, } as any - getViewableRobots.mockImplementation(inputState => { - expect(inputState).toBe(state) - return [ - { name: 'other-robot-name', host: '10.10.0.1', port: 31950 }, - { name: 'robot-name', host: '10.10.0.0', port: 31950 }, - { name: 'another-robot-name', host: '10.10.0.2', port: 31950 }, - ] as any - }) + vi.mocked(discoSelectors.getViewableRobots).mockImplementation( + inputState => { + expect(inputState).toBe(state) + return [ + { name: 'other-robot-name', host: '10.10.0.1', port: 31950 }, + { name: 'robot-name', host: '10.10.0.0', port: 31950 }, + { name: 'another-robot-name', host: '10.10.0.2', port: 31950 }, + ] as any + } + ) const result = selectors.getRobotUpdateRobot(state) expect(result).toEqual({ @@ -377,7 +371,7 @@ describe('robot update selectors', () => { }, } as any - getViewableRobots.mockReturnValue([ + vi.mocked(discoSelectors.getViewableRobots).mockReturnValue([ { name: 'other-robot-name', host: '10.10.0.1', port: 31950 }, { name: 'robot-name', @@ -405,7 +399,7 @@ describe('robot update selectors', () => { serverHealth: { capabilities: { buildrootUpdate: '/' } }, } as any - getViewableRobots.mockReturnValue([ + vi.mocked(discoSelectors.getViewableRobots).mockReturnValue([ { name: 'other-robot-name', host: '10.10.0.1', port: 31950 }, robot, { name: 'another-robot-name', host: '10.10.0.2', port: 31950 }, @@ -468,11 +462,13 @@ describe('robot update selectors', () => { const state: State = { robotUpdate: {} } as any const robotName = 'robot-name' - getRobotByName.mockImplementation((inputState, inputName) => { - expect(inputState).toBe(state) - expect(inputName).toBe(robotName) - return null - }) + vi.mocked(discoSelectors.getRobotByName).mockImplementation( + (inputState, inputName) => { + expect(inputState).toBe(state) + expect(inputName).toBe(robotName) + return null + } + ) const result = selectors.getRobotUpdateDisplayInfo(state, robotName) @@ -490,7 +486,7 @@ describe('robot update selectors', () => { const state: State = { robotUpdate: {} } as any const robotName = 'robot-name' - getRobotByName.mockReturnValue({ + vi.mocked(discoSelectors.getRobotByName).mockReturnValue({ ...mockReachableRobot, serverHealthStatus: HEALTH_STATUS_NOT_OK, }) @@ -515,12 +511,17 @@ describe('robot update selectors', () => { const robot = { ...mockReachableRobot, name: robotName } const otherRobot = { ...mockReachableRobot, name: 'other-name' } - getRobotByName.mockReturnValue(robot) - getViewableRobots.mockReturnValue([robot, otherRobot]) - getRobotApiVersion.mockImplementation(inputRobot => { - expect(inputRobot).toBe(robot) - return '1.0.0' - }) + vi.mocked(discoSelectors.getRobotByName).mockReturnValue(robot) + vi.mocked(discoSelectors.getViewableRobots).mockReturnValue([ + robot, + otherRobot, + ]) + vi.mocked(discoSelectors.getRobotApiVersion).mockImplementation( + inputRobot => { + expect(inputRobot).toBe(robot) + return '1.0.0' + } + ) const result = selectors.getRobotUpdateDisplayInfo(state, robotName) @@ -539,8 +540,8 @@ describe('robot update selectors', () => { const robotName = 'robot-name' const robot = { ...mockReachableRobot, name: robotName } - getRobotByName.mockReturnValue(robot) - getRobotApiVersion.mockReturnValue('1.0.0') + vi.mocked(discoSelectors.getRobotByName).mockReturnValue(robot) + vi.mocked(discoSelectors.getRobotApiVersion).mockReturnValue('1.0.0') const result = selectors.getRobotUpdateDisplayInfo(state, robotName) @@ -565,8 +566,8 @@ describe('robot update selectors', () => { }, } as any - getRobotByName.mockReturnValue(robot) - getRobotApiVersion.mockReturnValue('0.9.9') + vi.mocked(discoSelectors.getRobotByName).mockReturnValue(robot) + vi.mocked(discoSelectors.getRobotApiVersion).mockReturnValue('0.9.9') const result = selectors.getRobotUpdateDisplayInfo(state, robotName) @@ -589,8 +590,8 @@ describe('robot update selectors', () => { }, } - getRobotByName.mockReturnValue(robot as any) - getRobotApiVersion.mockReturnValue('0.9.9') + vi.mocked(discoSelectors.getRobotByName).mockReturnValue(robot as any) + vi.mocked(discoSelectors.getRobotApiVersion).mockReturnValue('0.9.9') const result = selectors.getRobotUpdateDisplayInfo(state, robotName) diff --git a/app/src/redux/sessions/__fixtures__/calibration-check.ts b/app/src/redux/sessions/__fixtures__/calibration-check.ts index d2c0cc70d74..befc555e239 100644 --- a/app/src/redux/sessions/__fixtures__/calibration-check.ts +++ b/app/src/redux/sessions/__fixtures__/calibration-check.ts @@ -7,7 +7,7 @@ import type { CalibrationLabware, } from '../types' -import tipRackFixture from '@opentrons/shared-data/labware/fixtures/2/fixture_tiprack_300_ul.json' +import { fixtureTiprack300ul } from '@opentrons/shared-data' import { CHECK_STEP_COMPARING_HEIGHT, CHECK_STEP_COMPARING_POINT_ONE, @@ -22,7 +22,7 @@ export const mockCalibrationCheckLabware: CalibrationLabware = { namespace: 'opentrons', version: 1, isTiprack: true, - definition: tipRackFixture as CalibrationLabware['definition'], + definition: fixtureTiprack300ul as CalibrationLabware['definition'], } export const badZComparison: CalibrationCheckComparison = { diff --git a/app/src/redux/sessions/__fixtures__/deck-calibration.ts b/app/src/redux/sessions/__fixtures__/deck-calibration.ts index 814c4268f22..2d6b8e7605d 100644 --- a/app/src/redux/sessions/__fixtures__/deck-calibration.ts +++ b/app/src/redux/sessions/__fixtures__/deck-calibration.ts @@ -1,4 +1,4 @@ -import tipRackFixture from '@opentrons/shared-data/labware/fixtures/2/fixture_tiprack_300_ul.json' +import { fixtureTiprack300ul } from '@opentrons/shared-data' import type { DeckCalibrationSessionDetails, CalibrationLabware, @@ -10,7 +10,7 @@ export const mockDeckCalTipRack: CalibrationLabware = { namespace: 'opentrons', version: 1, isTiprack: true, - definition: tipRackFixture as CalibrationLabware['definition'], + definition: fixtureTiprack300ul as CalibrationLabware['definition'], } export const mockDeckCalibrationSessionDetails: DeckCalibrationSessionDetails = { diff --git a/app/src/redux/sessions/__fixtures__/pipette-offset-calibration.ts b/app/src/redux/sessions/__fixtures__/pipette-offset-calibration.ts index b3755841d24..80391cdc3ff 100644 --- a/app/src/redux/sessions/__fixtures__/pipette-offset-calibration.ts +++ b/app/src/redux/sessions/__fixtures__/pipette-offset-calibration.ts @@ -1,4 +1,4 @@ -import tipRackFixture from '@opentrons/shared-data/labware/fixtures/2/fixture_tiprack_300_ul.json' +import { fixtureTiprack300ul } from '@opentrons/shared-data' import type { PipetteOffsetCalibrationSessionDetails, CalibrationLabware, @@ -11,7 +11,7 @@ export const mockPipetteOffsetTipRack: CalibrationLabware = { namespace: 'opentrons', version: 1, isTiprack: true, - definition: tipRackFixture as CalibrationLabware['definition'], + definition: fixtureTiprack300ul as CalibrationLabware['definition'], } export const mockPipetteOffsetCalibrationSessionDetails: PipetteOffsetCalibrationSessionDetails = { diff --git a/app/src/redux/sessions/__fixtures__/tip-length-calibration.ts b/app/src/redux/sessions/__fixtures__/tip-length-calibration.ts index fbb433c063b..b22548ebbd7 100644 --- a/app/src/redux/sessions/__fixtures__/tip-length-calibration.ts +++ b/app/src/redux/sessions/__fixtures__/tip-length-calibration.ts @@ -1,18 +1,23 @@ -import tipRackFixture from '@opentrons/shared-data/labware/fixtures/2/fixture_tiprack_300_ul.json' -import calBlockFixture from '@opentrons/shared-data/labware/definitions/2/opentrons_calibrationblock_short_side_left/1.json' +import { fixtureTiprack300ul } from '@opentrons/shared-data' +// import calBlockFixture from '@opentrons/shared-data/labware/definitions/2/opentrons_calibrationblock_short_side_left/1.json' +import { getLatestLabwareDef } from '../../../assets/labware/getLabware' import type { TipLengthCalibrationSessionDetails, CalibrationLabware, } from '../types' import type { TipLengthCalibrationSessionParams } from '../tip-length-calibration/types' +const calBlockFixture = getLatestLabwareDef( + 'opentrons_calibrationblock_short_side_left' +) + export const mockTipLengthTipRack: CalibrationLabware = { slot: '8', loadName: 'opentrons_96_tiprack_300ul', namespace: 'opentrons', version: 1, isTiprack: true, - definition: tipRackFixture as CalibrationLabware['definition'], + definition: fixtureTiprack300ul as CalibrationLabware['definition'], } export const mockTipLengthCalBlock: CalibrationLabware = { @@ -41,5 +46,5 @@ export const mockTipLengthCalibrationSessionDetails: TipLengthCalibrationSession export const mockTipLengthCalibrationSessionParams: TipLengthCalibrationSessionParams = { mount: 'left', hasCalibrationBlock: true, - tipRackDefinition: tipRackFixture as CalibrationLabware['definition'], + tipRackDefinition: fixtureTiprack300ul as CalibrationLabware['definition'], } diff --git a/app/src/redux/sessions/__tests__/actions.test.ts b/app/src/redux/sessions/__tests__/actions.test.ts index d5381d9a5d8..a134f529d9d 100644 --- a/app/src/redux/sessions/__tests__/actions.test.ts +++ b/app/src/redux/sessions/__tests__/actions.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import * as Actions from '../actions' import * as Fixtures from '../__fixtures__' diff --git a/app/src/redux/sessions/__tests__/reducer.test.ts b/app/src/redux/sessions/__tests__/reducer.test.ts index 503351f80a0..2376e4cad4a 100644 --- a/app/src/redux/sessions/__tests__/reducer.test.ts +++ b/app/src/redux/sessions/__tests__/reducer.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import * as Fixtures from '../__fixtures__' import * as Actions from '../actions' import { sessionReducer } from '../reducer' diff --git a/app/src/redux/sessions/epic/__tests__/createSessionCommandEpic.test.ts b/app/src/redux/sessions/epic/__tests__/createSessionCommandEpic.test.ts index c886f26997d..c587cb53e2b 100644 --- a/app/src/redux/sessions/epic/__tests__/createSessionCommandEpic.test.ts +++ b/app/src/redux/sessions/epic/__tests__/createSessionCommandEpic.test.ts @@ -1,3 +1,5 @@ +import { vi, describe, it, expect, afterEach } from 'vitest' + import { setupEpicTestMocks, runEpicTest } from '../../../robot-api/__utils__' import * as RobotApiHttp from '../../../robot-api/http' @@ -8,18 +10,14 @@ import { sessionsEpic } from '..' import type { Action } from '../../../types' import { CreateSessionCommandAction } from '../../types' -jest.mock('../../../robot-api/http') - -const fetchRobotApi = RobotApiHttp.fetchRobotApi as jest.MockedFunction< - typeof RobotApiHttp.fetchRobotApi -> +vi.mock('../../../robot-api/http') const makeTriggerAction = (robotName: string): CreateSessionCommandAction => Actions.createSessionCommand(robotName, '1234', Fixtures.mockSessionCommand) describe('createSessionCommandEpic', () => { afterEach(() => { - jest.resetAllMocks() + vi.resetAllMocks() }) const expectedCommandRequest = { @@ -44,10 +42,10 @@ describe('createSessionCommandEpic', () => { const mocks = setupEpicTestMocks(makeTriggerAction) runEpicTest(mocks, ({ hot, cold, expectObservable, flush }) => { - fetchRobotApi.mockReturnValueOnce( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValueOnce( cold('r', { r: Fixtures.mockSessionCommandsSuccess }) ) - fetchRobotApi.mockReturnValueOnce( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValueOnce( cold('r', { r: Fixtures.mockFetchSessionSuccess }) ) @@ -76,7 +74,7 @@ describe('createSessionCommandEpic', () => { const mocks = setupEpicTestMocks(makeTriggerAction) runEpicTest(mocks, ({ hot, cold, expectObservable, flush }) => { - fetchRobotApi.mockReturnValueOnce( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValueOnce( cold('r', { r: Fixtures.mockSessionCommandsFailure }) ) @@ -95,10 +93,10 @@ describe('createSessionCommandEpic', () => { const mocks = setupEpicTestMocks(makeTriggerAction) runEpicTest(mocks, ({ hot, cold, expectObservable, flush }) => { - fetchRobotApi.mockReturnValueOnce( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValueOnce( cold('-r', { r: Fixtures.mockSessionCommandsSuccess }) ) - fetchRobotApi.mockReturnValueOnce( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValueOnce( cold('-r', { r: Fixtures.mockFetchSessionSuccess }) ) @@ -143,10 +141,10 @@ describe('createSessionCommandEpic', () => { const mocks = setupEpicTestMocks(makeTriggerAction) runEpicTest(mocks, ({ hot, cold, expectObservable, flush }) => { - fetchRobotApi.mockReturnValueOnce( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValueOnce( cold('-r', { r: Fixtures.mockSessionCommandsSuccess }) ) - fetchRobotApi.mockReturnValueOnce( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValueOnce( cold('-r', { r: Fixtures.mockFetchSessionFailure }) ) diff --git a/app/src/redux/sessions/epic/__tests__/createSessionEpic.test.ts b/app/src/redux/sessions/epic/__tests__/createSessionEpic.test.ts index f4ef93f3f8f..332a63ec3ec 100644 --- a/app/src/redux/sessions/epic/__tests__/createSessionEpic.test.ts +++ b/app/src/redux/sessions/epic/__tests__/createSessionEpic.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import { setupEpicTestMocks, runEpicTest } from '../../../robot-api/__utils__' import * as Fixtures from '../../__fixtures__' @@ -10,10 +12,6 @@ const makeTriggerAction = (robotName: string) => Actions.createSession(robotName, 'calibrationCheck') describe('createSessionEpic', () => { - afterEach(() => { - jest.resetAllMocks() - }) - const expectedRequest = { method: 'POST', path: '/sessions', diff --git a/app/src/redux/sessions/epic/__tests__/deleteSessionEpic.test.ts b/app/src/redux/sessions/epic/__tests__/deleteSessionEpic.test.ts index 2d17eccef67..25a2cefdccc 100644 --- a/app/src/redux/sessions/epic/__tests__/deleteSessionEpic.test.ts +++ b/app/src/redux/sessions/epic/__tests__/deleteSessionEpic.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import { setupEpicTestMocks, runEpicTest } from '../../../robot-api/__utils__' import * as Fixtures from '../../__fixtures__' @@ -10,10 +12,6 @@ const makeTriggerAction = (robotName: string) => Actions.deleteSession(robotName, Fixtures.mockSessionId) describe('deleteSessionEpic', () => { - afterEach(() => { - jest.resetAllMocks() - }) - const expectedRequest = { method: 'DELETE', path: `/sessions/${Fixtures.mockSessionId}`, diff --git a/app/src/redux/sessions/epic/__tests__/ensureSessionEpic.test.ts b/app/src/redux/sessions/epic/__tests__/ensureSessionEpic.test.ts index fdaea35ea9a..46d3a7015a2 100644 --- a/app/src/redux/sessions/epic/__tests__/ensureSessionEpic.test.ts +++ b/app/src/redux/sessions/epic/__tests__/ensureSessionEpic.test.ts @@ -1,3 +1,5 @@ +import { vi, describe, it, expect, afterEach } from 'vitest' + import { setupEpicTestMocks, runEpicTest } from '../../../robot-api/__utils__' import * as RobotApiHttp from '../../../robot-api/http' @@ -7,11 +9,7 @@ import { sessionsEpic } from '..' import type { Action } from '../../../types' -jest.mock('../../../robot-api/http') - -const fetchRobotApi = RobotApiHttp.fetchRobotApi as jest.MockedFunction< - typeof RobotApiHttp.fetchRobotApi -> +vi.mock('../../../robot-api/http') const makeTriggerAction = (robotName: string): Action => Actions.ensureSession(robotName, 'calibrationCheck', { @@ -45,7 +43,7 @@ const mockEmptyFetchAllSuccess = { describe('ensureSessionEpic', () => { afterEach(() => { - jest.resetAllMocks() + vi.resetAllMocks() }) it('calls GET /sessions', () => { @@ -115,11 +113,11 @@ describe('ensureSessionEpic', () => { const mocks = setupEpicTestMocks(makeTriggerAction) runEpicTest(mocks, ({ hot, cold, expectObservable, flush }) => { - fetchRobotApi.mockReturnValueOnce( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValueOnce( cold('r', { r: mockEmptyFetchAllSuccess }) ) - fetchRobotApi.mockReturnValueOnce( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValueOnce( cold('r', { r: Fixtures.mockCreateSessionSuccess }) ) @@ -142,11 +140,11 @@ describe('ensureSessionEpic', () => { const mocks = setupEpicTestMocks(makeTriggerAction) runEpicTest(mocks, ({ hot, cold, expectObservable }) => { - fetchRobotApi.mockReturnValueOnce( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValueOnce( cold('r', { r: mockEmptyFetchAllSuccess }) ) - fetchRobotApi.mockReturnValueOnce( + vi.mocked(RobotApiHttp.fetchRobotApi).mockReturnValueOnce( cold('r', { r: Fixtures.mockCreateSessionFailure }) ) diff --git a/app/src/redux/sessions/epic/__tests__/fetchAllSessionsEpic.test.ts b/app/src/redux/sessions/epic/__tests__/fetchAllSessionsEpic.test.ts index 2a27faf1c3c..62ddfdd2dc4 100644 --- a/app/src/redux/sessions/epic/__tests__/fetchAllSessionsEpic.test.ts +++ b/app/src/redux/sessions/epic/__tests__/fetchAllSessionsEpic.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import { setupEpicTestMocks, runEpicTest } from '../../../robot-api/__utils__' import * as Fixtures from '../../__fixtures__' @@ -11,10 +13,6 @@ const makeTriggerAction = (robotName: string) => Actions.fetchAllSessions(robotName) describe('fetchAllSessionsEpic', () => { - afterEach(() => { - jest.resetAllMocks() - }) - const expectedRequest = { method: 'GET', path: '/sessions', diff --git a/app/src/redux/sessions/epic/__tests__/fetchSessionEpic.test.ts b/app/src/redux/sessions/epic/__tests__/fetchSessionEpic.test.ts index 63c3cd4226f..e25face2390 100644 --- a/app/src/redux/sessions/epic/__tests__/fetchSessionEpic.test.ts +++ b/app/src/redux/sessions/epic/__tests__/fetchSessionEpic.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import { setupEpicTestMocks, runEpicTest } from '../../../robot-api/__utils__' import * as Fixtures from '../../__fixtures__' @@ -11,10 +13,6 @@ const makeTriggerAction = (robotName: string) => Actions.fetchSession(robotName, Fixtures.mockSessionId) describe('fetchSessionEpic', () => { - afterEach(() => { - jest.resetAllMocks() - }) - const expectedRequest = { method: 'GET', path: `/sessions/${Fixtures.mockSessionId}`, diff --git a/app/src/redux/shell/__mocks__/remote.ts b/app/src/redux/shell/__mocks__/remote.ts index 8fd950ba097..8af4a39df7b 100644 --- a/app/src/redux/shell/__mocks__/remote.ts +++ b/app/src/redux/shell/__mocks__/remote.ts @@ -1,10 +1,11 @@ // mock remote object // keep in sync with app-shell/src/preload.js +import { vi } from 'vitest' const EventEmitter = require('events') class MockIpcRenderer extends EventEmitter { - send = jest.fn() + send = vi.fn() as any } export const remote = { ipcRenderer: new MockIpcRenderer() } diff --git a/app/src/redux/shell/__tests__/actions.test.ts b/app/src/redux/shell/__tests__/actions.test.ts index b9b1ef100e1..7edf16f1b64 100644 --- a/app/src/redux/shell/__tests__/actions.test.ts +++ b/app/src/redux/shell/__tests__/actions.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import { uiInitialized, notifySubscribeAction, diff --git a/app/src/redux/shell/__tests__/epics.test.ts b/app/src/redux/shell/__tests__/epics.test.ts index 2056a30c7dc..c4b8aaa73f2 100644 --- a/app/src/redux/shell/__tests__/epics.test.ts +++ b/app/src/redux/shell/__tests__/epics.test.ts @@ -1,4 +1,4 @@ -// tests for the shell module +import { vi, describe, it, expect, beforeEach, afterEach } from 'vitest' import { EMPTY } from 'rxjs' import { TestScheduler } from 'rxjs/testing' import { take } from 'rxjs/operators' @@ -13,22 +13,18 @@ import type { Action, State } from '../../types' const { ipcRenderer: mockIpc } = mockRemote -jest.mock('../../config') +vi.mock('../../config') +vi.mock('../remote') // TODO(mc, 2020-10-08): this is a partial mock because shell/update // needs some reorg to split actions and selectors -jest.mock('../update', () => ({ - ...jest.requireActual<{}>('../update'), - getAvailableShellUpdate: jest.fn(), -})) - -const getUpdateChannel = Config.getUpdateChannel as jest.MockedFunction< - typeof Config.getUpdateChannel -> - -const getAvailableShellUpdate = ShellUpdate.getAvailableShellUpdate as jest.MockedFunction< - typeof ShellUpdate.getAvailableShellUpdate -> +vi.mock('../update', async importOriginal => { + const actual = (await importOriginal()) as any + return { + ...actual, + getAvailableShellUpdate: vi.fn(), + } +}) describe('shell epics', () => { let testScheduler: TestScheduler @@ -40,7 +36,7 @@ describe('shell epics', () => { }) afterEach(() => { - jest.resetAllMocks() + vi.resetAllMocks() }) it('"dispatches" actions to IPC if meta.shell', () => { @@ -72,8 +68,8 @@ describe('shell epics', () => { it('triggers an appUpdateAvailable alert if an app update becomes available', () => { const mockState: State = { mockState: true } as any - getAvailableShellUpdate.mockReturnValueOnce(null) - getAvailableShellUpdate.mockReturnValue('1.2.3') + vi.mocked(ShellUpdate.getAvailableShellUpdate).mockReturnValueOnce(null) + vi.mocked(ShellUpdate.getAvailableShellUpdate).mockReturnValue('1.2.3') testScheduler.run(({ hot, expectObservable }) => { const action$ = hot('----') @@ -91,8 +87,8 @@ describe('shell epics', () => { it('should trigger a shell:CHECK_UPDATE action if the update channel changes', () => { const mockState: State = { mockState: true } as any - getUpdateChannel.mockReturnValueOnce('latest') - getUpdateChannel.mockReturnValue('beta') + vi.mocked(Config.getUpdateChannel).mockReturnValueOnce('latest') + vi.mocked(Config.getUpdateChannel).mockReturnValue('beta') testScheduler.run(({ hot, expectObservable }) => { const action$ = hot('------') diff --git a/app/src/redux/shell/__tests__/update.test.ts b/app/src/redux/shell/__tests__/update.test.ts index f87c124952e..b3b4048b9db 100644 --- a/app/src/redux/shell/__tests__/update.test.ts +++ b/app/src/redux/shell/__tests__/update.test.ts @@ -1,4 +1,4 @@ -// shell/update tests +import { describe, it, expect } from 'vitest' import * as ShellUpdate from '../update' import { shellUpdateReducer } from '../reducer' diff --git a/app/src/redux/system-info/__tests__/actions.test.ts b/app/src/redux/system-info/__tests__/actions.test.ts index 76a352c724b..8aa9219f426 100644 --- a/app/src/redux/system-info/__tests__/actions.test.ts +++ b/app/src/redux/system-info/__tests__/actions.test.ts @@ -1,4 +1,4 @@ -// system-info actions tests +import { describe, it, expect } from 'vitest' import * as Actions from '../actions' import * as Fixtures from '../__fixtures__' diff --git a/app/src/redux/system-info/__tests__/epic.test.ts b/app/src/redux/system-info/__tests__/epic.test.ts index 65bf1a62774..059411aba45 100644 --- a/app/src/redux/system-info/__tests__/epic.test.ts +++ b/app/src/redux/system-info/__tests__/epic.test.ts @@ -1,3 +1,4 @@ +import { vi, describe, it, expect, beforeEach } from 'vitest' import { TestScheduler } from 'rxjs/testing' import * as Alerts from '../../alerts' @@ -8,14 +9,10 @@ import { systemInfoEpic } from '../epic' import type { Action, State } from '../../types' import type { DriverStatus } from '../types' -jest.mock('../selectors') +vi.mock('../selectors') const MOCK_STATE: State = { mockState: true } as any -const getU2EWindowsDriverStatus = Selectors.getU2EWindowsDriverStatus as jest.MockedFunction< - typeof Selectors.getU2EWindowsDriverStatus -> - describe('system info epic', () => { let testScheduler: TestScheduler @@ -25,10 +22,12 @@ describe('system info epic', () => { expectedValues?: unknown ): void => { statusValues.forEach(status => { - getU2EWindowsDriverStatus.mockImplementationOnce(s => { - expect(s).toEqual(MOCK_STATE) - return status - }) + vi.mocked(Selectors.getU2EWindowsDriverStatus).mockImplementationOnce( + s => { + expect(s).toEqual(MOCK_STATE) + return status + } + ) }) testScheduler.run(({ hot, expectObservable }) => { @@ -41,7 +40,7 @@ describe('system info epic', () => { } beforeEach(() => { - getU2EWindowsDriverStatus.mockImplementation(s => { + vi.mocked(Selectors.getU2EWindowsDriverStatus).mockImplementation(s => { expect(s).toEqual(MOCK_STATE) return NOT_APPLICABLE }) @@ -50,10 +49,6 @@ describe('system info epic', () => { }) }) - afterEach(() => { - jest.resetAllMocks() - }) - it('should not trigger an alert if driver status never changes', () => { expectOutput([], '----') }) diff --git a/app/src/redux/system-info/__tests__/reducer.test.ts b/app/src/redux/system-info/__tests__/reducer.test.ts index 37c02915a59..c79a2e5c7fa 100644 --- a/app/src/redux/system-info/__tests__/reducer.test.ts +++ b/app/src/redux/system-info/__tests__/reducer.test.ts @@ -1,4 +1,4 @@ -// system-info reducer tests +import { describe, it, expect } from 'vitest' import * as Fixtures from '../__fixtures__' import * as Actions from '../actions' diff --git a/app/src/redux/system-info/__tests__/selectors.test.ts b/app/src/redux/system-info/__tests__/selectors.test.ts index 843df8ac5f0..00161a6d0bf 100644 --- a/app/src/redux/system-info/__tests__/selectors.test.ts +++ b/app/src/redux/system-info/__tests__/selectors.test.ts @@ -1,3 +1,5 @@ +import { vi, describe, it, expect } from 'vitest' + import * as Fixtures from '../__fixtures__' import * as Selectors from '../selectors' import * as Utils from '../utils' @@ -6,10 +8,6 @@ import * as Constants from '../constants' import type { State } from '../../types' describe('robot controls selectors', () => { - afterEach(() => { - jest.restoreAllMocks() - }) - it('should return null by default with getU2EAdapterDevice', () => { const state: State = { systemInfo: { usbDevices: [], networkInterfaces: [] }, @@ -46,7 +44,7 @@ describe('robot controls selectors', () => { }) it('should return status from utils.getDriverStatus if Windows Realtek device', () => { - const getDriverStatus = jest.spyOn(Utils, 'getDriverStatus') + const getDriverStatus = vi.spyOn(Utils, 'getDriverStatus') getDriverStatus.mockImplementation(d => { return d === Fixtures.mockWindowsRealtekDevice diff --git a/app/src/redux/system-info/__tests__/utils.test.ts b/app/src/redux/system-info/__tests__/utils.test.ts index 6c0adaad10d..193d4945224 100644 --- a/app/src/redux/system-info/__tests__/utils.test.ts +++ b/app/src/redux/system-info/__tests__/utils.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import { mockUsbDevice, mockRealtekDevice } from '../__fixtures__' import { isRealtekU2EAdapter, getDriverStatus } from '../utils' diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 546a878545f..a655396da76 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -479,6 +479,9 @@ importers: netmask: specifier: 2.0.2 version: 2.0.2 + node-fetch: + specifier: 2.6.7 + version: 2.6.7 path-to-regexp: specifier: 3.0.0 version: 3.0.0 @@ -561,6 +564,9 @@ importers: '@types/mixpanel-browser': specifier: ^2.35.6 version: 2.49.0 + '@types/node-fetch': + specifier: 2.6.11 + version: 2.6.11 '@types/styled-components': specifier: ^5.1.26 version: 5.1.34