From 13439a384f9f6468c2f32f41e41f725929f7bffc Mon Sep 17 00:00:00 2001 From: Jaybe Date: Sat, 15 Nov 2025 15:14:19 +0900 Subject: [PATCH] =?UTF-8?q?test(assets):=20grouped=20=EA=B2=BD=EB=A1=9C=20?= =?UTF-8?q?=EC=A0=84=EB=9E=B5=20=EA=B2=80=EC=A6=9D=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/assets/assetManager.grouped.test.ts | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 lib/assets/assetManager.grouped.test.ts 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') + }) +}) -- 2.52.0