concept-collection / stan-web-ide
stan-web-ide / scripts / dev-check.mjs
48 lines · 2.1 KBBlameHistoryRaw
1// Quick dev-server sanity check (expects `npx vite` already running on 3000):
2// project opens, LSP diagnostics work, a full run completes if a compile
3// server is up. Not part of `npm run smoke`.
4import { chromium } from 'playwright';
6const browser = await chromium.launch({ channel: 'chrome', headless: true });
7const page = await browser.newPage({ viewport: { width: 1500, height: 900 } });
8const errors = [];
9page.on('pageerror', (e) => errors.push(e.message));
10page.on('console', (m) => { if (m.type() === 'error') errors.push(m.text()); });
11const check = (name, ok) => console.log(`${ok ? 'OK ' : 'FAIL'} ${name}`);
13try {
14 await page.goto('http://127.0.0.1:3000/', { waitUntil: 'networkidle' });
15 await page.waitForTimeout(2000);
16 await page.getByRole('button', { name: 'New sample project' }).click();
17 await page.waitForTimeout(2500);
18 check('dev: form view opens', await page.locator('.sample-editor').count() >= 1);
20 // run first (the LSP check below leaves the model file edited);
21 // probing also wakes the fly.io machine if it was auto-stopped
22 const haveServer = await fetch('https://stan-wasm-wasi.fly.dev/probe').then(r => r.ok).catch(() => false);
23 if (haveServer) {
24 await page.locator('.sample-run-button').click();
25 let done = false;
26 const start = Date.now();
27 while (Date.now() - start < 360_000 && !done) {
28 done = ((await page.locator('.mw-output').innerText()).replace(/\u00a0/g, ' ')).includes('sampling completed');
29 if (!done) await page.waitForTimeout(400);
30 }
31 check('dev: full run completes', done);
32 }
34 await page.locator('.mw-explorer-item-label').filter({ hasText: /^linear\.stan$/ }).click();
35 await page.waitForTimeout(4000);
36 await page.locator('.view-lines').first().click();
37 await page.keyboard.press('Control+End');
38 await page.keyboard.type('\nbroken');
39 let sawMarker = false;
40 for (let i = 0; i < 60 && !sawMarker; i++) {
41 await page.waitForTimeout(250);
42 sawMarker = await page.locator('.squiggly-error').count() > 0;
43 }
44 check('dev: LSP diagnostics', sawMarker);
45 console.log(errors.length ? 'page errors:\n ' + errors.slice(0, 6).join('\n ') : 'no page errors');
46} finally {
47 await browser.close();