fix(config): restore legacy gameserver and urlserver contract
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { HttpConfigFetcher } from '../../YouleNexus/assets/framework/config/remote-config-fetcher.ts';
|
||||
import { resolveRuntimeConfig } from '../../YouleNexus/assets/framework/config/runtime-config.ts';
|
||||
|
||||
test('HttpConfigFetcher:POST 空 body,并无条件以 ? 拼接 cache bust', async () => {
|
||||
const calls: Array<{ input: string; init?: RequestInit }> = [];
|
||||
const fetcher = new HttpConfigFetcher(async (input, init) => {
|
||||
calls.push({ input: String(input), init });
|
||||
return new Response('{"data":{"urlserver":"10.0.0.1:3088"}}');
|
||||
});
|
||||
|
||||
await fetcher.fetch('https://config.example/file.txt?existing=1', () => '123');
|
||||
|
||||
assert.equal(calls.length, 1);
|
||||
assert.equal(calls[0]?.input, 'https://config.example/file.txt?existing=1?123');
|
||||
assert.deepEqual(calls[0]?.init, { method: 'POST', body: '' });
|
||||
});
|
||||
|
||||
test('resolveRuntimeConfig:把 cacheBust 注入唯一的 HTTP 请求构造点', async () => {
|
||||
const calls: Array<{ input: string; init?: RequestInit }> = [];
|
||||
const fetcher = new HttpConfigFetcher(async (input, init) => {
|
||||
calls.push({ input: String(input), init });
|
||||
return new Response('{"data":{"urlserver":"10.0.0.1:3088"}}');
|
||||
});
|
||||
|
||||
await resolveRuntimeConfig({
|
||||
mode: 'release',
|
||||
hostKind: 'h5',
|
||||
win: {},
|
||||
search: '?agentid=A&channelid=C',
|
||||
fetcher,
|
||||
cacheBust: () => '123',
|
||||
});
|
||||
|
||||
assert.equal(calls.length, 1);
|
||||
assert.equal(calls[0]?.input, 'https://tsgames.daoqi88.cn/config/update_jsonv2.txt?123');
|
||||
assert.deepEqual(calls[0]?.init, { method: 'POST', body: '' });
|
||||
});
|
||||
|
||||
test('HttpConfigFetcher:非法 JSON 显式抛 ConfigParseError', async () => {
|
||||
const fetcher = new HttpConfigFetcher(async () => new Response('not-json'));
|
||||
await assert.rejects(
|
||||
fetcher.fetch('https://config.example/file.txt', () => '123'),
|
||||
/远程配置 JSON 解析失败/,
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user