| 1 |
import {readdir, readFile} from "node:fs/promises"; |
| 2 |
|
| 3 |
import {expect, test} from "vitest"; |
| 4 |
|
| 5 |
test("uses a viewer-relative parser worker URL", async () => { |
| 6 |
const names = await readdir("_static/viewer", {recursive: true}); |
| 7 |
const scripts = names.filter((name) => name.endsWith(".js")); |
| 8 |
const bundle = (await Promise.all(scripts.map((name) => readFile(`_static/viewer/${name}`, "utf8")))).join("\n"); |
| 9 |
expect(bundle).toMatch(/new URL\("assets\/parser\.worker-[A-Za-z0-9_-]+\.js"/); |
| 10 |
expect(bundle).not.toMatch(/new URL\("\/assets\/parser\.worker-/); |
| 11 |
}); |
| 12 |
|
| 13 |
test("emits an independently reusable component and scoped stylesheet", async () => { |
| 14 |
const component = await readFile("_static/viewer/component.js", "utf8"); |
| 15 |
const styles = await readFile("_static/viewer/viewer.css", "utf8"); |
| 16 |
expect(component).toContain("mountColmapViewer"); |
| 17 |
expect(component).not.toContain("#colmap-viewer-root"); |
| 18 |
expect(styles).toContain(".colmap-viewer-host .viewer-workspace"); |
| 19 |
expect(styles).not.toMatch(/(^|})\.viewer-workspace/); |
| 20 |
}); |