mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-20 11:06:06 +00:00
848e3f90e1
Every lucide icon is its own module, and the plugin icon lookup reaches all of them by name from the navigation. The bundler therefore put each icon another chunk also uses into a chunk of its own: 187 files of a few hundred bytes, each one a request on a first visit and an entry in the precache. A `vendor-icons` group collects them. The first load asks for 32 script files instead of 224 (the bytes stay the same, 3.9 MB before compression), and the service worker installs 460 files instead of 652. With 50 ms added to every response the login page reaches DOMContentLoaded in 0.5 s instead of 3.8 s.
34 lines
1.8 KiB
TypeScript
34 lines
1.8 KiB
TypeScript
import { readFileSync } from 'node:fs';
|
|
import { resolve } from 'node:path';
|
|
import { describe, expect, it } from 'vitest';
|
|
import { ICON_CHUNK } from '../../../iconChunk.js';
|
|
|
|
describe('ICON_CHUNK', () => {
|
|
it('FE-ICON-CHUNK-001: takes every lucide module, on either path separator', () => {
|
|
expect(ICON_CHUNK.test.test('/app/node_modules/lucide-react/dist/esm/icons/chevron-down.js')).toBe(true);
|
|
expect(ICON_CHUNK.test.test('/app/node_modules/lucide-react/dist/esm/createLucideIcon.js')).toBe(true);
|
|
expect(ICON_CHUNK.test.test('C:\\app\\node_modules\\lucide-react\\dist\\esm\\icons\\map.js')).toBe(true);
|
|
});
|
|
|
|
it('FE-ICON-CHUNK-002: takes nothing else', () => {
|
|
expect(ICON_CHUNK.test.test('/app/node_modules/react/index.js')).toBe(false);
|
|
expect(ICON_CHUNK.test.test('/app/node_modules/lucide-react-native/dist/esm/icons/map.js')).toBe(false);
|
|
expect(ICON_CHUNK.test.test('/app/client/src/components/shared/PluginIcon.tsx')).toBe(false);
|
|
expect(ICON_CHUNK.test.test('/app/client/src/lucide-react/own.ts')).toBe(false);
|
|
});
|
|
|
|
it('FE-ICON-CHUNK-003: holds only what the first load already needs', () => {
|
|
// Without the tag the group would also collect icons that sit behind a lazy route
|
|
// and make them part of the first load (see the note on the groups in vite.config.js).
|
|
expect(ICON_CHUNK.tags).toEqual(['$initial']);
|
|
expect(ICON_CHUNK.name).toBe('vendor-icons');
|
|
});
|
|
|
|
it('FE-ICON-CHUNK-004: vite.config.js lists it among the chunk groups', () => {
|
|
const config = readFileSync(resolve(process.cwd(), 'vite.config.js'), 'utf8');
|
|
const groups = config.slice(config.indexOf('groups: ['));
|
|
expect(config).toContain("import { ICON_CHUNK } from './iconChunk.js'");
|
|
expect(groups).toMatch(/groups: \[[\s\S]*?\n {12}ICON_CHUNK,\n/);
|
|
});
|
|
});
|