perf: optimize app startup and background lifecycles
This commit is contained in:
@@ -89,4 +89,28 @@ describe('Host API IPC proxy', () => {
|
||||
expect(headers.get('authorization')).toBe('Bearer host-token');
|
||||
expect(headers.get('x-niancode-renderer-capability')).toBe('renderer-token');
|
||||
});
|
||||
|
||||
it('dispatches short JSON requests in Main without opening loopback HTTP', async () => {
|
||||
const fetchMock = vi.fn();
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
vi.doMock('../../electron/api/host-api-dispatcher', () => ({
|
||||
dispatchHostApiRequest: vi.fn().mockResolvedValue({
|
||||
status: 200,
|
||||
ok: true,
|
||||
json: { success: true, transport: 'test' },
|
||||
}),
|
||||
}));
|
||||
|
||||
const { registerHostApiProxyHandlers } = await import('../../electron/main/ipc/host-api-proxy');
|
||||
registerHostApiProxyHandlers({} as never);
|
||||
|
||||
const fetchHandler = handleMock.mock.calls.find(([channel]) => channel === 'hostapi:fetch')?.[1];
|
||||
const result = await fetchHandler(undefined, { path: '/api/app/runtime-info' });
|
||||
|
||||
expect(fetchMock).not.toHaveBeenCalled();
|
||||
expect(result).toEqual({
|
||||
ok: true,
|
||||
data: { status: 200, ok: true, json: { success: true, transport: 'test' }, transport: 'dispatcher' },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user