/**
* The game's build for the shell (`vite build --mode tauri`, tauri-platforms.md D2), made into a
* temporary folder and read: no service worker, no manifest, no policy, assets at the root,
* and the shell constant replaced. The PWA's own build is checked by the e2e suites.
*/
import { spawnSync } from 'node:child_process';
import { mkdtempSync, readdirSync, readFileSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
const APP = join(dirname(fileURLToPath(import.meta.url)), '..', '..', 'rosea');
let out = '';
let html = '';
let files: string[] = [];
let scripts = '';
beforeAll(() => {
out = mkdtempSync(join(tmpdir(), 'rosea-shell-build-'));
const build = spawnSync('pnpm', ['exec', 'vite', 'build', '--mode', 'tauri', '--outDir', out, '--emptyOutDir', '--logLevel', 'error'], {
cwd: APP,
encoding: 'utf8',
shell: process.platform === 'win32'
});
if (build.status !== 0) throw new Error(`vite build --mode tauri failed:\n${build.stdout}\n${build.stderr}`);
files = readdirSync(out, { recursive: true, encoding: 'utf8' }).map((f) => f.replaceAll('\\', '/'));
html = readFileSync(join(out, 'index.html'), 'utf8');
scripts = files.filter((f) => f.endsWith('.js')).map((f) => readFileSync(join(out, f), 'utf8')).join('\n');
}, 120_000);
afterAll(() => {
if (out) rmSync(out, { recursive: true, force: true });
});
describe('the game built for the shell', () => {
it('has no service worker and no web manifest', () => {
expect(files.filter((f) => /(^|\/)(sw|workbox-[^/]*|registerSW)\.js$/.test(f))).toEqual([]);
expect(files.filter((f) => f.endsWith('.webmanifest'))).toEqual([]);
expect(html).not.toContain('manifest');
expect(scripts).not.toContain('navigator.serviceWorker.register');
});
it('carries no content-security policy: Tauri delivers it (D4)', () => {
expect(html).not.toContain('Content-Security-Policy');
});
it('loads its assets from the root of the origin, not /Rosea/', () => {
const urls = [...html.matchAll(/(?:src|href)="([^"]+)"/g)].map((m) => m[1]!);
const assets = urls.filter((u) => u.includes('assets/'));
expect(assets.length).toBeGreaterThanOrEqual(2);
for (const u of assets) expect(u.startsWith('/assets/')).toBe(true);
expect(html).not.toContain('/Rosea/');
});
it('replaces the shell constant at build time: left in, it would throw in the webview', () => {
expect(scripts).not.toContain('__ROSEA_SHELL__');
});
it('ships no source maps', () => {
expect(files.filter((f) => f.endsWith('.map'))).toEqual([]);
});
});