Files
Rosea/apps/rosea-tauri/test/config.test.ts
T

127 lines
5.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* The shell's configuration holds what tauri-platforms.md decided (D3–D7, D10, D11). Each of
* these is a value that fails silently at runtime, or worse, only after a release: a changed
* identifier or origin leaves the player's rose behind in the old app.
*/
import { existsSync, readFileSync } from 'node:fs';
import { dirname, join, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { describe, expect, it } from 'vitest';
import { CSP } from '../../rosea/csp.js';
import { PRODUCT_NAME } from '../../../packages/schema/src/constants.js';
const SRC_TAURI = join(dirname(fileURLToPath(import.meta.url)), '..', 'src-tauri');
/** The parts of a Tauri config these tests read. */
interface TauriConf {
productName?: string;
identifier?: string;
version?: string;
build: { frontendDist: string; beforeBuildCommand: string; beforeDevCommand: string; devUrl: string };
app: { windows: Record<string, unknown>[]; security: Record<string, unknown> };
bundle: { targets?: string[] };
plugins?: unknown;
}
const json = (name: string): TauriConf => JSON.parse(readFileSync(join(SRC_TAURI, name), 'utf8')) as TauriConf;
const conf = json('tauri.conf.json');
const window = conf.app.windows[0] ?? {};
describe('tauri.conf.json', () => {
it('names the app with the product name, in the bundle and the window title (D3)', () => {
expect(conf.productName).toBe(PRODUCT_NAME);
expect(window['title']).toBe(PRODUCT_NAME);
});
it('keeps the identifier it was released with: a new one is a different app (D3)', () => {
expect(conf.identifier).toBe('cz.mareknovak.domi.rosea');
});
it("reads its version from the game's package.json (D3)", () => {
expect(conf.version).toBe('../../rosea/package.json');
const pkg = JSON.parse(readFileSync(resolve(SRC_TAURI, String(conf.version)), 'utf8')) as Record<string, string>;
expect(pkg['name']).toBe('@rosea/app');
expect(pkg['version']).toMatch(/^\d+\.\d+\.\d+$/);
});
it("delivers the PWA's content-security policy, the same string (D4)", () => {
expect(conf.app.security['csp']).toBe(CSP);
});
it("wraps the game's shell build and nothing else (D1, D2)", () => {
expect(conf.build.frontendDist).toBe('../../rosea/dist-tauri');
expect(resolve(SRC_TAURI, conf.build.frontendDist)).toBe(resolve(SRC_TAURI, '..', '..', 'rosea', 'dist-tauri'));
expect(conf.build.beforeBuildCommand).toBe('pnpm --filter @rosea/app build:shell');
expect(conf.build.beforeDevCommand).toBe('pnpm --filter @rosea/app dev:shell');
});
it('runs its dev server on 127.0.0.1 only (CLAUDE.md §5.7)', () => {
expect(new URL(conf.build.devUrl).hostname).toBe('127.0.0.1');
const app = JSON.parse(readFileSync(join(SRC_TAURI, '..', '..', 'rosea', 'package.json'), 'utf8')) as { scripts: Record<string, string> };
expect(app['scripts']['dev:shell']).toContain('--host 127.0.0.1');
expect(app['scripts']['dev:shell']).toContain('--port 5173');
expect(conf.build.devUrl).toBe('http://127.0.0.1:5173');
});
it('keeps the https origin it was released with: IndexedDB lives per origin (D10)', () => {
expect(window['useHttpsScheme']).toBe(true);
});
it("switches WebView2's own traffic off (D7)", () => {
const args = String(window['additionalBrowserArgs']);
for (const flag of [
'--disable-background-networking',
'--disable-component-update',
'--disable-domain-reliability',
'--disable-sync',
'--no-pings',
'--disable-client-side-phishing-detection',
'--dns-prefetch-disable'
]) {
expect(args.split(' ')).toContain(flag);
}
const disabled = /--disable-features=(\S+)/.exec(args)?.[1]?.split(',') ?? [];
for (const feature of [
// Tauri's own defaults, which a custom list must repeat.
'msWebOOUI', 'msPdfOOUI', 'msSmartScreenProtection',
'DnsOverHttpsUpgrade', 'msExperimentationAndConfigurationService', 'AutofillServerCommunication', 'OptimizationHints'
]) {
expect(disabled).toContain(feature);
}
});
it('builds only what each system can make (D11)', () => {
expect(json('tauri.windows.conf.json').bundle.targets).toEqual(['nsis']);
expect(json('tauri.macos.conf.json').bundle.targets).toEqual(['app', 'dmg']);
expect(json('tauri.linux.conf.json').bundle.targets).toEqual(['deb', 'appimage']);
expect(conf.bundle.targets).toBeUndefined();
});
it('applies the Android privacy patch before the game is built for Android (D6)', () => {
const before = json('tauri.android.conf.json').build.beforeBuildCommand;
const patch = before.indexOf('pnpm --filter @rosea/tauri android:privacy');
expect(patch).toBe(0);
expect(before.indexOf('&& pnpm --filter @rosea/app build:shell')).toBeGreaterThan(patch);
});
});
describe('the Rust side (D5)', () => {
it('depends on tauri alone: no plugin, no SDK', () => {
const cargo = readFileSync(join(SRC_TAURI, 'Cargo.toml'), 'utf8');
const deps = /\n\[dependencies\]\n([\s\S]*?)(?:\n\[|$)/.exec(cargo)?.[1] ?? '';
const names = deps
.split('\n')
.map((l) => /^([A-Za-z0-9_-]+)\s*=/.exec(l)?.[1])
.filter((n): n is string => n !== undefined);
expect(names).toEqual(['tauri']);
expect(cargo).not.toMatch(/\[target\.[^\]]*dependencies\]/);
});
it('grants the page no IPC: there is no capabilities folder', () => {
expect(existsSync(join(SRC_TAURI, 'capabilities'))).toBe(false);
expect(conf.app.security['capabilities']).toBeUndefined();
});
it('declares no plugin configuration', () => {
expect(conf.plugins).toBeUndefined();
});
});