41 lines
1.9 KiB
JavaScript
41 lines
1.9 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import test from 'node:test';
|
|
|
|
const root = path.resolve(import.meta.dirname, '../..');
|
|
const webRoot = path.join(root, 'src/web');
|
|
const sourceFiles = fs.readdirSync(webRoot, { recursive: true, withFileTypes: true })
|
|
.filter((entry) => entry.isFile() && entry.name.endsWith('.tsx'))
|
|
.map((entry) => path.join(entry.parentPath, entry.name));
|
|
const sources = sourceFiles.map((file) => ({ file, source: fs.readFileSync(file, 'utf8') }));
|
|
const ui = (name) => fs.readFileSync(path.join(webRoot, 'ui', `${name}.tsx`), 'utf8');
|
|
|
|
test('shared client primitives own repeated markup without feature dependencies', () => {
|
|
const tooltip = ui('Tooltip');
|
|
const copyButton = ui('CopyButton');
|
|
const railAction = ui('RailAction');
|
|
const drawer = ui('Drawer');
|
|
|
|
for (const source of [tooltip, copyButton, railAction, drawer]) {
|
|
assert.doesNotMatch(source, /features|api|state\//);
|
|
}
|
|
assert.match(tooltip, /className="client-tooltip"[\s\S]*role="tooltip"/);
|
|
assert.match(copyButton, /client-copy-label[\s\S]*client-copy-feedback/);
|
|
assert.match(railAction, /aria-expanded=\{open\}[\s\S]*aria-controls=\{controls\}/);
|
|
assert.match(drawer, /<aside[\s\S]*aria-hidden=\{!open\}[\s\S]*inert=\{!open[\s\S]*client-drawer-close/);
|
|
});
|
|
|
|
test('all repeated client primitive consumers use the shared owners', () => {
|
|
const production = sources
|
|
.filter(({ file }) => !file.includes(`${path.sep}ui${path.sep}`))
|
|
.map(({ source }) => source)
|
|
.join('\n');
|
|
|
|
assert.equal((production.match(/<Tooltip\b/g) || []).length, 14);
|
|
assert.equal((production.match(/<CopyButton\b/g) || []).length, 2);
|
|
assert.equal((production.match(/<RailAction\b/g) || []).length, 5);
|
|
assert.equal((production.match(/<Drawer\b/g) || []).length, 5);
|
|
assert.doesNotMatch(production, /className="client-tooltip"|className="client-copy-label"|className="client-drawer-close"/);
|
|
});
|