35 lines
1.9 KiB
TypeScript
35 lines
1.9 KiB
TypeScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {
|
|
STARTUP_CONFIG,
|
|
validateStartupConfig,
|
|
decodeGameConfig,
|
|
resolveGameServer,
|
|
} from '../../YouleNexus/assets/framework/config/profiles.ts';
|
|
|
|
test('decodeGameConfig:按旧协议把 -/# 解码为远程 txt URL', () => {
|
|
assert.equal(decodeGameConfig('host-path#8080-config'), 'http://host/path:8080/config.txt');
|
|
});
|
|
|
|
test('resolveGameServer:空 gameconfig 使用配置源,非空值使用解码后的注入源', () => {
|
|
assert.equal(
|
|
resolveGameServer({ configured: 'https://default/config.txt', injectedGameConfig: '' }),
|
|
'https://default/config.txt',
|
|
);
|
|
assert.equal(
|
|
resolveGameServer({ configured: 'https://default/config.txt', injectedGameConfig: 'host-path#80-a' }),
|
|
'http://host/path:80/a.txt',
|
|
);
|
|
});
|
|
|
|
test('one frozen source defines the complete default startup configuration', () => {
|
|
assert.deepEqual(STARTUP_CONFIG, { mode: 'debug', gameserver: 'https://tsgames.daoqi88.cn/config/update_jsonv2.txt', useLocalServer: true, localServers: ['ws://127.0.0.1:3088'] });
|
|
assert.ok(Object.isFrozen(STARTUP_CONFIG)); assert.ok(Object.isFrozen(STARTUP_CONFIG.localServers));
|
|
});
|
|
test('source validation rejects malformed configuration without defaults', () => {
|
|
for (const patch of [{mode:'other'}, {useLocalServer:undefined}, {gameserver:'ws://host'}, {gameserver:''}, {localServers:[]}, {localServers:['ws://example.com:3088']}, {localServers:['ws://user:pass@localhost']}, {localServers:['ws://localhost/#fragment']}, {localServers:['ws://127.999.0.1']}, {localServers:['not-a-url']}]) {
|
|
assert.throws(() => validateStartupConfig({...STARTUP_CONFIG,...patch} as any), /startup config/i);
|
|
}
|
|
for (const url of ['ws://127.4.3.2:3088','wss://localhost:3088','ws://[::1]:3088']) assert.deepEqual(validateStartupConfig({...STARTUP_CONFIG,localServers:[url]}).localServers,[url]);
|
|
});
|