diff --git a/lib/assets/assetManager.grouped.test.ts b/lib/assets/assetManager.grouped.test.ts new file mode 100644 index 0000000..68d04df --- /dev/null +++ b/lib/assets/assetManager.grouped.test.ts @@ -0,0 +1,26 @@ +import { describe, it, expect } from 'vitest' +import { AssetManager } from '@/lib/assets/assetManager' + +function u8(n: number): Uint8Array { const a = new Uint8Array(n); for (let i=0;i { + it('writes assets under assets/images and assets/fonts when grouped', async () => { + const am = new AssetManager({ maxBytes: 1024*1024, allowedExts: ['png','woff2'], pathStrategy: 'grouped' }) + const img = await am.add({ name: 'hero.png', type: 'image/png', bytes: u8(10) }) + const font = await am.add({ name: 'main.woff2', type: 'font/woff2', bytes: u8(12) }) + expect(img.path).toMatch(/^assets\/images\/[0-9a-f]{8}\.png$/) + expect(font.path).toMatch(/^assets\/fonts\/[0-9a-f]{8}\.woff2$/) + const zip = am.toZipStructure() + const keys = Object.keys(zip) + expect(keys.some(k => /^assets\/images\//.test(k))).toBe(true) + expect(keys.some(k => /^assets\/fonts\//.test(k))).toBe(true) + }) + + it('rewriteUrl marks referenced originals and returns grouped path', async () => { + const am = new AssetManager({ maxBytes: 1024*1024, allowedExts: ['png'], pathStrategy: 'grouped' }) + const img = await am.add({ name: 'hero.png', type: 'image/png', bytes: u8(10) }) + const rewritten = am.rewriteUrl('local:hero.png') + expect(rewritten).toBe(img.path) + expect(am.referencedList()).toContain('hero.png') + }) +})