Files
youle_cocos/cocoscreator_projects/framework-tests/config/profiles.test.ts
T

42 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { test } from 'node:test';
import assert from 'node:assert/strict';
import {
ACTIVE_PROFILE,
PROFILES,
decodeGameConfig,
resolveActiveProfile,
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('默认 profile 是 ACTIVE_PROFILE,local 保持 remote 源与独立连接目标', () => {
assert.equal(resolveActiveProfile('').name, ACTIVE_PROFILE);
const local = resolveActiveProfile('?profile=local');
assert.equal(local.source, 'remote');
assert.ok(local.gameserver);
assert.deepEqual(local.servers, ['ws://127.0.0.1:3088']);
});
test('未知 profile 显式报错,不回退到 ACTIVE_PROFILE', () => {
assert.throws(() => resolveActiveProfile('?profile=nope'), /未知 profile/);
});
test('正常 build 可达 profile 不含占位调试账号', () => {
assert.equal(JSON.stringify(PROFILES).includes('REPLACE_ME'), false);
assert.equal(PROFILES.staging.account, undefined);
});