test: 整併測試至 app/test 並解決 AI 審查 findings #8

Closed
jiantw83 wants to merge 23 commits from test/consolidate-app-test-20260626-111823 into develop
Showing only changes of commit e6ac2a09f6 - Show all commits
+10 -1
View File
@@ -3,7 +3,7 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { fetchReleases } = require('../releases');
const { fetchReleases, truncateString } = require('../releases');
// 以可控的假回應替換全域 fetch,並於結束後還原
function withFetch(handler, run) {
1
@@ -77,6 +77,15 @@ test('fetchReleases 對無法解析的 JSON 回應拋錯', async () => {
);
});
test('truncateString 以字元截斷且不拆分多位元組字元(emoji 代理對)', () => {
const emojis = '😀'.repeat(25);
const result = truncateString(emojis, 10);
// 應得到完整 10 個 emoji(以 code point 計),不殘留落單的代理碼元
assert.equal(Array.from(result).length, 10);
assert.equal(result, '😀'.repeat(10));
assert.ok(!/[\uD800-\uDBFF](?![\uDC00-\uDFFF])/.test(result), '不應殘留落單的高代理碼元');
});
test('fetchReleases 解析失敗時截斷過長的回應片段', async () => {
const huge = `{${'x'.repeat(5000)}`;
await withFetch(