Elffuss BraidHub

utopia-ia/elffuss-code public

main · 2.0 KiBRawPermalink
1// Al arrancar sin ficheros abiertos, el editor muestra el aviso de «sin
2// ficheros» y no el documento vacío de Monaco con un «1». Al abrir un fichero
3// el aviso desaparece, y al cerrar la última pestaña vuelve.
4import { chromium } from 'playwright';
5const BASE = process.env.BASE || 'http://localhost:8799';
6let fails = 0;
7const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; };
8
9const b = await chromium.launch();
10const ctx = await b.newContext();
11await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} });
12const p = await ctx.newPage();
13p.on('pageerror', e => { console.log('❌ pageerror: ' + e.message); fails++; });
14await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' });
15
16// Esperar a que Monaco exista: si no, «no hay aviso» no prueba nada.
17const listo = await p.waitForFunction(() => !!document.querySelector('#editor .monaco-editor'), null, { timeout: 30000 }).then(() => true, () => false);
18ok('⊕ control: Monaco se ha montado', listo);
19
20const visible = () => p.evaluate(() => {
21 const el = document.getElementById('editor-empty');
22 return !!el && getComputedStyle(el).display !== 'none' && el.offsetHeight > 0;
23});
24ok('al arrancar sin ficheros se ve el aviso, no el documento en blanco', await visible());
25
26// Abrir un fichero lo quita.
27await p.evaluate(async () => {
28 const root = await navigator.storage.getDirectory();
29 const fh = await root.getFileHandle('hola.js', { create: true });
30 const w = await fh.createWritable(); await w.write('export const a = 1;\n'); await w.close();
31 const code = await import('/js/tools/code.js');
32 await code.openProject(root);
33 const ide = await import('/js/ide.js');
34 await ide.openFile('hola.js');
35});
36await p.waitForTimeout(300);
37ok('al abrir un fichero el aviso desaparece', !(await visible()));
38
39await b.close();
40console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\nTodo en verde');
41process.exit(fails ? 1 : 0);