File size: 1,824 Bytes
dd53693
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Checks the .glb export in a real browser:  node tests/check_export.mjs
import fs from 'node:fs';
import http from 'node:http';
import path from 'node:path';
import { chromium } from 'playwright-core';

const WEB = new URL('../web/', import.meta.url).pathname;
const server = http.createServer((req, res) => {
  const f = path.join(WEB, decodeURIComponent(req.url.split('?')[0]).replace(/\/$/, '/index.html'));
  if (!fs.existsSync(f)) { res.writeHead(404); return res.end(); }
  res.writeHead(200, { 'content-type': { '.html': 'text/html', '.js': 'text/javascript', '.css': 'text/css', '.json': 'application/json' }[path.extname(f)] ?? 'application/octet-stream' });
  fs.createReadStream(f).pipe(res);
}).listen(0);
const root = `${process.env.HOME}/.cache/ms-playwright`;
const exe = process.env.CHROME ?? fs.readdirSync(root).filter((d) => d.startsWith('chromium_headless_shell')).flatMap((d) => fs.readdirSync(`${root}/${d}`).map((s) => `${root}/${d}/${s}/chrome-headless-shell`)).find((p) => fs.existsSync(p));
const browser = await chromium.launch({ executablePath: exe, args: ['--use-gl=angle', '--use-angle=swiftshader', '--enable-unsafe-swiftshader'] });
const page = await browser.newPage();
await page.goto(`http://localhost:${server.address().port}/?q=${encodeURIComponent('a knight riding a dragon next to a tower')}`);
await page.waitForFunction(() => window.tinyScene?.ready, null, { timeout: 60000 });
const r = await page.evaluate(async () => {
  const blob = await window.tinyScene.stage.exportGLB(), head = new Uint8Array(await blob.slice(0, 4).arrayBuffer());
  return { bytes: blob.size, magic: String.fromCharCode(...head) };
});
console.log('glb export:', r, r.magic === 'glTF' && r.bytes > 10000 ? 'ok' : 'FAILED');
await browser.close();
server.close();
process.exit(r.magic === 'glTF' ? 0 : 1);