| 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. |
| 4 | import { chromium } from 'playwright'; |
| 5 | const BASE = process.env.BASE || 'http://localhost:8799'; |
| 6 | let fails = 0; |
| 7 | const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; }; |
| 8 | |
| 9 | const b = await chromium.launch(); |
| 10 | const ctx = await b.newContext(); |
| 11 | await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} }); |
| 12 | const p = await ctx.newPage(); |
| 13 | p.on('pageerror', e => { console.log('❌ pageerror: ' + e.message); fails++; }); |
| 14 | await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); |
| 15 | |
| 16 | // Esperar a que Monaco exista: si no, «no hay aviso» no prueba nada. |
| 17 | const listo = await p.waitForFunction(() => !!document.querySelector('#editor .monaco-editor'), null, { timeout: 30000 }).then(() => true, () => false); |
| 18 | ok('⊕ control: Monaco se ha montado', listo); |
| 19 | |
| 20 | const visible = () => p.evaluate(() => { |
| 21 | const el = document.getElementById('editor-empty'); |
| 22 | return !!el && getComputedStyle(el).display !== 'none' && el.offsetHeight > 0; |
| 23 | }); |
| 24 | ok('al arrancar sin ficheros se ve el aviso, no el documento en blanco', await visible()); |
| 25 | |
| 26 | // Abrir un fichero lo quita. |
| 27 | await 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 | }); |
| 36 | await p.waitForTimeout(300); |
| 37 | ok('al abrir un fichero el aviso desaparece', !(await visible())); |
| 38 | |
| 39 | await b.close(); |
| 40 | console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\nTodo en verde'); |
| 41 | process.exit(fails ? 1 : 0); |