| import { describe, it, expect, beforeAll } from 'vitest'; |
| import 'fake-indexeddb/auto'; |
| import { vfs } from '../index'; |
|
|
| |
| |
|
|
| describe('project export/import round-trip', () => { |
| beforeAll(async () => { |
| await vfs.init(); |
| }); |
|
|
| it('preserves binary files and project settings through JSON', async () => { |
| const project = await vfs.createProject('Round Trip', 'test'); |
| project.settings = { ...project.settings, runtime: 'static' }; |
| await vfs.updateProject(project); |
|
|
| await vfs.createFile(project.id, '/index.html', '<html><body>hi</body></html>'); |
|
|
| const pngBytes = new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10, 1, 2, 3, 250]); |
| await vfs.createFile(project.id, '/myimage.png', pngBytes.buffer); |
|
|
| |
| const exported = await vfs.exportProject(project.id); |
| const roundTripped = JSON.parse(JSON.stringify(exported)); |
|
|
| const imported = await vfs.importProject(roundTripped); |
|
|
| |
| expect(imported.settings.runtime).toBe('static'); |
|
|
| |
| const html = await vfs.readFile(imported.id, '/index.html'); |
| expect(html.content).toBe('<html><body>hi</body></html>'); |
|
|
| |
| const img = await vfs.readFile(imported.id, '/myimage.png'); |
| expect(img.content).toBeInstanceOf(ArrayBuffer); |
| expect(Array.from(new Uint8Array(img.content as ArrayBuffer))).toEqual( |
| Array.from(pngBytes) |
| ); |
| }); |
|
|
| it('duplicateProject carries over project settings', async () => { |
| const project = await vfs.createProject('Dup Settings', 'test'); |
| project.settings = { ...project.settings, runtime: 'static' }; |
| await vfs.updateProject(project); |
|
|
| const copy = await vfs.duplicateProject(project.id); |
| expect(copy.settings.runtime).toBe('static'); |
| }); |
| }); |
|
|