|
| 1 | +import { beforeEach, test, vi } from 'vitest'; |
| 2 | +import assert from 'node:assert/strict'; |
| 3 | + |
| 4 | +vi.mock('../../platforms/apple/core/runner/runner-client.ts', async (importOriginal) => { |
| 5 | + const actual = |
| 6 | + await importOriginal<typeof import('../../platforms/apple/core/runner/runner-client.ts')>(); |
| 7 | + return { ...actual, runAppleRunnerCommand: vi.fn() }; |
| 8 | +}); |
| 9 | + |
| 10 | +import { dispatchCommand } from '../dispatch.ts'; |
| 11 | +import { runAppleRunnerCommand } from '../../platforms/apple/core/runner/runner-client.ts'; |
| 12 | +import { IOS_SIMULATOR } from '../../__tests__/test-utils/device-fixtures.ts'; |
| 13 | + |
| 14 | +const mockRunAppleRunnerCommand = vi.mocked(runAppleRunnerCommand); |
| 15 | + |
| 16 | +beforeEach(() => { |
| 17 | + vi.resetAllMocks(); |
| 18 | + mockRunAppleRunnerCommand.mockResolvedValue({ |
| 19 | + nodes: [{ index: 0, type: 'Application', rect: { x: 0, y: 0, width: 390, height: 844 } }], |
| 20 | + }); |
| 21 | +}); |
| 22 | + |
| 23 | +// #1634 P2: proves the whole daemon-side wire — dispatch context -> |
| 24 | +// handleSnapshotCommand -> interactor -> emitted RunnerCommand. Removing the |
| 25 | +// forwarding at any of those hops turns this red; the daemon corroboration |
| 26 | +// test (mocked dispatch) and the Swift plan-gate test cover the layers on |
| 27 | +// either side of it. |
| 28 | +test('dispatch snapshot forwards snapshotPreferredBackend to the runner command', async () => { |
| 29 | + await dispatchCommand(IOS_SIMULATOR, 'snapshot', [], undefined, { |
| 30 | + snapshotPreferredBackend: 'private-ax', |
| 31 | + }); |
| 32 | + |
| 33 | + const call = mockRunAppleRunnerCommand.mock.calls.find( |
| 34 | + ([, command]) => command.command === 'snapshot', |
| 35 | + ); |
| 36 | + assert.ok(call, 'expected a snapshot runner command'); |
| 37 | + assert.equal(call[1].preferredBackend, 'private-ax'); |
| 38 | +}); |
| 39 | + |
| 40 | +test('dispatch snapshot without a pin emits no preferredBackend', async () => { |
| 41 | + await dispatchCommand(IOS_SIMULATOR, 'snapshot', [], undefined, {}); |
| 42 | + |
| 43 | + const call = mockRunAppleRunnerCommand.mock.calls.find( |
| 44 | + ([, command]) => command.command === 'snapshot', |
| 45 | + ); |
| 46 | + assert.ok(call, 'expected a snapshot runner command'); |
| 47 | + assert.equal(call[1].preferredBackend, undefined); |
| 48 | +}); |
0 commit comments