44 lines
2.5 KiB
JavaScript
44 lines
2.5 KiB
JavaScript
// Document-start check: the built X runtime (src-tauri/x-runtime.js) injected the way the app does it,
|
|
// as an init script that runs before the parser has created <html>, into a static x.com fixture. Every
|
|
// feature is switched on, then off, then on again; any "[wayBetter for X] … failed" console error or page
|
|
// error fails the check. Run `node scripts/build-inject.mjs` first. Not a live X test. The check is
|
|
// the framework's (waybetter/dev-tools/runtime-start-check.mjs); X's fixtures and expectations are here.
|
|
//
|
|
// node scripts/runtime-start-check.mjs
|
|
|
|
import { readFile } from 'node:fs/promises';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { join } from 'node:path';
|
|
import { chromium } from 'playwright';
|
|
import { runtimeStartCheck } from '../../../waybetter/dev-tools/runtime-start-check.mjs';
|
|
import { fixtureHtml } from './theme-matrix/fixtures.mjs';
|
|
|
|
const root = fileURLToPath(new URL('../', import.meta.url));
|
|
const runtime = await readFile(join(root, 'src-tauri/x-runtime.js'), 'utf8');
|
|
// Every flag of the feature table (src/areas/table.ts): the runtime's own and the area plugins' feature modules.
|
|
const { X_TABLE } = await import(new URL('../src/areas/table.ts', import.meta.url).href);
|
|
const { tableDefaults } = await import(new URL('../../../waybetter/packages/runtime/src/featureTable.ts', import.meta.url).href);
|
|
const FEATURE_DEFAULTS = tableDefaults(X_TABLE);
|
|
|
|
const { problems, checked } = await runtimeStartCheck({
|
|
chromium,
|
|
runtime,
|
|
global: 'BetterTwttr',
|
|
label: 'wayBetter for X',
|
|
origin: 'https://x.com',
|
|
// What native code queues before the runtime exists (the host's pane and link scripts).
|
|
queued: 'window.__btPane={redundantNav:true};window.__btLinks={site:"pane"};',
|
|
featureDefaults: FEATURE_DEFAULTS,
|
|
pages: ['home', 'chat', 'profile', 'notifications'].map(cell => ({
|
|
name: cell,
|
|
path: `/${cell === 'chat' ? 'i/chat' : cell === 'profile' ? 'playfishies' : cell}`,
|
|
html: fixtureHtml(cell, 'dark'),
|
|
})),
|
|
verify: {
|
|
expression: `({ pane: document.documentElement.getAttribute('data-bt-pane-nav'), nav: !!document.querySelector('[data-testid="AppTabBar_BetterTwttr"]') })`,
|
|
check: (result, page) => (page.name !== 'chat' && result.pane !== 'hidden' ? `queued pane role not applied (${result.pane})` : null),
|
|
},
|
|
});
|
|
for (const problem of problems) console.log('FAIL', problem);
|
|
console.log(problems.length ? `\n${problems.length} problem(s)` : `\nall passed (${checked} pages)`);
|
|
process.exit(problems.length ? 1 : 0);
|