Skip to content

Commit

Permalink
migrate discovery-client and api-client tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jerader committed Mar 1, 2024
1 parent aaaab0b commit 70d1ddc
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 155 deletions.
1 change: 1 addition & 0 deletions api-client/src/protocols/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from 'vitest'
import {
parsePipetteEntity,
parseInitialPipetteNamesByMount,
Expand Down
44 changes: 22 additions & 22 deletions discovery-client/src/__tests__/discovery-client.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, vi, expect, beforeEach, afterEach } from 'vitest'
import {
mockLegacyHealthResponse,
mockLegacyServerHealthResponse,
Expand All @@ -14,59 +15,58 @@ import { createDiscoveryClient } from '..'
import type { HealthPoller, HealthPollerResult, Logger } from '../types'
import type { MdnsBrowser, MdnsBrowserService } from '../mdns-browser'

jest.mock('../health-poller')
jest.mock('../mdns-browser')

const createHealthPoller = HealthPollerModule.createHealthPoller as jest.MockedFunction<
typeof HealthPollerModule.createHealthPoller
>

const createMdnsBrowser = MdnsBrowserModule.createMdnsBrowser as jest.MockedFunction<
typeof MdnsBrowserModule.createMdnsBrowser
>
vi.mock('../health-poller')
vi.mock('../mdns-browser')

const createHealthPoller = HealthPollerModule.createHealthPoller
const createMdnsBrowser = MdnsBrowserModule.createMdnsBrowser
const logger = ({} as unknown) as Logger

describe('discovery client', () => {
const onListChange = jest.fn()
const onListChange = vi.fn()

const healthPoller: {
start: jest.MockedFunction<HealthPoller['start']>
stop: jest.MockedFunction<HealthPoller['stop']>
start: any
stop: any
} = {
start: jest.fn(),
stop: jest.fn(),
start: vi.fn(),
stop: vi.fn(),
}

const mdnsBrowser: {
start: jest.MockedFunction<MdnsBrowser['start']>
stop: jest.MockedFunction<MdnsBrowser['stop']>
start: any
stop: any
} = {
start: jest.fn(),
stop: jest.fn(),
start: vi.fn(),
stop: vi.fn(),
}

const emitPollResult = (result: HealthPollerResult): void => {
// @ts-expect-error: mock doesn't exist on type
const { onPollResult } = createHealthPoller.mock.calls[
// @ts-expect-error: mock doesn't exist on type
createHealthPoller.mock.calls.length - 1
][0]
onPollResult(result)
}

const emitService = (service: MdnsBrowserService): void => {
// @ts-expect-error: mock doesn't exist on type
const { onService } = createMdnsBrowser.mock.calls[
// @ts-expect-error: mock doesn't exist on type

createMdnsBrowser.mock.calls.length - 1
][0]
onService(service)
}

beforeEach(() => {
createHealthPoller.mockReturnValue(healthPoller)
createMdnsBrowser.mockReturnValue(mdnsBrowser)
vi.mocked(createHealthPoller).mockReturnValue(healthPoller)
vi.mocked(createMdnsBrowser).mockReturnValue(mdnsBrowser)
})

afterEach(() => {
jest.resetAllMocks()
vi.resetAllMocks()
})

it('should create an mDNS browser and health poller', () => {
Expand Down
Loading

0 comments on commit 70d1ddc

Please sign in to comment.