-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathiconSlimming.test.ts
More file actions
59 lines (49 loc) · 2.07 KB
/
iconSlimming.test.ts
File metadata and controls
59 lines (49 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import fs from 'node:fs';
import path from 'node:path';
import { describe, expect, it } from 'vitest';
const ROOT = path.resolve(__dirname);
function read(filePath: string) {
return fs.readFileSync(path.join(ROOT, filePath), 'utf8');
}
describe('icon slimming', () => {
it('does not import the full fontawesome css bundle', () => {
expect(read('index.tsx')).not.toContain('@fortawesome/fontawesome-free/css/all.min.css');
});
it('does not rely on regular or brand fontawesome classes in app source', () => {
const files = [
'App.tsx',
'components',
'hooks',
];
const contents = files
.flatMap((entry) => {
const resolved = path.join(ROOT, entry);
const stat = fs.statSync(resolved);
if (stat.isDirectory()) {
return fs.readdirSync(resolved)
.filter((name) => name.endsWith('.ts') || name.endsWith('.tsx'))
.map((name) => read(path.join(entry, name)));
}
return [read(entry)];
})
.join('\n');
expect(contents).not.toContain('fa-brands');
expect(contents).not.toContain('fa-regular');
});
});
describe('favicon layout', () => {
it('keeps the cube cluster inside the canvas and horizontally centered', () => {
const svg = read('public/icon.svg');
const viewBox = svg.match(/viewBox="([^"]+)"/);
const cubeUses = [...svg.matchAll(/<use[^>]*href="#cube"[^>]*x="([^"]+)"[^>]*y="([^"]+)"/g)];
expect(viewBox).not.toBeNull();
expect(cubeUses.length).toBeGreaterThan(0);
const [, , , width] = viewBox![1].split(/\s+/).map(Number);
const cubeWidth = 60;
const minX = Math.min(...cubeUses.map(([, x]) => Number(x)));
const maxX = Math.max(...cubeUses.map(([, x]) => Number(x) + cubeWidth));
expect(minX).toBeGreaterThanOrEqual(0);
expect(maxX).toBeLessThanOrEqual(width);
expect((minX + maxX) / 2).toBeCloseTo(width / 2, 0);
});
});