import path from 'node:path'; import { describe, expect, test } from 'vitest'; 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([ 'auth.requestLogin', 'payment.request', 'share.setTarget', 'share.open', ]); 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', ); }); });