Files
youle_cocos/cocoscreator_projects/framework-tests/config/sources/native-settings.test.ts
T

60 lines
2.4 KiB
TypeScript

import { test } from 'node:test';
import assert from 'node:assert/strict';
import {
getchannelName,
getmarketname,
getothername,
nativeIdentitySource,
} from '../../../YouleNexus/assets/framework/config/sources/native-settings.ts';
test('非 uAgent_3 getothername 调 settings,异常只在源边界转换为空串', () => {
const names: string[] = [];
const win = { settings: { getothername(name: string) { names.push(name); throw new Error('bridge'); } } };
assert.equal(getothername(win, 'native-settings', 'gameconfig'), '');
assert.deepEqual(names, ['gameconfig']);
});
test('getchannelName 返回 truthy settings 结果,否则按宿主执行旧缺省语义', () => {
assert.equal(getchannelName({ settings: { getchannelName: () => 'C1' } }, 'native-settings'), 'C1');
assert.equal(getchannelName({ settings: { getchannelName: () => 0 } }, 'native-settings'), '');
assert.equal(getchannelName({ settings: { getchannelName: () => { throw new Error('bridge'); } } }, 'native-settings'), '');
assert.equal(getchannelName({
settings: { getchannelName: () => { throw new Error('bridge'); } },
app_channel: 'APP-C',
}, 'uAgent_3'), 'APP-C');
});
test('getmarketname 返回 settings 结果;异常按宿主执行旧缺省语义', () => {
assert.equal(getmarketname({ settings: { getmarketname: () => 0 } }, 'native-settings'), 0);
assert.equal(getmarketname({ settings: { getmarketname: () => { throw new Error('bridge'); } } }, 'native-settings'), '4');
assert.equal(getmarketname({
settings: { getmarketname: () => { throw new Error('bridge'); } },
app_market: 8,
}, 'uAgent_3'), 8);
});
test('uAgent_3 getothername 只读 app_<name>,不调用 settings', () => {
let settingsCalls = 0;
const win = {
settings: { getothername: () => { settingsCalls += 1; return 'WRONG'; } },
app_agent: 'APP-A',
app_gameconfig: 'host-path#80-a',
};
assert.equal(getothername(win, 'uAgent_3', 'agent'), 'APP-A');
assert.equal(getothername(win, 'uAgent_3', 'gameconfig'), 'host-path#80-a');
assert.equal(settingsCalls, 0);
});
test('nativeIdentitySource 仅返回所选宿主提供的原生身份字段', () => {
const win = {
settings: {
getothername: (name: string) => name === 'agent' ? 'NA' : '',
getchannelName: () => 'NC',
getmarketname: () => 7,
},
};
assert.deepEqual(nativeIdentitySource(win, 'native-settings')(), {
agentid: 'NA', channelid: 'NC', marketid: 7,
});
});