diff options
Diffstat (limited to 'viewer/tests/importmap.mjs')
| -rw-r--r-- | viewer/tests/importmap.mjs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/viewer/tests/importmap.mjs b/viewer/tests/importmap.mjs new file mode 100644 index 0000000..301d2bc --- /dev/null +++ b/viewer/tests/importmap.mjs @@ -0,0 +1,15 @@ +// Import first, then load viewer modules with dynamic import(): bare 'three' resolves as in index.html. +import { register } from 'node:module'; +import { readFileSync } from 'node:fs'; + +export const HTML = readFileSync(new URL('../index.html', import.meta.url), 'utf8'); +export const IMPORTS = JSON.parse(HTML.match(/<script type="importmap">([\s\S]*?)<\/script>/)[1]).imports; +register('./importmap-hooks.mjs', import.meta.url, { data: { imports: IMPORTS, base: new URL('../', import.meta.url).href } }); + +export function fakeCanvas(width = 800, height = 400) { + const c = new EventTarget(); + Object.assign(c, { style: {}, ownerDocument: new EventTarget(), setPointerCapture() {}, releasePointerCapture() {}, + getRootNode: () => new EventTarget(), getBoundingClientRect: () => ({ left: 0, top: 0, width, height }) }); + return c; +} +export const fakeRenderer = () => ({ domElement: fakeCanvas(), render() {} }); |
