From 36e36f2dd6b86915fb0dd60b45b866e65ed2826e Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Thu, 15 Oct 2026 14:01:13 -0700 Subject: [PATCH] [CI] Reuse web preload imports across local-field tests (#29202) Reuse the imported preload graph with explicit runtime cleanup between cases. --- ...reload-api-ui-pairing-local-fields.test.ts | 55 +++++++++++-------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/src/renderer/src/web/web-preload-api-ui-pairing-local-fields.test.ts b/src/renderer/src/web/web-preload-api-ui-pairing-local-fields.test.ts index 7a1cffeaedf..94e1329d980 100644 --- a/src/renderer/src/web/web-preload-api-ui-pairing-local-fields.test.ts +++ b/src/renderer/src/web/web-preload-api-ui-pairing-local-fields.test.ts @@ -1,4 +1,4 @@ -import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { afterEach, describe, expect, it, vi } from 'vitest' import { PAIRING_LOCAL_UI_FIELDS, type PairingLocalUiField @@ -10,15 +10,28 @@ import { writeStoredRuntimeEnvironment } from './web-preload-api-test-harness' -describe('web UI preload API pairing-local fields', () => { - beforeEach(() => { - vi.resetModules() - }) +const runtimeClient = vi.hoisted(() => ({ + call: vi.fn<(method: string, params?: unknown) => Promise>>() +})) - afterEach(() => { - vi.useRealTimers() - vi.unstubAllGlobals() - vi.doUnmock('./web-runtime-client') +vi.mock('./web-runtime-client', () => ({ + WebRuntimeClient: class { + call = runtimeClient.call + + close(): void {} + } +})) + +describe('web UI preload API pairing-local fields', () => { + afterEach(async () => { + try { + const { removeActiveRuntimeEnvironment } = await import('./preload-api/web-runtime-session') + removeActiveRuntimeEnvironment() + } finally { + runtimeClient.call.mockReset() + vi.useRealTimers() + vi.unstubAllGlobals() + } }) // Different host samples expose any missing browser-local pin. @@ -69,21 +82,15 @@ describe('web UI preload API pairing-local fields', () => { 'keeps the browser-local %s and never sends it to the host through %s', async (field, method) => { const runtimeCalls: { method: string; params: unknown }[] = [] - vi.doMock('./web-runtime-client', () => ({ - WebRuntimeClient: class { - call(method: string, params?: unknown): Promise> { - runtimeCalls.push({ method, params }) - return Promise.resolve({ - id: method, - ok: true, - result: { ui: { [field]: hostUiSamples[field] } }, - _meta: { runtimeId: 'runtime-1' } - }) - } - - close(): void {} - } - })) + runtimeClient.call.mockImplementation((method, params) => { + runtimeCalls.push({ method, params }) + return Promise.resolve({ + id: method, + ok: true, + result: { ui: { [field]: hostUiSamples[field] } }, + _meta: { runtimeId: 'runtime-1' } + }) + }) const browserLocal: Partial = { [field]: browserLocalUiSamples[field] } const globals = installBrowserGlobals('Linux')