chore: replace all cn comments of fe to en version by volc api (#320)

This commit is contained in:
tecvan
2025-07-31 10:32:15 +08:00
committed by GitHub
parent 716ec0cba8
commit 71f6245a01
2960 changed files with 15545 additions and 15545 deletions

View File

@@ -23,65 +23,65 @@ describe('generatePdfAssetsUrl', () => {
const originalRegion = global.REGION;
beforeEach(() => {
// 重置模拟
// Reset simulation
vi.resetAllMocks();
});
afterEach(() => {
// 恢复原始 REGION
// Restore original REGION value
global.REGION = originalRegion;
});
it('应该为 cmaps 生成正确的 URL中国区域', () => {
// 设置区域为中国
// Set the region to China
global.REGION = 'cn';
const url = generatePdfAssetsUrl('cmaps');
// 验证 URL 格式
// Verify URL format
expect(url).toContain('//lf-cdn.coze.cn/obj/unpkg');
expect(url).toContain(pkg.name.replace(/^@/, ''));
expect(url).toContain('lib/cmaps/');
});
it('应该为 pdf.worker 生成正确的 URL中国区域', () => {
// 设置区域为中国
// Set the region to China
global.REGION = 'cn';
const url = generatePdfAssetsUrl('pdf.worker');
// 验证 URL 格式
// Verify URL format
expect(url).toContain('//lf-cdn.coze.cn/obj/unpkg');
expect(url).toContain(pkg.name.replace(/^@/, ''));
expect(url).toContain('lib/worker.js');
});
it('应该为 cmaps 生成正确的 URL国际区域', () => {
// 设置区域为国际
// Set the region to International
global.REGION = 'va';
const url = generatePdfAssetsUrl('cmaps');
// 验证 URL 格式
// Verify URL format
expect(url).toContain('//sf-cdn.coze.com/obj/unpkg-va');
expect(url).toContain(pkg.name.replace(/^@/, ''));
expect(url).toContain('lib/cmaps/');
});
it('应该为 pdf.worker 生成正确的 URL国际区域', () => {
// 设置区域为国际
// Set the region to International
global.REGION = 'va';
const url = generatePdfAssetsUrl('pdf.worker');
// 验证 URL 格式
// Verify URL format
expect(url).toContain('//sf-cdn.coze.com/obj/unpkg-va');
expect(url).toContain(pkg.name.replace(/^@/, ''));
expect(url).toContain('lib/worker.js');
});
it('应该在传入无效资源类型时抛出错误', () => {
// 使用类型断言来测试错误情况
// Use type assertions to test error conditions
expect(() => generatePdfAssetsUrl('invalid' as any)).toThrow(
'目前只支持引用 cmaps 与 pdf.worker 文件',
);

View File

@@ -16,12 +16,12 @@
import { describe, it, expect, vi } from 'vitest';
// 模拟 pdfjs-dist 模块
// Emulate pdfjs-dist module
vi.mock('pdfjs-dist', () => ({
getDocument: vi.fn(),
}));
// 模拟 generate-assets init-pdfjs-dist 模块
// Emulate generate-assets and init-pdfjs-dist modules
vi.mock('../src/generate-assets', () => ({
generatePdfAssetsUrl: vi.fn(),
}));
@@ -30,7 +30,7 @@ vi.mock('../src/init-pdfjs-dist', () => ({
initPdfJsWorker: vi.fn(),
}));
// 导入被测试的模块
// Import the tested module
import {
generatePdfAssetsUrl,
initPdfJsWorker,
@@ -39,11 +39,11 @@ import {
describe('pdfjs-shadow index', () => {
it('应该导出所有必要的函数和类型', () => {
// 验证导出的函数
// Validate the derived function
expect(typeof generatePdfAssetsUrl).toBe('function');
expect(typeof initPdfJsWorker).toBe('function');
// 验证从 pdfjs-dist 重新导出的函数和类型
// Verify functions and types re-exported from pdfjs-dist
expect(getDocument).toBeDefined();
});
});

View File

@@ -16,19 +16,19 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
// 模拟 pdfjs-dist 模块
// Emulate pdfjs-dist module
vi.mock('pdfjs-dist', () => ({
GlobalWorkerOptions: {
workerSrc: '',
},
}));
// 模拟 generate-assets 模块
// Simulate generate-assets module
vi.mock('../src/generate-assets', () => ({
generatePdfAssetsUrl: vi.fn().mockReturnValue('mocked-worker-url'),
}));
// 导入被测试的模块
// Import the tested module
import { GlobalWorkerOptions } from 'pdfjs-dist';
import { initPdfJsWorker } from '../src/init-pdfjs-dist';
@@ -36,43 +36,43 @@ import { generatePdfAssetsUrl } from '../src/generate-assets';
describe('initPdfJsWorker', () => {
beforeEach(() => {
// 每个测试前重置 GlobalWorkerOptions.workerSrc
// Reset GlobalWorkerOptions.workerSrc before each test
GlobalWorkerOptions.workerSrc = '';
// 清除所有模拟函数的调用记录
// Clear all call records for simulated functions
vi.clearAllMocks();
});
afterEach(() => {
// 每个测试后重置模拟
// Reset simulation after each test
vi.resetAllMocks();
});
it('应该设置 GlobalWorkerOptions.workerSrc 当它为空时', () => {
// 确保 workerSrc 初始为空
// Make sure workerSrc is initially empty
expect(GlobalWorkerOptions.workerSrc).toBe('');
// 调用初始化函数
// Invoke initialization function
initPdfJsWorker();
// 验证 generatePdfAssetsUrl 被调用,且参数正确
// Verify generatePdfAssetsUrl is called and the parameters are correct
expect(generatePdfAssetsUrl).toHaveBeenCalledTimes(1);
expect(generatePdfAssetsUrl).toHaveBeenCalledWith('pdf.worker');
// 验证 workerSrc 被正确设置
// Verify that workerSrc is set correctly
expect(GlobalWorkerOptions.workerSrc).toBe('mocked-worker-url');
});
it('不应该重新设置 GlobalWorkerOptions.workerSrc 当它已经有值时', () => {
// 预先设置 workerSrc
// Pre-set workerSrc
GlobalWorkerOptions.workerSrc = 'existing-worker-url';
// 调用初始化函数
// Invoke initialization function
initPdfJsWorker();
// 验证 generatePdfAssetsUrl 没有被调用
// Verify generatePdfAssetsUrl not called
expect(generatePdfAssetsUrl).not.toHaveBeenCalled();
// 验证 workerSrc 保持不变
// Verify that workerSrc remains unchanged
expect(GlobalWorkerOptions.workerSrc).toBe('existing-worker-url');
});
});