Option2 무결성 강화: integrity index 추가, 인덱스 정렬/교차 검증, referencedAt 매트릭스, README 문서화 (TDD)
This commit is contained in:
@@ -19,4 +19,38 @@ describe('Assets index builder', () => {
|
||||
expect(obj.fonts[0]).toMatch(/^assets\/[0-9a-f]{8}\.woff2$/)
|
||||
expect(obj.other[0]).toMatch(/^assets\/[0-9a-f]{8}\.txt$/)
|
||||
})
|
||||
|
||||
it('sorts each group array by path (ascending)', async () => {
|
||||
const am = new AssetManager({ maxBytes: 1024*1024, allowedExts: ['png','txt','woff2'] })
|
||||
// Add in shuffled order so that sort is required
|
||||
await am.add({ name: 'z.png', type: 'image/png', bytes: u8(3) })
|
||||
await am.add({ name: 'a.png', type: 'image/png', bytes: u8(5) })
|
||||
await am.add({ name: 'm.txt', type: 'text/plain', bytes: u8(2) })
|
||||
await am.add({ name: 'b.txt', type: 'text/plain', bytes: u8(4) })
|
||||
await am.add({ name: 'f.woff2', type: 'font/woff2', bytes: u8(6) })
|
||||
await am.add({ name: 'e.woff2', type: 'font/woff2', bytes: u8(7) })
|
||||
const bytes = buildAssetsIndex(am)
|
||||
const obj = JSON.parse(new TextDecoder().decode(bytes)) as { images: string[]; fonts: string[]; other: string[] }
|
||||
const imgs = [...obj.images]
|
||||
const fonts = [...obj.fonts]
|
||||
const others = [...obj.other]
|
||||
const sortedImgs = [...imgs].sort()
|
||||
const sortedFonts = [...fonts].sort()
|
||||
const sortedOthers = [...others].sort()
|
||||
expect(imgs).toEqual(sortedImgs)
|
||||
expect(fonts).toEqual(sortedFonts)
|
||||
expect(others).toEqual(sortedOthers)
|
||||
})
|
||||
|
||||
it('respects grouped pathStrategy and outputs grouped paths in index', async () => {
|
||||
const am = new AssetManager({ maxBytes: 1024*1024, allowedExts: ['png','woff2','txt'], pathStrategy: 'grouped' })
|
||||
await am.add({ name: 'hero.png', type: 'image/png', bytes: u8(10) })
|
||||
await am.add({ name: 'main.woff2', type: 'font/woff2', bytes: u8(12) })
|
||||
await am.add({ name: 'readme.txt', type: 'text/plain', bytes: u8(1) })
|
||||
const bytes = buildAssetsIndex(am)
|
||||
const obj = JSON.parse(new TextDecoder().decode(bytes)) as { images: string[]; fonts: string[]; other: string[] }
|
||||
expect(obj.images[0]).toMatch(/^assets\/images\/[0-9a-f]{8}\.png$/)
|
||||
expect(obj.fonts[0]).toMatch(/^assets\/fonts\/[0-9a-f]{8}\.woff2$/)
|
||||
expect(obj.other[0]).toMatch(/^assets\/other\/[0-9a-f]{8}\.txt$/)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user