(files: Record<string, string>)
| 18 | } |
| 19 | |
| 20 | function fakeWebAssets(files: Record<string, string>): { |
| 21 | manifest: WebAssetManifest; |
| 22 | source: WebAssetSource; |
| 23 | } { |
| 24 | const manifest: WebAssetManifest = { |
| 25 | version: WEB_ASSET_MANIFEST_VERSION, |
| 26 | target: 'test-target', |
| 27 | root: 'dist-web', |
| 28 | files: Object.entries(files).map(([relativePath, content]) => ({ |
| 29 | assetKey: `web/test-target/dist-web/${relativePath}`, |
| 30 | relativePath, |
| 31 | sha256: sha256(content), |
| 32 | })), |
| 33 | }; |
| 34 | const assets = new Map<string, Buffer>([ |
| 35 | ['web/test-target/manifest.json', Buffer.from(JSON.stringify(manifest))], |
| 36 | ...Object.entries(files).map(([relativePath, content]) => [ |
| 37 | `web/test-target/dist-web/${relativePath}`, |
| 38 | Buffer.from(content), |
| 39 | ] as const), |
| 40 | ]); |
| 41 | return { |
| 42 | manifest, |
| 43 | source: { |
| 44 | getAssetKeys: () => [...assets.keys()], |
| 45 | getRawAsset: (assetKey) => { |
| 46 | const asset = assets.get(assetKey); |
| 47 | if (asset === undefined) throw new Error(`missing test asset: ${assetKey}`); |
| 48 | return asset; |
| 49 | }, |
| 50 | }, |
| 51 | }; |
| 52 | } |
| 53 | |
| 54 | describe('web assets', () => { |
| 55 | it('extracts embedded web assets into a dist-web cache directory', () => { |
no test coverage detected