31 lines
1.2 KiB
TypeScript
31 lines
1.2 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { AssetManager } from '@/lib/assets/assetManager'
|
|
import { buildAssetsMetadata } from '@/lib/exporter/assets.meta'
|
|
import type { AssetMetaItem } from '@/lib/exporter/assets.meta'
|
|
|
|
function u8(n: number): Uint8Array {
|
|
const arr = new Uint8Array(n)
|
|
for (let i = 0; i < n; i++) arr[i] = (i * 31) & 0xff
|
|
return arr
|
|
}
|
|
|
|
describe('Assets metadata builder', () => {
|
|
it('emits assets.json with originalName/mime/size/hash/ext/zipPath', async () => {
|
|
const am = new AssetManager({ maxBytes: 1024 * 1024, allowedExts: ['png'] })
|
|
const bytes = u8(10)
|
|
await am.add({ name: 'hero.png', type: 'image/png', bytes })
|
|
const metaBytes = buildAssetsMetadata(am)
|
|
const json = new TextDecoder().decode(metaBytes)
|
|
const obj = JSON.parse(json) as { assets: AssetMetaItem[] }
|
|
expect(Array.isArray(obj.assets)).toBe(true)
|
|
expect(obj.assets.length).toBe(1)
|
|
const a = obj.assets[0]
|
|
expect(a.originalName).toBe('hero.png')
|
|
expect(a.mimeType).toBe('image/png')
|
|
expect(a.size).toBe(bytes.byteLength)
|
|
expect(a.ext).toBe('png')
|
|
expect(a.hash8).toMatch(/^[0-9a-f]{8}$/)
|
|
expect(a.zipPath).toMatch(/^assets\/[0-9a-f]{8}\.png$/)
|
|
})
|
|
})
|