fix: 修復 lint 錯誤和代碼格式化
- 移除未使用的導入 (readdirSync, basename, readFileSync, execSync) - 將不需要重新賦值的 let 改為 const - 修復 switch case 區塊中的詞法聲明問題 - 移除未使用的 SAMPLING_RATE 和 sampled 變量 - 移除未使用的 _timeout 參數 - 運行 Prettier 格式化所有文件
This commit is contained in:
parent
e327345ad7
commit
a2512bf29b
6 changed files with 886 additions and 712 deletions
1
.github/workflows/run-bun-test.yml
vendored
1
.github/workflows/run-bun-test.yml
vendored
|
|
@ -51,4 +51,3 @@ jobs:
|
|||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
echo "Basic tests completed. For comprehensive E2E tests with all converters," >> $GITHUB_STEP_SUMMARY
|
||||
echo "see the [Docker E2E Tests](${{ github.server_url }}/${{ github.repository }}/actions/workflows/docker-e2e-tests.yml) workflow." >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@
|
|||
*/
|
||||
|
||||
import { describe, test, expect, beforeAll, afterAll } from "bun:test";
|
||||
import { existsSync, statSync, mkdirSync, writeFileSync, readdirSync } from "node:fs";
|
||||
import { join, basename } from "node:path";
|
||||
import { existsSync, statSync, mkdirSync, writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { spawnSync } from "node:child_process";
|
||||
|
||||
// =============================================================================
|
||||
|
|
@ -97,25 +97,24 @@ function ensureDir(dir: string): void {
|
|||
}
|
||||
|
||||
function createTestSvg(path: string): void {
|
||||
writeFileSync(path, `<?xml version="1.0" encoding="UTF-8"?>
|
||||
writeFileSync(
|
||||
path,
|
||||
`<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="0 0 200 200">
|
||||
<rect x="10" y="10" width="180" height="180" fill="#4285f4" rx="20"/>
|
||||
<circle cx="100" cy="100" r="50" fill="#ffffff"/>
|
||||
<text x="100" y="110" text-anchor="middle" font-size="24" fill="#333">測試</text>
|
||||
</svg>`);
|
||||
</svg>`,
|
||||
);
|
||||
}
|
||||
|
||||
function createTestPng(path: string): void {
|
||||
// 最小有效 PNG (1x1 紅色像素)
|
||||
const png = Buffer.from([
|
||||
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a,
|
||||
0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,
|
||||
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
|
||||
0x08, 0x02, 0x00, 0x00, 0x00, 0x90, 0x77, 0x53,
|
||||
0xde, 0x00, 0x00, 0x00, 0x0c, 0x49, 0x44, 0x41,
|
||||
0x54, 0x08, 0xd7, 0x63, 0xf8, 0xcf, 0xc0, 0x00,
|
||||
0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x05, 0xfe,
|
||||
0xd4, 0xef, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45,
|
||||
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,
|
||||
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x02, 0x00, 0x00, 0x00, 0x90, 0x77, 0x53,
|
||||
0xde, 0x00, 0x00, 0x00, 0x0c, 0x49, 0x44, 0x41, 0x54, 0x08, 0xd7, 0x63, 0xf8, 0xcf, 0xc0, 0x00,
|
||||
0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x05, 0xfe, 0xd4, 0xef, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45,
|
||||
0x4e, 0x44, 0xae, 0x42, 0x60, 0x82,
|
||||
]);
|
||||
writeFileSync(path, png);
|
||||
|
|
@ -142,7 +141,9 @@ function createTestBmp(path: string): void {
|
|||
}
|
||||
|
||||
function createTestMarkdown(path: string): void {
|
||||
writeFileSync(path, `# 測試文件 Test Document
|
||||
writeFileSync(
|
||||
path,
|
||||
`# 測試文件 Test Document
|
||||
|
||||
這是一個**多語言**測試文件。
|
||||
|
||||
|
|
@ -173,11 +174,15 @@ This is an English paragraph for testing.
|
|||
\`\`\`javascript
|
||||
console.log("Hello, 世界!");
|
||||
\`\`\`
|
||||
`);
|
||||
`,
|
||||
);
|
||||
}
|
||||
|
||||
function createTestJson(path: string): void {
|
||||
writeFileSync(path, JSON.stringify({
|
||||
writeFileSync(
|
||||
path,
|
||||
JSON.stringify(
|
||||
{
|
||||
name: "測試",
|
||||
version: "1.0.0",
|
||||
languages: ["zh-TW", "zh-CN", "en", "ja", "ko"],
|
||||
|
|
@ -185,11 +190,17 @@ function createTestJson(path: string): void {
|
|||
enabled: true,
|
||||
count: 42,
|
||||
},
|
||||
}, null, 2));
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function createTestHtml(path: string): void {
|
||||
writeFileSync(path, `<!DOCTYPE html>
|
||||
writeFileSync(
|
||||
path,
|
||||
`<!DOCTYPE html>
|
||||
<html lang="zh-TW">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
|
|
@ -203,11 +214,14 @@ function createTestHtml(path: string): void {
|
|||
<li>項目二</li>
|
||||
</ul>
|
||||
</body>
|
||||
</html>`);
|
||||
</html>`,
|
||||
);
|
||||
}
|
||||
|
||||
function createTestTxt(path: string): void {
|
||||
writeFileSync(path, `測試文字檔案 Test Text File
|
||||
writeFileSync(
|
||||
path,
|
||||
`測試文字檔案 Test Text File
|
||||
|
||||
這是一個純文字測試檔案。
|
||||
This is a plain text test file.
|
||||
|
|
@ -220,16 +234,20 @@ This is a plain text test file.
|
|||
- 한국어
|
||||
- Deutsch
|
||||
- Français
|
||||
`);
|
||||
`,
|
||||
);
|
||||
}
|
||||
|
||||
function createTestCsv(path: string): void {
|
||||
writeFileSync(path, `name,value,description
|
||||
writeFileSync(
|
||||
path,
|
||||
`name,value,description
|
||||
測試1,100,這是第一項
|
||||
測試2,200,這是第二項
|
||||
test3,300,This is the third item
|
||||
テスト4,400,これは4番目の項目です
|
||||
`);
|
||||
`,
|
||||
);
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
|
|
@ -250,7 +268,6 @@ async function runConversion(
|
|||
converter: string,
|
||||
inputPath: string,
|
||||
outputPath: string,
|
||||
timeout = TIMEOUT.medium,
|
||||
): Promise<ConversionResult> {
|
||||
const startTime = Date.now();
|
||||
const inputSize = existsSync(inputPath) ? statSync(inputPath).size : 0;
|
||||
|
|
@ -315,7 +332,9 @@ function printSummary(): void {
|
|||
console.log(`✅ 通過 Passed: ${stats.passed}`);
|
||||
console.log(`❌ 失敗 Failed: ${stats.failed}`);
|
||||
console.log(`⏭ 跳過 Skipped: ${stats.skipped}`);
|
||||
console.log(`成功率 Success Rate: ${((stats.passed / (stats.total - stats.skipped)) * 100).toFixed(1)}%`);
|
||||
console.log(
|
||||
`成功率 Success Rate: ${((stats.passed / (stats.total - stats.skipped)) * 100).toFixed(1)}%`,
|
||||
);
|
||||
console.log("=".repeat(60));
|
||||
}
|
||||
|
||||
|
|
@ -323,7 +342,7 @@ function printSummary(): void {
|
|||
// 測試套件
|
||||
// =============================================================================
|
||||
|
||||
let availableTools: Record<string, boolean> = {};
|
||||
const availableTools: Record<string, boolean> = {};
|
||||
|
||||
beforeAll(() => {
|
||||
console.log("\n🔧 檢測可用工具 Detecting available tools...\n");
|
||||
|
|
@ -332,7 +351,9 @@ beforeAll(() => {
|
|||
const status = check();
|
||||
availableTools[name] = status.available;
|
||||
const icon = status.available ? "✅" : "❌";
|
||||
console.log(` ${icon} ${name}: ${status.available ? status.version || "available" : "not found"}`);
|
||||
console.log(
|
||||
` ${icon} ${name}: ${status.available ? status.version || "available" : "not found"}`,
|
||||
);
|
||||
}
|
||||
|
||||
console.log("\n");
|
||||
|
|
@ -365,7 +386,9 @@ describe("🖼️ 圖像格式轉換 Image Conversions", () => {
|
|||
});
|
||||
|
||||
for (const format of formats) {
|
||||
test(`SVG → ${format.toUpperCase()}`, async () => {
|
||||
test(
|
||||
`SVG → ${format.toUpperCase()}`,
|
||||
async () => {
|
||||
if (!availableTools.inkscape || !availableTools.xvfbRun) {
|
||||
stats.skipped++;
|
||||
stats.total++;
|
||||
|
|
@ -380,14 +403,18 @@ describe("🖼️ 圖像格式轉換 Image Conversions", () => {
|
|||
|
||||
if (result.success) {
|
||||
stats.passed++;
|
||||
console.log(` ✓ SVG → ${format.toUpperCase()}: ${result.outputSize} bytes (${result.duration}ms)`);
|
||||
console.log(
|
||||
` ✓ SVG → ${format.toUpperCase()}: ${result.outputSize} bytes (${result.duration}ms)`,
|
||||
);
|
||||
} else {
|
||||
stats.failed++;
|
||||
console.log(` ✗ SVG → ${format.toUpperCase()}: ${result.error}`);
|
||||
}
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
}, TIMEOUT.medium);
|
||||
},
|
||||
TIMEOUT.medium,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -403,7 +430,9 @@ describe("🖼️ 圖像格式轉換 Image Conversions", () => {
|
|||
];
|
||||
|
||||
for (const [from, to] of conversions) {
|
||||
test(`${from.toUpperCase()} → ${to.toUpperCase()}`, async () => {
|
||||
test(
|
||||
`${from.toUpperCase()} → ${to.toUpperCase()}`,
|
||||
async () => {
|
||||
if (!availableTools.imagemagick) {
|
||||
stats.skipped++;
|
||||
stats.total++;
|
||||
|
|
@ -423,13 +452,17 @@ describe("🖼️ 圖像格式轉換 Image Conversions", () => {
|
|||
|
||||
if (result.success) {
|
||||
stats.passed++;
|
||||
console.log(` ✓ ${from.toUpperCase()} → ${to.toUpperCase()}: ${result.outputSize} bytes`);
|
||||
console.log(
|
||||
` ✓ ${from.toUpperCase()} → ${to.toUpperCase()}: ${result.outputSize} bytes`,
|
||||
);
|
||||
} else {
|
||||
stats.failed++;
|
||||
}
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
}, TIMEOUT.fast);
|
||||
},
|
||||
TIMEOUT.fast,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -438,7 +471,9 @@ describe("🖼️ 圖像格式轉換 Image Conversions", () => {
|
|||
const formats = ["svg", "eps", "pdf"];
|
||||
|
||||
for (const format of formats) {
|
||||
test(`BMP → ${format.toUpperCase()}`, async () => {
|
||||
test(
|
||||
`BMP → ${format.toUpperCase()}`,
|
||||
async () => {
|
||||
if (!availableTools.potrace) {
|
||||
stats.skipped++;
|
||||
stats.total++;
|
||||
|
|
@ -462,7 +497,9 @@ describe("🖼️ 圖像格式轉換 Image Conversions", () => {
|
|||
}
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
}, TIMEOUT.fast);
|
||||
},
|
||||
TIMEOUT.fast,
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
@ -488,7 +525,9 @@ describe("📄 文件格式轉換 Document Conversions", () => {
|
|||
});
|
||||
|
||||
for (const format of formats) {
|
||||
test(`Markdown → ${format.toUpperCase()}`, async () => {
|
||||
test(
|
||||
`Markdown → ${format.toUpperCase()}`,
|
||||
async () => {
|
||||
if (!availableTools.pandoc) {
|
||||
stats.skipped++;
|
||||
stats.total++;
|
||||
|
|
@ -509,7 +548,9 @@ describe("📄 文件格式轉換 Document Conversions", () => {
|
|||
}
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
}, TIMEOUT.medium);
|
||||
},
|
||||
TIMEOUT.medium,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -522,7 +563,9 @@ describe("📄 文件格式轉換 Document Conversions", () => {
|
|||
];
|
||||
|
||||
for (const [from, to] of conversions) {
|
||||
test(`${from.toUpperCase()} → ${to.toUpperCase()}`, async () => {
|
||||
test(
|
||||
`${from.toUpperCase()} → ${to.toUpperCase()}`,
|
||||
async () => {
|
||||
if (!availableTools.libreoffice) {
|
||||
stats.skipped++;
|
||||
stats.total++;
|
||||
|
|
@ -542,13 +585,17 @@ describe("📄 文件格式轉換 Document Conversions", () => {
|
|||
|
||||
if (result.success) {
|
||||
stats.passed++;
|
||||
console.log(` ✓ ${from.toUpperCase()} → ${to.toUpperCase()}: ${result.outputSize} bytes`);
|
||||
console.log(
|
||||
` ✓ ${from.toUpperCase()} → ${to.toUpperCase()}: ${result.outputSize} bytes`,
|
||||
);
|
||||
} else {
|
||||
stats.failed++;
|
||||
}
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
}, TIMEOUT.slow);
|
||||
},
|
||||
TIMEOUT.slow,
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
@ -575,7 +622,9 @@ describe("📊 資料格式轉換 Data Format Conversions", () => {
|
|||
];
|
||||
|
||||
for (const [from, to] of conversions) {
|
||||
test(`${from.toUpperCase()} → ${to.toUpperCase()}`, async () => {
|
||||
test(
|
||||
`${from.toUpperCase()} → ${to.toUpperCase()}`,
|
||||
async () => {
|
||||
if (!availableTools.dasel) {
|
||||
stats.skipped++;
|
||||
stats.total++;
|
||||
|
|
@ -599,13 +648,17 @@ describe("📊 資料格式轉換 Data Format Conversions", () => {
|
|||
|
||||
if (result.success) {
|
||||
stats.passed++;
|
||||
console.log(` ✓ ${from.toUpperCase()} → ${to.toUpperCase()}: ${result.outputSize} bytes`);
|
||||
console.log(
|
||||
` ✓ ${from.toUpperCase()} → ${to.toUpperCase()}: ${result.outputSize} bytes`,
|
||||
);
|
||||
} else {
|
||||
stats.failed++;
|
||||
}
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
}, TIMEOUT.fast);
|
||||
},
|
||||
TIMEOUT.fast,
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
@ -637,8 +690,11 @@ describe("🌍 多語言翻譯 Multilingual Translation", () => {
|
|||
describe("PDFMathTranslate (PDF 翻譯)", () => {
|
||||
// 注意:這些測試需要網路連接和 PDF 測試檔案
|
||||
|
||||
for (const lang of LANGUAGES.slice(0, 4)) { // 只測試前 4 種語言
|
||||
test.skip(`PDF → ${lang.name} (${lang.code})`, async () => {
|
||||
for (const lang of LANGUAGES.slice(0, 4)) {
|
||||
// 只測試前 4 種語言
|
||||
test.skip(
|
||||
`PDF → ${lang.name} (${lang.code})`,
|
||||
async () => {
|
||||
if (!availableTools.pdf2zh) {
|
||||
stats.skipped++;
|
||||
stats.total++;
|
||||
|
|
@ -662,20 +718,27 @@ describe("🌍 多語言翻譯 Multilingual Translation", () => {
|
|||
|
||||
if (result.success) {
|
||||
stats.passed++;
|
||||
console.log(` ✓ PDF → ${lang.name}: ${result.outputSize} bytes (${result.duration}ms)`);
|
||||
console.log(
|
||||
` ✓ PDF → ${lang.name}: ${result.outputSize} bytes (${result.duration}ms)`,
|
||||
);
|
||||
} else {
|
||||
stats.failed++;
|
||||
}
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
}, TIMEOUT.translation);
|
||||
},
|
||||
TIMEOUT.translation,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// BabelDOC 測試
|
||||
describe("BabelDOC (進階 PDF 翻譯)", () => {
|
||||
for (const lang of LANGUAGES.slice(0, 2)) { // 只測試中英
|
||||
test.skip(`PDF → ${lang.name} (babeldoc)`, async () => {
|
||||
for (const lang of LANGUAGES.slice(0, 2)) {
|
||||
// 只測試中英
|
||||
test.skip(
|
||||
`PDF → ${lang.name} (babeldoc)`,
|
||||
async () => {
|
||||
if (!availableTools.babeldoc) {
|
||||
stats.skipped++;
|
||||
stats.total++;
|
||||
|
|
@ -704,7 +767,9 @@ describe("🌍 多語言翻譯 Multilingual Translation", () => {
|
|||
}
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
}, TIMEOUT.translation);
|
||||
},
|
||||
TIMEOUT.translation,
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
@ -731,7 +796,9 @@ describe("📚 電子書格式轉換 Ebook Conversions", () => {
|
|||
];
|
||||
|
||||
for (const [from, to] of conversions) {
|
||||
test(`${from.toUpperCase()} → ${to.toUpperCase()}`, async () => {
|
||||
test(
|
||||
`${from.toUpperCase()} → ${to.toUpperCase()}`,
|
||||
async () => {
|
||||
if (!availableTools.calibre || !availableTools.xvfbRun) {
|
||||
stats.skipped++;
|
||||
stats.total++;
|
||||
|
|
@ -751,13 +818,17 @@ describe("📚 電子書格式轉換 Ebook Conversions", () => {
|
|||
|
||||
if (result.success) {
|
||||
stats.passed++;
|
||||
console.log(` ✓ ${from.toUpperCase()} → ${to.toUpperCase()}: ${result.outputSize} bytes`);
|
||||
console.log(
|
||||
` ✓ ${from.toUpperCase()} → ${to.toUpperCase()}: ${result.outputSize} bytes`,
|
||||
);
|
||||
} else {
|
||||
stats.failed++;
|
||||
}
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
}, TIMEOUT.slow);
|
||||
},
|
||||
TIMEOUT.slow,
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
@ -777,7 +848,9 @@ describe("🎬 音視頻格式轉換 Media Conversions", () => {
|
|||
describe("FFmpeg (音視頻格式)", () => {
|
||||
// 注意:這些測試需要實際的音視頻測試檔案
|
||||
|
||||
test.skip("MP3 → WAV", async () => {
|
||||
test.skip(
|
||||
"MP3 → WAV",
|
||||
async () => {
|
||||
if (!availableTools.ffmpeg) {
|
||||
stats.skipped++;
|
||||
stats.total++;
|
||||
|
|
@ -799,7 +872,9 @@ describe("🎬 音視頻格式轉換 Media Conversions", () => {
|
|||
stats.results.push(result);
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
}, TIMEOUT.medium);
|
||||
},
|
||||
TIMEOUT.medium,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -815,8 +890,15 @@ describe("🔢 格式轉換矩陣 Conversion Matrix", () => {
|
|||
|
||||
test("生成格式轉換矩陣報告", async () => {
|
||||
const converters = [
|
||||
"inkscape", "imagemagick", "graphicsmagick", "pandoc",
|
||||
"dasel", "potrace", "vtracer", "libreoffice", "calibre",
|
||||
"inkscape",
|
||||
"imagemagick",
|
||||
"graphicsmagick",
|
||||
"pandoc",
|
||||
"dasel",
|
||||
"potrace",
|
||||
"vtracer",
|
||||
"libreoffice",
|
||||
"calibre",
|
||||
];
|
||||
|
||||
const matrix: Record<string, { from: string[]; to: string[] }> = {};
|
||||
|
|
@ -862,8 +944,12 @@ describe("🔢 格式轉換矩陣 Conversion Matrix", () => {
|
|||
totalCombinations += combinations;
|
||||
|
||||
console.log(`${converter}:`);
|
||||
console.log(` 輸入格式: ${formats.from.length} (${formats.from.slice(0, 5).join(", ")}${formats.from.length > 5 ? "..." : ""})`);
|
||||
console.log(` 輸出格式: ${formats.to.length} (${formats.to.slice(0, 5).join(", ")}${formats.to.length > 5 ? "..." : ""})`);
|
||||
console.log(
|
||||
` 輸入格式: ${formats.from.length} (${formats.from.slice(0, 5).join(", ")}${formats.from.length > 5 ? "..." : ""})`,
|
||||
);
|
||||
console.log(
|
||||
` 輸出格式: ${formats.to.length} (${formats.to.slice(0, 5).join(", ")}${formats.to.length > 5 ? "..." : ""})`,
|
||||
);
|
||||
console.log(` 組合數: ${combinations}`);
|
||||
console.log();
|
||||
}
|
||||
|
|
@ -944,7 +1030,9 @@ describe("⚠️ 邊界條件測試 Edge Cases", () => {
|
|||
expect(result.success).toBe(true);
|
||||
});
|
||||
|
||||
test("超長內容處理", async () => {
|
||||
test(
|
||||
"超長內容處理",
|
||||
async () => {
|
||||
if (!availableTools.pandoc) {
|
||||
stats.skipped++;
|
||||
stats.total++;
|
||||
|
|
@ -956,8 +1044,9 @@ describe("⚠️ 邊界條件測試 Edge Cases", () => {
|
|||
const outputPath = join(outputDir, "long_output.html");
|
||||
|
||||
// 生成 10000 行的文件
|
||||
const lines = Array.from({ length: 10000 }, (_, i) =>
|
||||
`第 ${i + 1} 行:這是測試內容 Line ${i + 1}: This is test content`
|
||||
const lines = Array.from(
|
||||
{ length: 10000 },
|
||||
(_, i) => `第 ${i + 1} 行:這是測試內容 Line ${i + 1}: This is test content`,
|
||||
).join("\n");
|
||||
writeFileSync(inputPath, `# 長文件測試\n\n${lines}`);
|
||||
|
||||
|
|
@ -972,7 +1061,9 @@ describe("⚠️ 邊界條件測試 Edge Cases", () => {
|
|||
}
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
}, TIMEOUT.slow);
|
||||
},
|
||||
TIMEOUT.slow,
|
||||
);
|
||||
|
||||
test("特殊字元處理", async () => {
|
||||
if (!availableTools.pandoc) {
|
||||
|
|
@ -985,7 +1076,9 @@ describe("⚠️ 邊界條件測試 Edge Cases", () => {
|
|||
const inputPath = join(outputDir, "special_chars.markdown");
|
||||
const outputPath = join(outputDir, "special_output.html");
|
||||
|
||||
writeFileSync(inputPath, `# 特殊字元測試
|
||||
writeFileSync(
|
||||
inputPath,
|
||||
`# 特殊字元測試
|
||||
|
||||
& < > " ' \` ~ ! @ # $ % ^ & * ( ) - = + [ ] { } | \\ : ; < > ? , . /
|
||||
|
||||
|
|
@ -996,7 +1089,8 @@ describe("⚠️ 邊界條件測試 Edge Cases", () => {
|
|||
CJK 擴展:㊀ ㊁ ㊂ ㊃ ㊄
|
||||
|
||||
全形標點:「」『』【】〈〉《》
|
||||
`);
|
||||
`,
|
||||
);
|
||||
|
||||
const result = await runConversion("pandoc", inputPath, outputPath);
|
||||
stats.results.push(result);
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
*/
|
||||
|
||||
import { describe, test, expect, beforeAll, afterAll } from "bun:test";
|
||||
import { existsSync, mkdirSync, writeFileSync, readFileSync } from "node:fs";
|
||||
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { spawnSync } from "node:child_process";
|
||||
|
||||
|
|
@ -25,9 +25,6 @@ import { spawnSync } from "node:child_process";
|
|||
const E2E_OUTPUT_DIR = "tests/e2e/output/format-matrix";
|
||||
const TIMEOUT = 60_000; // 60 秒超時
|
||||
|
||||
// 抽樣比例(0.1 = 10%,避免測試過長)
|
||||
const SAMPLING_RATE = 0.05;
|
||||
|
||||
// 每個轉換器最大測試數
|
||||
const MAX_TESTS_PER_CONVERTER = 20;
|
||||
|
||||
|
|
@ -118,18 +115,14 @@ function createTestContent(format: string): Buffer | string {
|
|||
|
||||
case "png":
|
||||
return Buffer.from([
|
||||
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a,
|
||||
0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,
|
||||
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
|
||||
0x08, 0x02, 0x00, 0x00, 0x00, 0x90, 0x77, 0x53,
|
||||
0xde, 0x00, 0x00, 0x00, 0x0c, 0x49, 0x44, 0x41,
|
||||
0x54, 0x08, 0xd7, 0x63, 0xf8, 0xcf, 0xc0, 0x00,
|
||||
0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x05, 0xfe,
|
||||
0xd4, 0xef, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45,
|
||||
0x4e, 0x44, 0xae, 0x42, 0x60, 0x82,
|
||||
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44,
|
||||
0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x02, 0x00, 0x00, 0x00, 0x90,
|
||||
0x77, 0x53, 0xde, 0x00, 0x00, 0x00, 0x0c, 0x49, 0x44, 0x41, 0x54, 0x08, 0xd7, 0x63, 0xf8,
|
||||
0xcf, 0xc0, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x05, 0xfe, 0xd4, 0xef, 0x00, 0x00,
|
||||
0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82,
|
||||
]);
|
||||
|
||||
case "bmp":
|
||||
case "bmp": {
|
||||
const bmp = Buffer.alloc(70);
|
||||
bmp.write("BM", 0);
|
||||
bmp.writeUInt32LE(70, 2);
|
||||
|
|
@ -143,6 +136,7 @@ function createTestContent(format: string): Buffer | string {
|
|||
bmp[55] = 0x00;
|
||||
bmp[56] = 0x00;
|
||||
return bmp;
|
||||
}
|
||||
|
||||
// 文檔格式
|
||||
case "md":
|
||||
|
|
@ -232,7 +226,21 @@ const CONVERTERS: ConverterConfig[] = [
|
|||
name: "imagemagick",
|
||||
command: "magick",
|
||||
from: ["png", "jpg", "jpeg", "gif", "bmp", "tiff", "tif", "webp", "ico", "ppm", "pgm", "pbm"],
|
||||
to: ["png", "jpg", "jpeg", "gif", "bmp", "tiff", "tif", "webp", "ico", "ppm", "pgm", "pbm", "pdf"],
|
||||
to: [
|
||||
"png",
|
||||
"jpg",
|
||||
"jpeg",
|
||||
"gif",
|
||||
"bmp",
|
||||
"tiff",
|
||||
"tif",
|
||||
"webp",
|
||||
"ico",
|
||||
"ppm",
|
||||
"pgm",
|
||||
"pbm",
|
||||
"pdf",
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "graphicsmagick",
|
||||
|
|
@ -316,7 +324,7 @@ const CONVERTERS: ConverterConfig[] = [
|
|||
// 主測試
|
||||
// =============================================================================
|
||||
|
||||
let report: MatrixReport = {
|
||||
const report: MatrixReport = {
|
||||
generatedAt: new Date().toISOString(),
|
||||
converters: [],
|
||||
totalCombinations: 0,
|
||||
|
|
@ -350,7 +358,9 @@ afterAll(() => {
|
|||
console.log(`通過 Passed: ${report.passedTests}`);
|
||||
console.log(`失敗 Failed: ${report.failedTests}`);
|
||||
console.log(`跳過 Skipped: ${report.skippedTests}`);
|
||||
console.log(`成功率 Success Rate: ${((report.passedTests / (report.testedCombinations || 1)) * 100).toFixed(1)}%`);
|
||||
console.log(
|
||||
`成功率 Success Rate: ${((report.passedTests / (report.testedCombinations || 1)) * 100).toFixed(1)}%`,
|
||||
);
|
||||
console.log("=".repeat(70));
|
||||
console.log(`📁 報告路徑: ${reportPath}`);
|
||||
console.log(`📄 摘要路徑: ${summaryPath}`);
|
||||
|
|
@ -380,7 +390,7 @@ function generateMarkdownSummary(report: MatrixReport): string {
|
|||
}
|
||||
|
||||
md += `## 失敗的測試\n\n`;
|
||||
const failedResults = report.results.filter(r => !r.success);
|
||||
const failedResults = report.results.filter((r) => !r.success);
|
||||
if (failedResults.length === 0) {
|
||||
md += `無失敗的測試 ✅\n`;
|
||||
} else {
|
||||
|
|
@ -399,7 +409,6 @@ function generateMarkdownSummary(report: MatrixReport): string {
|
|||
// =============================================================================
|
||||
|
||||
describe("📊 格式轉換矩陣 Format Conversion Matrix", () => {
|
||||
|
||||
describe("發現可用轉換器 Discover Available Converters", () => {
|
||||
test("檢測所有轉換器", () => {
|
||||
for (const config of CONVERTERS) {
|
||||
|
|
@ -427,7 +436,9 @@ describe("📊 格式轉換矩陣 Format Conversion Matrix", () => {
|
|||
report.totalCombinations += combinations.length;
|
||||
|
||||
const icon = available ? "✅" : "❌";
|
||||
console.log(` ${icon} ${config.name}: ${combinations.length} 組合 (${available ? "可用" : "不可用"})`);
|
||||
console.log(
|
||||
` ${icon} ${config.name}: ${combinations.length} 組合 (${available ? "可用" : "不可用"})`,
|
||||
);
|
||||
}
|
||||
|
||||
console.log(`\n 📈 總組合數: ${report.totalCombinations}`);
|
||||
|
|
@ -436,12 +447,22 @@ describe("📊 格式轉換矩陣 Format Conversion Matrix", () => {
|
|||
});
|
||||
|
||||
describe("圖像格式轉換 Image Format Conversions", () => {
|
||||
const imageConverters = ["inkscape", "imagemagick", "graphicsmagick", "potrace", "vtracer", "resvg", "vips"];
|
||||
const imageConverters = [
|
||||
"inkscape",
|
||||
"imagemagick",
|
||||
"graphicsmagick",
|
||||
"potrace",
|
||||
"vtracer",
|
||||
"resvg",
|
||||
"vips",
|
||||
];
|
||||
|
||||
for (const converterName of imageConverters) {
|
||||
describe(`${converterName}`, () => {
|
||||
test(`測試格式轉換`, async () => {
|
||||
const converter = report.converters.find(c => c.name === converterName);
|
||||
test(
|
||||
`測試格式轉換`,
|
||||
async () => {
|
||||
const converter = report.converters.find((c) => c.name === converterName);
|
||||
if (!converter) {
|
||||
report.skippedTests++;
|
||||
console.log(` ⏭ ${converterName}: 轉換器未找到`);
|
||||
|
|
@ -450,13 +471,17 @@ describe("📊 格式轉換矩陣 Format Conversion Matrix", () => {
|
|||
|
||||
if (!converter.available) {
|
||||
report.skippedTests += converter.combinations.length;
|
||||
console.log(` ⏭ ${converterName}: 工具不可用,跳過 ${converter.combinations.length} 個測試`);
|
||||
console.log(
|
||||
` ⏭ ${converterName}: 工具不可用,跳過 ${converter.combinations.length} 個測試`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// 抽樣測試
|
||||
const sampled = sampleCombinations(converter.combinations, MAX_TESTS_PER_CONVERTER);
|
||||
console.log(` 🧪 ${converterName}: 測試 ${sampled.length}/${converter.combinations.length} 個組合`);
|
||||
console.log(
|
||||
` 🧪 ${converterName}: 測試 ${sampled.length}/${converter.combinations.length} 個組合`,
|
||||
);
|
||||
|
||||
for (const [from, to] of sampled) {
|
||||
report.testedCombinations++;
|
||||
|
|
@ -511,7 +536,9 @@ describe("📊 格式轉換矩陣 Format Conversion Matrix", () => {
|
|||
console.log(` ❌ ${from} → ${to}: ${error}`);
|
||||
}
|
||||
}
|
||||
}, TIMEOUT * sampled.length);
|
||||
},
|
||||
TIMEOUT * sampled.length,
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -521,8 +548,10 @@ describe("📊 格式轉換矩陣 Format Conversion Matrix", () => {
|
|||
|
||||
for (const converterName of docConverters) {
|
||||
describe(`${converterName}`, () => {
|
||||
test(`測試格式轉換`, async () => {
|
||||
const converter = report.converters.find(c => c.name === converterName);
|
||||
test(
|
||||
`測試格式轉換`,
|
||||
async () => {
|
||||
const converter = report.converters.find((c) => c.name === converterName);
|
||||
if (!converter) {
|
||||
report.skippedTests++;
|
||||
console.log(` ⏭ ${converterName}: 轉換器未找到`);
|
||||
|
|
@ -531,13 +560,17 @@ describe("📊 格式轉換矩陣 Format Conversion Matrix", () => {
|
|||
|
||||
if (!converter.available) {
|
||||
report.skippedTests += converter.combinations.length;
|
||||
console.log(` ⏭ ${converterName}: 工具不可用,跳過 ${converter.combinations.length} 個測試`);
|
||||
console.log(
|
||||
` ⏭ ${converterName}: 工具不可用,跳過 ${converter.combinations.length} 個測試`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// 抽樣測試
|
||||
const sampled = sampleCombinations(converter.combinations, MAX_TESTS_PER_CONVERTER);
|
||||
console.log(` 🧪 ${converterName}: 測試 ${sampled.length}/${converter.combinations.length} 個組合`);
|
||||
console.log(
|
||||
` 🧪 ${converterName}: 測試 ${sampled.length}/${converter.combinations.length} 個組合`,
|
||||
);
|
||||
|
||||
for (const [from, to] of sampled) {
|
||||
report.testedCombinations++;
|
||||
|
|
@ -564,7 +597,8 @@ describe("📊 格式轉換矩陣 Format Conversion Matrix", () => {
|
|||
|
||||
const module = await import(`../../src/converters/${converterName}`);
|
||||
// 對於 Pandoc,正規化格式名稱
|
||||
const normalizedFrom = converterName === "pandoc" ? normalizeFormatForPandoc(from) : from;
|
||||
const normalizedFrom =
|
||||
converterName === "pandoc" ? normalizeFormatForPandoc(from) : from;
|
||||
const normalizedTo = converterName === "pandoc" ? normalizeFormatForPandoc(to) : to;
|
||||
await module.convert(inputPath, normalizedFrom, normalizedTo, outputPath);
|
||||
|
||||
|
|
@ -599,7 +633,9 @@ describe("📊 格式轉換矩陣 Format Conversion Matrix", () => {
|
|||
console.log(` ❌ ${from} → ${to}: ${error}`);
|
||||
}
|
||||
}
|
||||
}, TIMEOUT * sampled.length);
|
||||
},
|
||||
TIMEOUT * sampled.length,
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -609,8 +645,10 @@ describe("📊 格式轉換矩陣 Format Conversion Matrix", () => {
|
|||
|
||||
for (const converterName of dataConverters) {
|
||||
describe(`${converterName}`, () => {
|
||||
test(`測試格式轉換`, async () => {
|
||||
const converter = report.converters.find(c => c.name === converterName);
|
||||
test(
|
||||
`測試格式轉換`,
|
||||
async () => {
|
||||
const converter = report.converters.find((c) => c.name === converterName);
|
||||
if (!converter) {
|
||||
report.skippedTests++;
|
||||
console.log(` ⏭ ${converterName}: 轉換器未找到`);
|
||||
|
|
@ -619,12 +657,16 @@ describe("📊 格式轉換矩陣 Format Conversion Matrix", () => {
|
|||
|
||||
if (!converter.available) {
|
||||
report.skippedTests += converter.combinations.length;
|
||||
console.log(` ⏭ ${converterName}: 工具不可用,跳過 ${converter.combinations.length} 個測試`);
|
||||
console.log(
|
||||
` ⏭ ${converterName}: 工具不可用,跳過 ${converter.combinations.length} 個測試`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const sampled = sampleCombinations(converter.combinations, MAX_TESTS_PER_CONVERTER);
|
||||
console.log(` 🧪 ${converterName}: 測試 ${sampled.length}/${converter.combinations.length} 個組合`);
|
||||
console.log(
|
||||
` 🧪 ${converterName}: 測試 ${sampled.length}/${converter.combinations.length} 個組合`,
|
||||
);
|
||||
|
||||
for (const [from, to] of sampled) {
|
||||
report.testedCombinations++;
|
||||
|
|
@ -671,7 +713,9 @@ describe("📊 格式轉換矩陣 Format Conversion Matrix", () => {
|
|||
});
|
||||
}
|
||||
}
|
||||
}, TIMEOUT * sampled.length);
|
||||
},
|
||||
TIMEOUT * sampled.length,
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -693,6 +737,3 @@ function sampleCombinations(
|
|||
const shuffled = [...combinations].sort(() => Math.random() - 0.5);
|
||||
return shuffled.slice(0, maxCount);
|
||||
}
|
||||
|
||||
// 為 sampled 變數提供全局作用域
|
||||
let sampled: [string, string][] = [];
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@
|
|||
*/
|
||||
|
||||
import { describe, test, expect, beforeAll, afterAll } from "bun:test";
|
||||
import { existsSync, mkdirSync, writeFileSync, readFileSync, statSync } from "node:fs";
|
||||
import { existsSync, mkdirSync, writeFileSync, statSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { spawnSync, execSync } from "node:child_process";
|
||||
import { spawnSync } from "node:child_process";
|
||||
|
||||
// =============================================================================
|
||||
// 配置
|
||||
|
|
@ -41,7 +41,12 @@ interface Language {
|
|||
|
||||
const SUPPORTED_LANGUAGES: Language[] = [
|
||||
{ code: "zh", name: "Simplified Chinese", nativeName: "简体中文", testPhrase: "这是一个测试" },
|
||||
{ code: "zh-TW", name: "Traditional Chinese", nativeName: "繁體中文", testPhrase: "這是一個測試" },
|
||||
{
|
||||
code: "zh-TW",
|
||||
name: "Traditional Chinese",
|
||||
nativeName: "繁體中文",
|
||||
testPhrase: "這是一個測試",
|
||||
},
|
||||
{ code: "en", name: "English", nativeName: "English", testPhrase: "This is a test" },
|
||||
{ code: "ja", name: "Japanese", nativeName: "日本語", testPhrase: "これはテストです" },
|
||||
{ code: "ko", name: "Korean", nativeName: "한국어", testPhrase: "이것은 테스트입니다" },
|
||||
|
|
@ -53,7 +58,12 @@ const SUPPORTED_LANGUAGES: Language[] = [
|
|||
{ code: "it", name: "Italian", nativeName: "Italiano", testPhrase: "Questo è un test" },
|
||||
{ code: "ar", name: "Arabic", nativeName: "العربية", testPhrase: "هذا اختبار" },
|
||||
{ code: "th", name: "Thai", nativeName: "ไทย", testPhrase: "นี่คือการทดสอบ" },
|
||||
{ code: "vi", name: "Vietnamese", nativeName: "Tiếng Việt", testPhrase: "Đây là một bài kiểm tra" },
|
||||
{
|
||||
code: "vi",
|
||||
name: "Vietnamese",
|
||||
nativeName: "Tiếng Việt",
|
||||
testPhrase: "Đây là một bài kiểm tra",
|
||||
},
|
||||
];
|
||||
|
||||
// =============================================================================
|
||||
|
|
@ -133,15 +143,15 @@ This document is used for testing multilingual translation capabilities.
|
|||
|
||||
try {
|
||||
// 嘗試使用 xelatex
|
||||
const result = spawnSync("xelatex", [
|
||||
"-interaction=nonstopmode",
|
||||
"-output-directory=" + join(path, ".."),
|
||||
texPath,
|
||||
], {
|
||||
const result = spawnSync(
|
||||
"xelatex",
|
||||
["-interaction=nonstopmode", "-output-directory=" + join(path, ".."), texPath],
|
||||
{
|
||||
timeout: 60000,
|
||||
encoding: "utf-8",
|
||||
stdio: ["pipe", "pipe", "pipe"],
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
return result.status === 0 && existsSync(path);
|
||||
} catch {
|
||||
|
|
@ -204,7 +214,9 @@ beforeAll(async () => {
|
|||
|
||||
for (const [name, status] of Object.entries(translators)) {
|
||||
const icon = status.available ? "✅" : "❌";
|
||||
console.log(` ${icon} ${name}: ${status.available ? status.version || "available" : "not found"}`);
|
||||
console.log(
|
||||
` ${icon} ${name}: ${status.available ? status.version || "available" : "not found"}`,
|
||||
);
|
||||
}
|
||||
|
||||
// 檢查或創建測試 PDF
|
||||
|
|
@ -230,16 +242,25 @@ afterAll(() => {
|
|||
console.log(`✅ 通過 Passed: ${stats.passed}`);
|
||||
console.log(`❌ 失敗 Failed: ${stats.failed}`);
|
||||
console.log(`⏭ 跳過 Skipped: ${stats.skipped}`);
|
||||
console.log(`成功率 Success Rate: ${((stats.passed / (stats.total - stats.skipped || 1)) * 100).toFixed(1)}%`);
|
||||
console.log(
|
||||
`成功率 Success Rate: ${((stats.passed / (stats.total - stats.skipped || 1)) * 100).toFixed(1)}%`,
|
||||
);
|
||||
console.log("=".repeat(70));
|
||||
|
||||
// 生成報告
|
||||
const reportPath = join(E2E_OUTPUT_DIR, "translation-report.json");
|
||||
writeFileSync(reportPath, JSON.stringify({
|
||||
writeFileSync(
|
||||
reportPath,
|
||||
JSON.stringify(
|
||||
{
|
||||
generatedAt: new Date().toISOString(),
|
||||
translators,
|
||||
stats,
|
||||
}, null, 2));
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
);
|
||||
console.log(`📁 報告已保存: ${reportPath}`);
|
||||
});
|
||||
|
||||
|
|
@ -250,12 +271,14 @@ afterAll(() => {
|
|||
describe("📚 PDFMathTranslate (pdf2zh)", () => {
|
||||
// 主要語言測試
|
||||
describe("主要語言翻譯 Primary Languages", () => {
|
||||
const primaryLanguages = SUPPORTED_LANGUAGES.filter(l =>
|
||||
["zh", "en", "ja", "ko"].includes(l.code)
|
||||
const primaryLanguages = SUPPORTED_LANGUAGES.filter((l) =>
|
||||
["zh", "en", "ja", "ko"].includes(l.code),
|
||||
);
|
||||
|
||||
for (const lang of primaryLanguages) {
|
||||
test(`英文 → ${lang.nativeName} (${lang.code})`, async () => {
|
||||
test(
|
||||
`英文 → ${lang.nativeName} (${lang.code})`,
|
||||
async () => {
|
||||
stats.total++;
|
||||
|
||||
if (!translators.pdf2zh?.available) {
|
||||
|
|
@ -299,7 +322,9 @@ describe("📚 PDFMathTranslate (pdf2zh)", () => {
|
|||
|
||||
if (success) {
|
||||
stats.passed++;
|
||||
console.log(` ✓ en → ${lang.code}: ${outputSize} bytes (${(duration / 1000).toFixed(1)}s)`);
|
||||
console.log(
|
||||
` ✓ en → ${lang.code}: ${outputSize} bytes (${(duration / 1000).toFixed(1)}s)`,
|
||||
);
|
||||
} else {
|
||||
stats.failed++;
|
||||
console.log(` ✗ en → ${lang.code}: 輸出為空`);
|
||||
|
|
@ -322,14 +347,16 @@ describe("📚 PDFMathTranslate (pdf2zh)", () => {
|
|||
console.log(` ✗ en → ${lang.code}: ${error}`);
|
||||
throw error;
|
||||
}
|
||||
}, TIMEOUT);
|
||||
},
|
||||
TIMEOUT,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// 次要語言測試(可選)
|
||||
describe("次要語言翻譯 Secondary Languages", () => {
|
||||
const secondaryLanguages = SUPPORTED_LANGUAGES.filter(l =>
|
||||
["de", "fr", "es", "ru"].includes(l.code)
|
||||
const secondaryLanguages = SUPPORTED_LANGUAGES.filter((l) =>
|
||||
["de", "fr", "es", "ru"].includes(l.code),
|
||||
);
|
||||
|
||||
for (const lang of secondaryLanguages) {
|
||||
|
|
@ -349,12 +376,12 @@ describe("📚 PDFMathTranslate (pdf2zh)", () => {
|
|||
|
||||
describe("🌐 BabelDOC", () => {
|
||||
describe("PDF 翻譯", () => {
|
||||
const testLanguages = SUPPORTED_LANGUAGES.filter(l =>
|
||||
["zh", "ja"].includes(l.code)
|
||||
);
|
||||
const testLanguages = SUPPORTED_LANGUAGES.filter((l) => ["zh", "ja"].includes(l.code));
|
||||
|
||||
for (const lang of testLanguages) {
|
||||
test(`英文 → ${lang.nativeName} (${lang.code})`, async () => {
|
||||
test(
|
||||
`英文 → ${lang.nativeName} (${lang.code})`,
|
||||
async () => {
|
||||
stats.total++;
|
||||
|
||||
if (!translators.babeldoc?.available) {
|
||||
|
|
@ -397,7 +424,9 @@ describe("🌐 BabelDOC", () => {
|
|||
|
||||
if (success) {
|
||||
stats.passed++;
|
||||
console.log(` ✓ en → ${lang.code}: ${outputSize} bytes (${(duration / 1000).toFixed(1)}s)`);
|
||||
console.log(
|
||||
` ✓ en → ${lang.code}: ${outputSize} bytes (${(duration / 1000).toFixed(1)}s)`,
|
||||
);
|
||||
} else {
|
||||
stats.failed++;
|
||||
console.log(` ✗ en → ${lang.code}: 輸出為空`);
|
||||
|
|
@ -420,7 +449,9 @@ describe("🌐 BabelDOC", () => {
|
|||
console.log(` ✗ en → ${lang.code}: ${error}`);
|
||||
throw error;
|
||||
}
|
||||
}, TIMEOUT);
|
||||
},
|
||||
TIMEOUT,
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
@ -436,16 +467,25 @@ describe("🔤 語言矩陣測試 Language Matrix", () => {
|
|||
console.log("|------|------|----------|----------|");
|
||||
|
||||
for (const lang of SUPPORTED_LANGUAGES) {
|
||||
console.log(`| ${lang.code.padEnd(6)} | ${lang.name.padEnd(20)} | ${lang.nativeName} | ${lang.testPhrase} |`);
|
||||
console.log(
|
||||
`| ${lang.code.padEnd(6)} | ${lang.name.padEnd(20)} | ${lang.nativeName} | ${lang.testPhrase} |`,
|
||||
);
|
||||
}
|
||||
|
||||
// 生成語言矩陣報告
|
||||
const matrixPath = join(E2E_OUTPUT_DIR, "language-matrix.json");
|
||||
writeFileSync(matrixPath, JSON.stringify({
|
||||
writeFileSync(
|
||||
matrixPath,
|
||||
JSON.stringify(
|
||||
{
|
||||
languages: SUPPORTED_LANGUAGES,
|
||||
translators: Object.keys(translators),
|
||||
generatedAt: new Date().toISOString(),
|
||||
}, null, 2));
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
);
|
||||
|
||||
console.log(`\n📁 語言矩陣已保存: ${matrixPath}`);
|
||||
expect(SUPPORTED_LANGUAGES.length).toBeGreaterThan(0);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue