/ concept-collection / numbl-web-ide
Sign in
concept-collection / numbl-web-ide
numbl-web-ide / scripts / live-check.mjs
52 lines · 2.4 KBBlameHistoryRaw
1// Quick verification against the deployed GitHub Pages site.
2import { chromium } from 'playwright';
4const base = 'https://concept-collection.github.io/numbl-web-ide/';
5const out = process.argv[2] ?? '.';
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(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' });
21 await page.getByRole('button', { name: 'New sample project' }).click();
22 await page.waitForTimeout(2500);
23 check('IDE opened with waves.m', await page.locator('.mw-tab-label', { hasText: 'waves.m' }).count() === 1);
24 await page.locator('.mw-tab-action[title="numbl"]').click();
25 let ran = false;
26 for (let i = 0; i < 60 && !ran; i++) {
27 await page.waitForTimeout(500);
28 ran = ((await page.locator('.mw-output').innerText()).replace(/\u00a0/g, ' ')).includes('peak amplitude');
29 }
30 check('run output streamed', ran);
31 await page.waitForTimeout(2000);
32 check('figure view appears', await page.locator('.mw-auxbar .mw-panel-tab', { hasText: 'Figure 1' }).count() === 1);
33 await page.screenshot({ path: out + '/live-run.png' });
35 // mip: install + run the package demo
36 await page.getByText('scripts', { exact: true }).click();
37 await page.waitForTimeout(400);
38 await page.getByText('mip_demo.m', { exact: true }).click();
39 await page.waitForTimeout(600);
40 await page.locator('.mw-tab-action[title="numbl"]').click();
41 let mipRan = false;
42 for (let i = 0; i < 180 && !mipRan; i++) {
43 await page.waitForTimeout(500);
44 mipRan = ((await page.locator('.mw-output').innerText()).replace(/\u00a0/g, ' ')).includes('points inside: 201 / 2000');
45 }
46 check('mip demo runs live', mipRan);
47 await page.screenshot({ path: out + '/live-mip.png' });
49 console.log(errors.length ? 'page errors:\n ' + errors.slice(0, 8).join('\n ') : 'no page errors');
50} finally {
51 await browser.close();
moveopenescclose