- 同步商品与订单时处理线上删除状态并联动自动化规则\n- 过滤卖家系统中的购买订单,修复订单逻辑删除与数据库迁移\n- 修复聊天新消息自动滚动,并统一前端颜色令牌与硬编码颜色检查
37 lines
1.5 KiB
TypeScript
37 lines
1.5 KiB
TypeScript
import { readdirSync, readFileSync } from 'node:fs';
|
|
import { resolve } from 'node:path';
|
|
import { describe, expect, test } from 'vitest';
|
|
|
|
const componentsDir = resolve(__dirname, 'components');
|
|
const pageSources = [
|
|
resolve(__dirname, 'App.tsx'),
|
|
...readdirSync(componentsDir)
|
|
.filter((fileName) => fileName.endsWith('.tsx') && !fileName.endsWith('.test.tsx'))
|
|
.map((fileName) => resolve(componentsDir, fileName)),
|
|
];
|
|
|
|
// rgb(var(--color-*)), CSS classes and the central index.css are references.
|
|
// Literal colors in page code would bypass the design-token system.
|
|
const hardCodedColorPattern = /#[0-9a-f]{3,8}\b|rgba?\((?!var\(--color-)/gi;
|
|
|
|
describe('global color token contract', () => {
|
|
test('page components do not contain hard-coded color values', () => {
|
|
const violations = pageSources.flatMap((filePath) => {
|
|
const source = readFileSync(filePath, 'utf8');
|
|
return [...source.matchAll(hardCodedColorPattern)].map((match) => `${filePath}:${match[0]}`);
|
|
});
|
|
|
|
expect(violations).toEqual([]);
|
|
});
|
|
|
|
test('the primary brand and highlight colors are defined in the central stylesheet', () => {
|
|
const globalStyles = readFileSync(resolve(__dirname, 'index.css'), 'utf8');
|
|
|
|
expect(globalStyles).toContain('--color-brand: 0 148 247;');
|
|
expect(globalStyles).toContain('--color-brand-highlight: 0 113 227;');
|
|
expect(globalStyles).toContain('--color-success-500:');
|
|
expect(globalStyles).toContain('--color-warning-500:');
|
|
expect(globalStyles).toContain('--color-danger-500:');
|
|
});
|
|
});
|