concept-collection / stan-web-ide
Add live-site check script
Jeremy Magland <jmagland@flatironinstitute.org> committed commit 69482822f9f8 parent 21efcb6 Browse files
1 changed file+48−0
scripts/live-check.mjsadded+48−0View file
@@ -0,0 +1,48 @@
1+// Quick verification against the deployed GitHub Pages site.
2+import { chromium } from 'playwright';
3+
4+const base = 'https://concept-collection.github.io/stan-web-ide/';
5+const out = process.argv[2] ?? '.';
6+const browser = await chromium.launch({ channel: 'chrome', headless: true });
7+const page = await browser.newPage({ viewport: { width: 1500, height: 900 } });
8+const errors = [];
9+page.on('pageerror', (e) => errors.push(e.message));
10+page.on('console', (m) => { if (m.type() === 'error') errors.push(m.text()); });
11+const check = (name, ok) => console.log(`${ok ? 'OK ' : 'FAIL'} ${name}`);
12+
13+try {
14+ await page.goto(base, { waitUntil: 'networkidle' });
15+ // the coi-serviceworker registers and reloads once on first visit
16+ await page.waitForTimeout(3500);
17+ check('cross-origin isolated', await page.evaluate(() => window.crossOriginIsolated));
18+ check('landing renders', await page.locator('.landing-header').count() === 1);
19+ await page.screenshot({ path: out + '/live-landing.png' });
20+
21+ await page.getByRole('button', { name: 'New sample project' }).click();
22+ await page.waitForTimeout(2500);
23+ check('fit.sample opens as form', await page.locator('.sample-editor h2', { hasText: 'fit.sample' }).count() === 1);
24+ check('form: stan file selected', await page.locator('.sample-editor select').first().inputValue() === 'linear.stan');
25+
26+ // Stan LSP diagnostics on the live bundle
27+ await page.locator('.mw-explorer-item-label').filter({ hasText: /^linear\.stan$/ }).click();
28+ await page.waitForTimeout(3000);
29+ await page.locator('.view-lines').first().click();
30+ await page.keyboard.press('Control+End');
31+ await page.keyboard.type('\nbroken');
32+ let sawMarker = false;
33+ for (let i = 0; i < 60 && !sawMarker; i++) {
34+ await page.waitForTimeout(250);
35+ sawMarker = await page.locator('.squiggly-error').count() > 0;
36+ }
37+ check('LSP diagnostics live', sawMarker);
38+ await page.screenshot({ path: out + '/live-ide.png' });
39+
40+ // the status bar should show the compile server as offline (localhost
41+ // default doesn't apply to the Pages origin)
42+ const statusText = (await page.locator('.mw-statusbar').innerText()).replace(/\u00a0/g, ' ');
43+ check('server status item present', statusText.includes('Stan server:'));
44+
45+ console.log(errors.length ? 'page errors:\n ' + errors.slice(0, 8).join('\n ') : 'no page errors');
46+} finally {
47+ await browser.close();
48+}