This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import test from 'node:test';
|
||||
import { analyzeCss, broadBusinessSelectors, verifyGlobalCssAbsent } from './verify-css-governance.mjs';
|
||||
|
||||
test('AST metrics ignore formatting and count selectors and important declarations', () => {
|
||||
assert.deepEqual(analyzeCss('.page { color: red !important; }\n.page a, .page button { display: block; }'), {
|
||||
rules: 2,
|
||||
selectors: 3,
|
||||
declarations: 2,
|
||||
important: 1,
|
||||
selectorList: ['.page', '.page a', '.page button'],
|
||||
});
|
||||
});
|
||||
|
||||
test('broad business tag selectors are rejected while rooted selectors are allowed', () => {
|
||||
assert.deepEqual(broadBusinessSelectors('button { color: red; } .report-page button { color: blue; }'), ['button']);
|
||||
});
|
||||
|
||||
test('formatting changes do not affect AST growth metrics', () => {
|
||||
assert.deepEqual(analyzeCss('.page{color:red}'), analyzeCss('.page {\n color: red;\n}\n'));
|
||||
});
|
||||
|
||||
test('global.css cannot be recreated after migration', () => {
|
||||
const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'cmpp-css-gate-'));
|
||||
fs.mkdirSync(path.join(directory, 'src/styles'), { recursive: true });
|
||||
assert.doesNotThrow(() => verifyGlobalCssAbsent(directory));
|
||||
fs.writeFileSync(path.join(directory, 'src/styles/global.css'), '.new-page {}');
|
||||
assert.throws(() => verifyGlobalCssAbsent(directory), /禁止重新创建/);
|
||||
fs.rmSync(directory, { recursive: true, force: true });
|
||||
});
|
||||
Reference in New Issue
Block a user