import test from 'node:test'; import assert from 'node:assert/strict'; import {startPlatformLocation,callPlatformSetting} from '../../YouleNexus/assets/framework/adapters/native/platform-native.ts'; test('browser location enters the legacy callback as JSON, with a fresh payload each time',()=>{ const results:string[]=[]; startPlatformLocation({kind:'browser'},value=>results.push(value as string)); startPlatformLocation({kind:'browser'},value=>results.push(value as string)); assert.equal(results.length,2); assert.deepEqual(JSON.parse(results[0]),{ address:'江西省南昌市青云谱区施尧路靠近上海浦东发展银行(长天支行)',city:'南昌市',cityCode:'0791',country:'中国', district:'青云谱区',latitude:28.623546,longitude:115.900333,province:'江西省',street:'施尧路',errorCode:0, }); assert.equal(results[0],results[1]); }); test('settings and WVJB preserve scalar and no-argument conventions without browser callbacks',()=>{ const calls:unknown[]=[]; const settings={startlocation:(...args:unknown[])=>calls.push(['location',...args]), stopshake:(...args:unknown[])=>calls.push(['stop',...args]),voicePlaying:(n:number)=>calls.push(['voice',n]), SwitchShake:(n:number)=>calls.push(['sound',n])}; const host={kind:'settings' as const,settings}; startPlatformLocation(host,()=>assert.fail('native must own its callback')); callPlatformSetting(host,'stopshake');callPlatformSetting(host,'voicePlaying',0);callPlatformSetting(host,'SwitchShake',1); const bridge={kind:'bridge' as const,call:(name:string,data:unknown)=>calls.push([name,data])}; startPlatformLocation(bridge,()=>assert.fail('bridge must own its callback')); callPlatformSetting(bridge,'stopshake');callPlatformSetting(bridge,'voicePlaying',1); assert.deepEqual(calls,[['location',2],['stop'],['voice',0],['sound',1],['startlocation',2],['stopshake',''],['voicePlaying',1]]); }); test('browser setting commands complete, but malformed native hosts and native failures stay visible',()=>{ callPlatformSetting({kind:'browser'},'voicePlaying',0); callPlatformSetting({kind:'browser'},'stopshake'); assert.throws(()=>callPlatformSetting({kind:'settings',settings:{}},'voicePlaying',1),/voicePlaying/); assert.throws(()=>startPlatformLocation({kind:'settings',settings:{startlocation(){throw Error('native failed');}}},()=>assert.fail()),/native failed/); });