c04c7d4d8d
共享 HostBridge 契约新增微信小程序能力 profile 微信小程序协议测试和原生壳门禁反查共享 profile 同步宿主壳能力来源文档和共享记忆
79 lines
2.7 KiB
JavaScript
79 lines
2.7 KiB
JavaScript
import path from 'node:path';
|
|
|
|
import { describe, expect, test } from 'vitest';
|
|
|
|
import { HOST_BRIDGE_WECHAT_MINI_PROGRAM_CAPABILITIES } from '../../packages/shared/src/contracts/hostBridge.ts';
|
|
import { loadCommonJsModule } from '../test-utils/loadCommonJsModule.js';
|
|
|
|
const protocolPath = path.resolve(
|
|
process.cwd(),
|
|
'miniprogram/host-bridge/protocol.js',
|
|
);
|
|
const dispatchPath = path.resolve(
|
|
process.cwd(),
|
|
'miniprogram/host-bridge/dispatch.js',
|
|
);
|
|
const paymentPath = path.resolve(
|
|
process.cwd(),
|
|
'miniprogram/host-bridge/payment.js',
|
|
);
|
|
const shareGridPath = path.resolve(
|
|
process.cwd(),
|
|
'miniprogram/host-bridge/shareGrid.js',
|
|
);
|
|
const subscribeMessagePath = path.resolve(
|
|
process.cwd(),
|
|
'miniprogram/host-bridge/subscribeMessage.js',
|
|
);
|
|
const webViewPath = path.resolve(
|
|
process.cwd(),
|
|
'miniprogram/host-bridge/webView.js',
|
|
);
|
|
|
|
describe('wechat mini program host bridge protocol index', () => {
|
|
test('keeps native page routes and result keys centralized', () => {
|
|
const protocol = loadCommonJsModule(protocolPath);
|
|
|
|
expect(protocol.WECHAT_HOST_CAPABILITIES).toEqual(
|
|
HOST_BRIDGE_WECHAT_MINI_PROGRAM_CAPABILITIES,
|
|
);
|
|
expect(protocol.WECHAT_AUTH_PAGE_URL).toBe(
|
|
'/pages/web-view/index?authAction=login&returnTo=previous',
|
|
);
|
|
expect(protocol.WECHAT_PAY_PAGE_URL).toBe('/pages/wechat-pay/index');
|
|
expect(protocol.WECHAT_SHARE_GRID_PAGE_URL).toBe('/pages/share-grid/index');
|
|
expect(protocol.WECHAT_SUBSCRIBE_MESSAGE_PAGE_URL).toBe(
|
|
'/pages/subscribe-message/index',
|
|
);
|
|
expect(protocol.WECHAT_PAY_RESULT_HASH_KEY).toBe('wx_pay_result');
|
|
expect(protocol.WECHAT_SUBSCRIBE_RESULT_HASH_KEY).toBe(
|
|
'wx_subscribe_result',
|
|
);
|
|
});
|
|
|
|
test('dispatch index exposes current bridge ability modules', () => {
|
|
const payment = loadCommonJsModule(paymentPath);
|
|
const protocol = loadCommonJsModule(protocolPath);
|
|
const shareGrid = loadCommonJsModule(shareGridPath);
|
|
const subscribeMessage = loadCommonJsModule(subscribeMessagePath);
|
|
const webView = loadCommonJsModule(webViewPath);
|
|
const dispatch = loadCommonJsModule(dispatchPath, {
|
|
'./payment': payment,
|
|
'./protocol': protocol,
|
|
'./shareGrid': shareGrid,
|
|
'./subscribeMessage': subscribeMessage,
|
|
'./webView': webView,
|
|
});
|
|
|
|
expect(dispatch.protocol.WECHAT_PAY_PAGE_URL).toBe('/pages/wechat-pay/index');
|
|
expect(typeof dispatch.webView.resolveWebViewUrlFromRuntimeConfig).toBe(
|
|
'function',
|
|
);
|
|
expect(typeof dispatch.payment.requestWechatPayment).toBe('function');
|
|
expect(typeof dispatch.shareGrid.buildShareGridTilePlan).toBe('function');
|
|
expect(typeof dispatch.subscribeMessage.buildSubscribeResultValue).toBe(
|
|
'function',
|
|
);
|
|
});
|
|
});
|