Files
Genarrative/apps/mobile-shell/src/host-bridge/runtime.test.ts
T
kdletters 4623709a39 锁定移动壳运行时能力回包
移动 HostBridge runtime 单测精确断言共享能力 profile

移动壳配置门禁反查 runtime 能力 profile 断言

补充原生壳方案文档和共享决策记录
2026-06-20 20:28:59 +08:00

88 lines
2.4 KiB
TypeScript

import { Platform } from 'react-native';
import { beforeEach, describe, expect, test, vi } from 'vitest';
import {
HOST_BRIDGE_EXPO_MOBILE_BASE_CAPABILITIES,
HOST_BRIDGE_EXPO_MOBILE_IOS_CAPABILITIES,
HOST_BRIDGE_PROTOCOL,
HOST_BRIDGE_VERSION,
type HostBridgeRequest,
} from '../../../../packages/shared/src/contracts/hostBridge';
import { MOBILE_SHELL_HOST_VERSION } from '../shell/runtime';
import {
getMobileHostBridgeRuntime,
getMobileHostBridgeRuntimeResponse,
getMobileRuntimePlatform,
} from './runtime';
vi.mock('react-native', () => ({
Platform: {
OS: 'ios',
},
}));
function request(): HostBridgeRequest {
return {
bridge: HOST_BRIDGE_PROTOCOL,
version: HOST_BRIDGE_VERSION,
id: 'runtime-request',
method: 'host.getRuntime',
};
}
function setPlatformOS(os: 'ios' | 'android') {
(Platform as { OS: 'ios' | 'android' }).OS = os;
}
beforeEach(() => {
setPlatformOS('ios');
});
describe('mobile HostBridge runtime helper', () => {
test('reports iOS runtime with host version, bridge version and iOS capabilities', () => {
expect(getMobileRuntimePlatform()).toBe('ios');
const runtime = getMobileHostBridgeRuntime();
expect(runtime).toEqual(
expect.objectContaining({
shell: 'expo_mobile',
platform: 'ios',
hostVersion: MOBILE_SHELL_HOST_VERSION,
bridgeVersion: HOST_BRIDGE_VERSION,
}),
);
expect(runtime.capabilities).toBe(HOST_BRIDGE_EXPO_MOBILE_IOS_CAPABILITIES);
});
test('reports Android runtime without iOS-only app badge capability', () => {
setPlatformOS('android');
const runtime = getMobileHostBridgeRuntime();
expect(getMobileRuntimePlatform()).toBe('android');
expect(runtime).toEqual(
expect.objectContaining({
shell: 'expo_mobile',
platform: 'android',
hostVersion: MOBILE_SHELL_HOST_VERSION,
bridgeVersion: HOST_BRIDGE_VERSION,
}),
);
expect(runtime.capabilities).toBe(HOST_BRIDGE_EXPO_MOBILE_BASE_CAPABILITIES);
expect(runtime.capabilities).not.toContain('app.setBadgeCount');
});
test('wraps runtime metadata in the HostBridge response shape', () => {
const response = getMobileHostBridgeRuntimeResponse(request());
expect(response).toEqual({
bridge: HOST_BRIDGE_PROTOCOL,
version: HOST_BRIDGE_VERSION,
id: 'runtime-request',
ok: true,
result: getMobileHostBridgeRuntime(),
});
});
});