Compare commits

...
3 changed files with 71 additions and 36 deletions

No files matched your search

+35 -33
View File
@@ -1,33 +1,35 @@
{ {
"name": "frontend", "name": "frontend",
"version": "1.0.0", "version": "1.0.0",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "vite build", "build": "vite build",
"preview": "vite preview" "preview": "vite preview",
}, "test": "vitest run"
"keywords": [], },
"author": "", "keywords": [],
"license": "ISC", "author": "",
"dependencies": { "license": "ISC",
"@types/qrcode": "^1.5.6", "dependencies": {
"highlight.js": "^11.11.1", "@types/qrcode": "^1.5.6",
"html2canvas": "^1.4.1", "highlight.js": "^11.11.1",
"jspdf": "^4.2.1", "html2canvas": "^1.4.1",
"katex": "^0.17.0", "jspdf": "^4.2.1",
"mermaid": "^11.16.0", "katex": "^0.17.0",
"qrcode": "^1.5.4", "mermaid": "^11.16.0",
"react": "^18.3.1", "qrcode": "^1.5.4",
"react-dom": "^18.3.1", "react": "^18.3.1",
"react-router-dom": "^6.30.3" "react-dom": "^18.3.1",
}, "react-router-dom": "^6.30.3"
"devDependencies": { },
"@types/react": "^18.3.29", "devDependencies": {
"@types/react-dom": "^18.3.7", "@types/react": "^18.3.29",
"@vitejs/plugin-react": "^4.7.0", "@types/react-dom": "^18.3.7",
"typescript": "^5.9.3", "@vitejs/plugin-react": "^4.7.0",
"vite": "^5.4.21" "typescript": "^5.9.3",
} "vite": "^5.4.21",
} "vitest": "^4.1.10"
}
}
+29
View File
@@ -0,0 +1,29 @@
import { describe, it, expect } from 'vitest';
import { formatBjTime } from './datetime';
// 北京时间渲染曾是反复出现的问题(微信Bot时间错乱、Token驾驶舱时间列不正确等)。
// 该测试固化「后端按北京时间存储、前端显式按 Asia/Shanghai 渲染」的契约。
describe('formatBjTime', () => {
it('空输入返回占位符 -', () => {
expect(formatBjTime(undefined)).toBe('-');
expect(formatBjTime(null)).toBe('-');
expect(formatBjTime('')).toBe('-');
});
it('无时区标记的时间戳按 Asia/Shanghai (+08:00) 渲染', () => {
// 2026-07-18T12:00:00 视为北京时间,渲染应含 12:00:00
const out = formatBjTime('2026-07-18T12:00:00');
expect(out).toContain('2026');
expect(out).toContain('12:00:00');
});
it('UTC(Z) 时间戳正确转换为北京时间 (+8)', () => {
// 2026-07-18T04:00:00Z = 北京时间 12:00:00
const out = formatBjTime('2026-07-18T04:00:00Z');
expect(out).toContain('12:00:00');
});
it('非法日期原样返回', () => {
expect(formatBjTime('not-a-date')).toBe('not-a-date');
});
});
+7 -3
View File
@@ -1,4 +1,5 @@
import { defineConfig } from 'vite'; /// <reference types="vitest/config" />
import { defineConfig } from 'vitest/config';
import react from '@vitejs/plugin-react'; import react from '@vitejs/plugin-react';
import path from 'path'; import path from 'path';
@@ -17,8 +18,6 @@ export default defineConfig({
chunkSizeWarningLimit: 1200, chunkSizeWarningLimit: 1200,
rollupOptions: { rollupOptions: {
output: { output: {
// 仅将 react 核心库单独打包(长期缓存);
// 其余第三方库交给 Rollup 自动按需拆分,避免被强制合并成一个大 vendor 在首屏加载
manualChunks(id) { manualChunks(id) {
if (id.includes('node_modules')) { if (id.includes('node_modules')) {
if ( if (
@@ -37,4 +36,9 @@ export default defineConfig({
server: { server: {
port: 5173, port: 5173,
}, },
// Phase 0 测试基建:vitest 配置(纯函数测试用 node 环境,组件测试可改 jsdom)
test: {
environment: 'node',
include: ['src/**/*.test.ts'],
},
}); });