smoke-web.mjs 874 B

1234567891011121314151617181920
  1. const base = 'http://localhost:4173/web/index.html';
  2. const response = await fetch(base);
  3. if (!response.ok) throw new Error(`preview page returned ${response.status}`);
  4. const html = await response.text();
  5. const script = html.match(/<script>([\s\S]*)<\/script>/)?.[1];
  6. if (!script) throw new Error('missing inline game script');
  7. new Function(script);
  8. const assetUrls = [...html.matchAll(/'\.\.\/assets\/resources\/sprites\/([^']+)'/g)]
  9. .map((m) => new URL(`../assets/resources/sprites/${m[1]}`, base).href);
  10. for (const url of assetUrls) {
  11. const asset = await fetch(url);
  12. if (!asset.ok) throw new Error(`asset failed: ${url} -> ${asset.status}`);
  13. const type = asset.headers.get('content-type') || '';
  14. if (!type.includes('image/png')) throw new Error(`asset is not png: ${url} (${type})`);
  15. }
  16. console.log(`web smoke passed: ${assetUrls.length} png assets loaded`);