utopia-ia/elffuss-code public
Changesets · Branches · Tags · Compare
| Changeset | 901cc036b9a2612d21e7d932740fe57dbe87841a74dee2d905ca56d757d0f5f7 |
|---|---|
| Author | KikoCis <kikocisneros@gmail.com> · 2026-10-12 11:45 +02:00 |
| Committer | KikoCis <kikocisneros@gmail.com> · 2026-10-12 11:45 +02:00 |
| Parents | aae34830ffe7 |
4 files changed
added tests/ext_feedback.mjs +237 −0
| @@ -0,0 +1,237 @@ | ||
| 1 | +// Extensions: what the user SEES after installing one, and what is offered | |
| 2 | +// before. Level 1 only applies themes, grammars, snippets and language | |
| 3 | +// settings; an install that changes nothing visible felt pointless. | |
| 4 | +// | |
| 5 | +// BASE=http://localhost:8999 node tests/ext_feedback.mjs | |
| 6 | +// | |
| 7 | +// Fixtures are built in ext_fixtures.mjs and Open VSX is mocked with routes, | |
| 8 | +// so it runs offline. The LIVE part at the end installs real extensions from | |
| 9 | +// Open VSX; without network it is NOT RUN and does not count as a failure. | |
| 10 | +import { chromium } from 'playwright'; | |
| 11 | +import { pureThemeVsix, PURE_DARK, partialLangVsix, TOMLISH, jsSnippetsVsix, codeOnlyVsix } from './ext_fixtures.mjs'; | |
| 12 | + | |
| 13 | +const BASE = process.env.BASE || 'http://localhost:8999'; | |
| 14 | +const OUT = process.env.SCRATCH || '/tmp/elffuss-test'; | |
| 15 | +let fails = 0; | |
| 16 | +const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; }; | |
| 17 | +const notRun = (n, e) => console.log('⏭️ NOT RUN ' + n + (e ? ' — ' + e : '')); | |
| 18 | +const sleep = ms => new Promise(r => setTimeout(r, ms)); | |
| 19 | +const rgb = hex => { const h = hex.replace('#', ''); return `rgb(${parseInt(h.slice(0, 2), 16)}, ${parseInt(h.slice(2, 4), 16)}, ${parseInt(h.slice(4, 6), 16)})`; }; | |
| 20 | +async function hasta(fn, { tiempo = 12000, cada = 150 } = {}) { | |
| 21 | + const fin = Date.now() + tiempo; | |
| 22 | + let v; | |
| 23 | + while (Date.now() < fin) { try { v = await fn(); if (v) return v; } catch { /* retry */ } await sleep(cada); } | |
| 24 | + return v; | |
| 25 | +} | |
| 26 | +// internal words a user should never read in the panel | |
| 27 | +const JERGA = /contributes|customEditors|extension host|host de extensiones|main\/browser|activationEvents/i; | |
| 28 | + | |
| 29 | +const b = await chromium.launch(); | |
| 30 | + | |
| 31 | +async function nuevaPagina(locale, viewport = { width: 1280, height: 860 }) { | |
| 32 | + const ctx = await b.newContext({ locale, viewport }); | |
| 33 | + await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} }); | |
| 34 | + const p = await ctx.newPage(); | |
| 35 | + p.errores = []; | |
| 36 | + p.on('pageerror', e => { if (e.message !== 'Canceled') p.errores.push(e.message); }); | |
| 37 | + await p.goto(BASE + '/', { waitUntil: 'domcontentloaded' }); | |
| 38 | + await p.evaluate(async () => { | |
| 39 | + const o = await navigator.storage.getDirectory(); | |
| 40 | + for await (const k of o.keys()) await o.removeEntry(k, { recursive: true }).catch(() => {}); | |
| 41 | + const w = async (n, t) => { const f = await o.getFileHandle(n, { create: true }); const s = await f.createWritable(); await s.write(t); await s.close(); }; | |
| 42 | + await w('app.js', '// app\nconst a = 1;\n'); | |
| 43 | + await w('data.tomlish', 'name = "x"\n# note\n'); | |
| 44 | + }); | |
| 45 | + await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); | |
| 46 | + await hasta(() => p.evaluate(() => !!window.monaco?.editor?.getEditors?.().length), { tiempo: 30000 }); | |
| 47 | + return { ctx, p }; | |
| 48 | +} | |
| 49 | +const pulsa = (p, sel) => p.click(sel, { timeout: 3000 }).catch(() => {}); | |
| 50 | +const abre = (p, path) => p.evaluate(async path => { await (await import('/js/ide.js')).openFile(path); }, path); | |
| 51 | +const fondo = p => p.evaluate(() => getComputedStyle(document.querySelector('#editor .monaco-editor-background') || document.querySelector('#editor .monaco-editor')).backgroundColor); | |
| 52 | +const abrePanel = async p => { if (!(await p.locator('#ext-panel').isVisible().catch(() => false))) { await p.click('#act-ext'); await p.waitForSelector('#ext-panel', { timeout: 10000 }); } }; | |
| 53 | +const instalaFichero = async (p, nombre, bytes) => { | |
| 54 | + await abrePanel(p); | |
| 55 | + await p.evaluate(() => { const m = document.getElementById('ext-msg'); if (m) { m.hidden = true; m.textContent = ''; } document.getElementById('ext-done')?.remove(); }); | |
| 56 | + await p.setInputFiles('#ext-file', { name: nombre, mimeType: 'application/octet-stream', buffer: Buffer.from(bytes) }); | |
| 57 | + return hasta(() => p.evaluate(() => { const m = document.getElementById('ext-msg'); return m && !m.hidden && m.textContent; }), { tiempo: 15000 }); | |
| 58 | +}; | |
| 59 | +const tarjeta = p => p.evaluate(() => document.getElementById('ext-done')?.innerText.replace(/\s+/g, ' ') || ''); | |
| 60 | +const fila = (p, id) => p.locator(`#ext-installed .ext-row[data-id="${id}"]`); | |
| 61 | + | |
| 62 | +// ── 1. Theme-only extension: applied on install, with Undo and the picker ── | |
| 63 | +{ | |
| 64 | + const { p } = await nuevaPagina('en-US'); | |
| 65 | + await abre(p, 'app.js'); | |
| 66 | + await instalaFichero(p, 'pure.vsix', pureThemeVsix()); | |
| 67 | + ok('theme: the first theme is applied on install (editor background)', await hasta(async () => (await fondo(p)) === rgb(PURE_DARK)), await fondo(p)); | |
| 68 | + const t = await tarjeta(p); | |
| 69 | + ok('theme: the notice names the theme and says it is applied', /Pure Night/.test(t) && /applied/i.test(t), t); | |
| 70 | + ok('theme: Undo and Choose theme… buttons', await p.locator('#ext-done button[data-act="undo-theme"]').count() === 1 && await p.locator('#ext-done button[data-act="pick-theme"]').count() === 1); | |
| 71 | + await pulsa(p, '#ext-done button[data-act="undo-theme"]'); | |
| 72 | + ok('theme: Undo restores the previous theme', await hasta(async () => (await fondo(p)) === 'rgb(30, 30, 30)'), await fondo(p)); | |
| 73 | + ok('theme: after Undo, an Apply now button', await hasta(() => p.locator('#ext-done button[data-act="apply-theme"]').count())); | |
| 74 | + await pulsa(p, '#ext-done button[data-act="apply-theme"]'); | |
| 75 | + ok('theme: Apply now applies it', await hasta(async () => (await fondo(p)) === rgb(PURE_DARK)), await fondo(p)); | |
| 76 | + await pulsa(p, '#ext-done button[data-act="pick-theme"]'); | |
| 77 | + ok('theme: Choose theme… opens the Color Theme picker', await hasta(() => p.locator('#ext-themepick').count())); | |
| 78 | + await p.keyboard.press('Escape'); | |
| 79 | + const now = (await fila(p, 'elffuss-test.pure-theme').locator('.ext-now').innerText().catch(() => '')).replace(/\s+/g, ' '); | |
| 80 | + ok('installed list: says which theme is active right now', /Active theme/i.test(now) && /Pure Night/.test(now), now); | |
| 81 | + await p.screenshot({ path: OUT + '/extfb-theme.png' }); | |
| 82 | + | |
| 83 | + // ── 2. Language with grammar + settings + code: open file highlighted at once ── | |
| 84 | + await abre(p, 'data.tomlish'); | |
| 85 | + ok('language: before installing, the file is plain text', (await p.evaluate(() => window.monaco.editor.getEditors()[0].getModel().getLanguageId())) === 'plaintext'); | |
| 86 | + await instalaFichero(p, 'tomlish.vsix', partialLangVsix()); | |
| 87 | + ok('language: the open file switches to the new language', await hasta(() => p.evaluate(() => window.monaco.editor.getEditors()[0].getModel().getLanguageId() === 'tomlish'))); | |
| 88 | + const tipos = await hasta(async () => { const x = await p.evaluate(() => window.monaco.editor.tokenize('name = 1', 'tomlish').flat().map(t => t.type)); return x.some(t => /variable\.other\.key/.test(t)) && x; }); | |
| 89 | + ok('language: the grammar tokenizes', !!tipos, JSON.stringify(tipos)); | |
| 90 | + const t2 = await tarjeta(p); | |
| 91 | + ok('language: notice says highlighting for Tomlish (.tomlish)', /Tomlish/.test(t2) && /\.tomlish/.test(t2) && /highlight/i.test(t2), t2); | |
| 92 | + ok('language: notice says the open file is already highlighted, with a button to go there', /data\.tomlish/.test(t2) && await p.locator('#ext-done button[data-act="goto"]').count() >= 1, t2); | |
| 93 | + ok('language: notice says what the settings change (comment with #, brackets)', /#/.test(t2) && /\[\s?\]/.test(t2), t2); | |
| 94 | + ok('language: notice says what does not work, in plain words, and that it comes with the next version', /format/i.test(t2) && /next version/i.test(t2) && !JERGA.test(t2), t2); | |
| 95 | + const now2 = (await fila(p, 'elffuss-test.tomlish').locator('.ext-now').innerText().catch(() => '')).replace(/\s+/g, ' '); | |
| 96 | + ok('installed list: «Highlighting 1 open file»', /Highlighting 1 open file/i.test(now2), now2); | |
| 97 | + await p.screenshot({ path: OUT + '/extfb-lang.png' }); | |
| 98 | + | |
| 99 | + // ── 3. Snippets: count, languages and prefixes to try ── | |
| 100 | + await instalaFichero(p, 'snips.vsix', jsSnippetsVsix()); | |
| 101 | + const t3 = await tarjeta(p); | |
| 102 | + ok('snippets: «4 snippets for JavaScript and TypeScript»', /4 snippets/.test(t3) && /JavaScript/.test(t3) && /TypeScript/.test(t3), t3); | |
| 103 | + ok('snippets: shows prefixes to type (clg, imp…) and how to accept', /clg/.test(t3) && /imp/.test(t3) && /Tab/.test(t3), t3); | |
| 104 | + const now3 = (await fila(p, 'elffuss-test.js-snips').locator('.ext-now').innerText().catch(() => '')).replace(/\s+/g, ' '); | |
| 105 | + ok('installed list: «4 snippets» with a link to try them', /4 snippets/.test(now3) && await fila(p, 'elffuss-test.js-snips').locator('button[data-act="try-snippet"]').count() === 1, now3); | |
| 106 | + await pulsa(p, '#ext-done button[data-act="try-snippet"]'); | |
| 107 | + ok('snippets: Try opens a JavaScript file and puts the cursor in the editor', await hasta(() => p.evaluate(() => { | |
| 108 | + const ed = window.monaco.editor.getEditors()[0]; | |
| 109 | + return document.getElementById('settings-panel').hidden && ed.getModel().getLanguageId() === 'javascript' && ed.hasTextFocus(); | |
| 110 | + }))); | |
| 111 | + | |
| 112 | + // ── 4. Code-only .vsix: not installed, said plainly ── | |
| 113 | + const m4 = await instalaFichero(p, 'previewer.vsix', codeOnlyVsix()); | |
| 114 | + ok('code-only: not installed', await fila(p, 'elffuss-test.previewer').count() === 0, m4); | |
| 115 | + ok('code-only: says its main feature needs its own code, in plain words', /own code/i.test(m4 || '') && !JERGA.test(m4 || ''), m4); | |
| 116 | + ok('code-only (custom editors): does not promise the next version', !/next version/i.test(m4 || ''), m4); | |
| 117 | + | |
| 118 | + // ── 5. Plain language everywhere in the panel ── | |
| 119 | + const todo = await p.evaluate(() => document.getElementById('ext-panel').innerText); | |
| 120 | + ok('panel text: no internal terms (contributes, customEditors, main/browser…)', !JERGA.test(todo), (todo.match(JERGA) || [''])[0]); | |
| 121 | + ok('no page errors', !p.errores.length, p.errores.slice(0, 3).join(' | ')); | |
| 122 | + await p.context().close(); | |
| 123 | +} | |
| 124 | + | |
| 125 | +// ── 6. Search results (Open VSX mocked): verdict before installing ── | |
| 126 | +{ | |
| 127 | + const { ctx, p } = await nuevaPagina('en-US'); | |
| 128 | + const manifests = { | |
| 129 | + 'elffuss-test/previewer': { publisher: 'elffuss-test', name: 'previewer', version: '1.0.0', displayName: 'Rich Previewer', description: 'LaTeX, STL and video preview with right-click copy', categories: ['Visualization', 'Other'], main: './dist/extension.js', | |
| 130 | + contributes: { languages: [{ id: 'csv', aliases: ['CSV'], extensions: ['.csv'] }, { id: 'tsv', extensions: ['.tsv'] }], commands: [{}], menus: {}, customEditors: [{}], configuration: {} } }, | |
| 131 | + 'elffuss-test/tomlish': { publisher: 'elffuss-test', name: 'tomlish', version: '1.0.0', displayName: 'Tomlish Support', categories: ['Programming Languages', 'Formatters'], main: './x.js', browser: './b.js', | |
| 132 | + contributes: { languages: [{ id: 'tomlish', aliases: ['Tomlish'], extensions: ['.tomlish'], configuration: './c.json' }], grammars: [{ language: 'tomlish', scopeName: 'source.tomlish', path: './g.json' }], commands: [{}] } }, | |
| 133 | + 'elffuss-test/heavy': { publisher: 'elffuss-test', name: 'heavy', version: '1.0.0', displayName: 'Heavy Workshop', categories: ['Programming Languages', 'Linters'], main: './x.js', | |
| 134 | + contributes: { languages: [{ id: 'heavy', aliases: ['Heavy'], extensions: ['.hv'], configuration: './c.json' }], grammars: [{ language: 'heavy', scopeName: 'source.hv', path: './g.json' }], commands: new Array(12).fill({}), views: { x: [{ type: 'webview' }] }, customEditors: [{}] } }, | |
| 135 | + 'elffuss-test/pure-theme': { publisher: 'elffuss-test', name: 'pure-theme', version: '1.0.0', displayName: 'Pure Theme', categories: ['Themes'], contributes: { themes: [{ label: 'Pure Night', path: './n.json' }, { label: 'Pure Dusk', path: './d.json' }] } }, | |
| 136 | + }; | |
| 137 | + const descargas = []; | |
| 138 | + await ctx.route('https://open-vsx.org/**', route => { | |
| 139 | + const u = new URL(route.request().url()); | |
| 140 | + const json = o => route.fulfill({ status: 200, contentType: 'application/json', headers: { 'access-control-allow-origin': '*' }, body: JSON.stringify(o) }); | |
| 141 | + if (u.pathname === '/api/-/search') { | |
| 142 | + return json({ totalSize: 4, offset: 0, extensions: Object.values(manifests).map(m => ({ namespace: m.publisher, name: m.name, version: m.version, displayName: m.displayName, description: m.description || '', downloadCount: 10 })) }); | |
| 143 | + } | |
| 144 | + const mm = /^\/api\/([^/]+)\/([^/]+)\/([^/]+)\/file\/package\.json$/.exec(u.pathname); | |
| 145 | + if (mm) return json(manifests[`${mm[1]}/${mm[2]}`]); | |
| 146 | + const md = /^\/api\/([^/]+)\/([^/]+)(?:\/([^/]+))?$/.exec(u.pathname); | |
| 147 | + if (md && manifests[`${md[1]}/${md[2]}`]) { | |
| 148 | + const m = manifests[`${md[1]}/${md[2]}`]; | |
| 149 | + return json({ namespace: m.publisher, name: m.name, version: m.version, displayName: m.displayName, license: 'MIT', files: { manifest: `https://open-vsx.org/api/${m.publisher}/${m.name}/${m.version}/file/package.json`, download: `https://open-vsx.org/api/${m.publisher}/${m.name}/${m.version}/file/x.vsix` } }); | |
| 150 | + } | |
| 151 | + descargas.push(u.pathname); | |
| 152 | + return route.fulfill({ status: 404, body: '' }); | |
| 153 | + }); | |
| 154 | + await abrePanel(p); | |
| 155 | + await p.fill('#ext-q', 'anything'); | |
| 156 | + await p.press('#ext-q', 'Enter'); | |
| 157 | + const r = id => p.locator(`#ext-results .ext-row[data-id="${id}"]`); | |
| 158 | + await r('elffuss-test.pure-theme').waitFor({ timeout: 10000 }).catch(() => {}); | |
| 159 | + const listo = await hasta(() => p.evaluate(() => document.querySelectorAll('#ext-results .ext-verdict').length >= 4)); | |
| 160 | + ok('results: every row gets a verdict before installing', !!listo); | |
| 161 | + const v = async id => (await r(id).locator('.ext-verdict').innerText().catch(() => '')).replace(/\s+/g, ' '); | |
| 162 | + const btn = id => r(id).locator('.ext-install'); | |
| 163 | + const vPrev = await v('elffuss-test.previewer'); | |
| 164 | + ok('code-only: «The main thing … does not work in Code: it needs to run its own code»', /main/i.test(vPrev) && /does not work in Code/i.test(vPrev) && /own code/i.test(vPrev), vPrev); | |
| 165 | + ok('code-only: Install is disabled and labelled so', (await btn('elffuss-test.previewer').getAttribute('aria-disabled')) === 'true' && !/^Install$/.test((await btn('elffuss-test.previewer').innerText()).trim()), await btn('elffuss-test.previewer').innerText()); | |
| 166 | + ok('code-only with custom editors: no «next version» promise', !/next version/i.test(vPrev), vPrev); | |
| 167 | + await btn('elffuss-test.previewer').click({ timeout: 3000 }).catch(() => {}); | |
| 168 | + await sleep(400); | |
| 169 | + ok('code-only: clicking it downloads nothing', !descargas.some(x => /previewer/.test(x)), descargas.join(' ')); | |
| 170 | + const vToml = await v('elffuss-test.tomlish'); | |
| 171 | + ok('partial: «Partly works» naming the language, and the missing part in plain words', /Tomlish/.test(vToml) && /format/i.test(vToml) && /next version/i.test(vToml) && !JERGA.test(vToml), vToml); | |
| 172 | + ok('partial: the button says what you get («Install only the highlighting»)', /only the highlighting/i.test(await btn('elffuss-test.tomlish').innerText()), await btn('elffuss-test.tomlish').innerText()); | |
| 173 | + const vHeavy = await v('elffuss-test.heavy'); | |
| 174 | + ok('mostly code: leads with the main feature not working, then «Only … would apply: highlighting for Heavy»', /does not work in Code/i.test(vHeavy) && /Only/.test(vHeavy) && /Heavy/.test(vHeavy), vHeavy); | |
| 175 | + ok('mostly code: install is a secondary button', /ghost/.test(await btn('elffuss-test.heavy').getAttribute('class')) && /only/i.test(await btn('elffuss-test.heavy').innerText())); | |
| 176 | + const vPure = await v('elffuss-test.pure-theme'); | |
| 177 | + ok('declarative: plain Install and the theme names', (await btn('elffuss-test.pure-theme').innerText()).trim() === 'Install' && /Pure Night/.test(vPure), vPure); | |
| 178 | + await r('elffuss-test.previewer').locator('.ext-name').click({ timeout: 3000 }).catch(() => {}); | |
| 179 | + const det = await hasta(async () => { const x = await r('elffuss-test.previewer').locator('.ext-detail').innerText({ timeout: 2000 }); return !/Reading/.test(x) && x; }); | |
| 180 | + ok('details: plain language, no raw contribution names', !!det && !JERGA.test(det) && !/commands|menus|configuration/.test(det), det); | |
| 181 | + const todo = await p.evaluate(() => document.getElementById('ext-panel').innerText); | |
| 182 | + ok('results panel: no internal terms', !JERGA.test(todo), (todo.match(JERGA) || [''])[0]); | |
| 183 | + await p.screenshot({ path: OUT + '/extfb-results.png' }); | |
| 184 | + // keyboard: the disabled button still takes focus and is announced as such | |
| 185 | + await btn('elffuss-test.previewer').focus({ timeout: 3000 }).catch(() => {}); | |
| 186 | + const nombre = await btn('elffuss-test.previewer').evaluate(b => (b.getAttribute('aria-label') || b.textContent) + ' | ' + (b.getAttribute('aria-describedby') ? document.getElementById(b.getAttribute('aria-describedby'))?.textContent : '')); | |
| 187 | + ok('a11y: the disabled button is focusable and its reason is linked (aria-describedby)', /does not work/i.test(nombre), nombre); | |
| 188 | + await ctx.close(); | |
| 189 | +} | |
| 190 | + | |
| 191 | +// ── 7. Spanish + phone width ── | |
| 192 | +{ | |
| 193 | + const { p } = await nuevaPagina('es-ES'); | |
| 194 | + await abrePanel(p); // the activity bar is in the drawer on a phone | |
| 195 | + await p.setViewportSize({ width: 390, height: 800 }); | |
| 196 | + await instalaFichero(p, 'pure.vsix', pureThemeVsix()); | |
| 197 | + const t = await tarjeta(p); | |
| 198 | + ok('es: «Tema «Pure Night» aplicado»', /Tema «Pure Night» aplicado/.test(t), t); | |
| 199 | + ok('es: botones Deshacer y Elegir tema…', /Deshacer/.test(t) && /Elegir tema/.test(t), t); | |
| 200 | + const ancho = await p.evaluate(() => { const x = document.getElementById('ext-panel'); return [x.scrollWidth, x.clientWidth, document.documentElement.scrollWidth, innerWidth]; }); | |
| 201 | + ok('phone width: no horizontal overflow', ancho[0] <= ancho[1] + 1 && ancho[2] <= ancho[3] + 1, ancho.join(',')); | |
| 202 | + const fuera = await p.evaluate(() => [...document.querySelectorAll('#ext-done button')].filter(b => { const r = b.getBoundingClientRect(); return r.right > innerWidth + 1 || r.left < -1; }).length); | |
| 203 | + ok('phone width: notice buttons fit on screen', fuera === 0, String(fuera)); | |
| 204 | + await p.screenshot({ path: OUT + '/extfb-phone-es.png' }); | |
| 205 | + const todo = await p.evaluate(() => document.getElementById('ext-panel').innerText); | |
| 206 | + ok('es: sin términos internos', !JERGA.test(todo), (todo.match(JERGA) || [''])[0]); | |
| 207 | + await p.context().close(); | |
| 208 | +} | |
| 209 | + | |
| 210 | +// ── LIVE: real Open VSX ── | |
| 211 | +{ | |
| 212 | + const vivo = await fetch('https://open-vsx.org/api/esbenp/prettier-vscode', { signal: AbortSignal.timeout(8000) }).then(r => r.ok).catch(() => false); | |
| 213 | + if (!vivo) notRun('live Open VSX', 'no network'); | |
| 214 | + else { | |
| 215 | + const { p } = await nuevaPagina('en-US'); | |
| 216 | + await abrePanel(p); | |
| 217 | + await p.fill('#ext-q', 'prettier'); | |
| 218 | + await p.press('#ext-q', 'Enter'); | |
| 219 | + const row = p.locator('#ext-results .ext-row[data-id="esbenp.prettier-vscode"]'); | |
| 220 | + await row.waitFor({ timeout: 20000 }).catch(() => {}); | |
| 221 | + const dis = await hasta(async () => (await row.locator('.ext-install').getAttribute('aria-disabled')) === 'true', { tiempo: 20000 }); | |
| 222 | + ok('live: Prettier is not offered as a plain Install', !!dis, await row.innerText().catch(() => '')); | |
| 223 | + await p.fill('#ext-q', 'dracula'); | |
| 224 | + await p.press('#ext-q', 'Enter'); | |
| 225 | + const d = p.locator('#ext-results .ext-row[data-id="dracula-theme.theme-dracula"]'); | |
| 226 | + await d.waitFor({ timeout: 20000 }).catch(() => {}); | |
| 227 | + await d.locator('.ext-install').click().catch(() => {}); | |
| 228 | + ok('live: Dracula applied on install', await hasta(async () => (await fondo(p)) === 'rgb(40, 42, 54)', { tiempo: 40000 }), await fondo(p)); | |
| 229 | + await p.screenshot({ path: OUT + '/extfb-live-dracula.png' }); | |
| 230 | + ok('live: no page errors', !p.errores.length, p.errores.slice(0, 3).join(' | ')); | |
| 231 | + await p.context().close(); | |
| 232 | + } | |
| 233 | +} | |
| 234 | + | |
| 235 | +console.log(fails ? `\n❌ ${fails} FAILURE(S)` : '\n✅ EXTENSIONS: VISIBLE EFFECT AFTER INSTALL OK'); | |
| 236 | +await b.close(); | |
| 237 | +process.exit(fails ? 1 : 0); |
modified tests/ext_fixtures.mjs +52 −0
| @@ -299,3 +299,55 @@ | ||
| 299 | 299 | }, |
| 300 | 300 | }, [['extension/conf.json', JSON.stringify({ wordPattern: '(a+)+$', brackets: [['(', ')']] })]]); |
| 301 | 301 | } |
| 302 | + | |
| 303 | +// ── lo que se ve al instalar (ext_feedback.mjs) ────────────────────────────── | |
| 304 | +// Solo código: vistas previas propias, comandos, menús y dos lenguajes SIN | |
| 305 | +// gramática ni configuración (como una extensión real de vista previa). Aquí no | |
| 306 | +// aporta nada visible: no se ofrece instalarla. | |
| 307 | +export function codeOnlyVsix() { | |
| 308 | + return paquete({ | |
| 309 | + name: 'previewer', displayName: 'Rich Previewer', description: 'LaTeX, STL and video preview with right-click copy', | |
| 310 | + categories: ['Visualization', 'Other'], main: './dist/extension.js', | |
| 311 | + contributes: { | |
| 312 | + languages: [{ id: 'csv', aliases: ['CSV'], extensions: ['.csv'] }, { id: 'tsv', aliases: ['TSV'], extensions: ['.tsv'] }], | |
| 313 | + commands: [{ command: 'pv.copy', title: 'Copy' }], menus: { 'editor/context': [] }, | |
| 314 | + customEditors: [{ viewType: 'pv.stl', displayName: 'STL', selector: [{ filenamePattern: '*.stl' }] }], | |
| 315 | + configuration: { properties: {} }, | |
| 316 | + }, | |
| 317 | + }, [['extension/dist/extension.js', 'throw new Error("must never run")', { method: 99 }]]); | |
| 318 | +} | |
| 319 | +// Resaltado + configuración de un lenguaje nuevo, y además código para el | |
| 320 | +// navegador (formatear, comandos): funciona en parte. | |
| 321 | +export const TOMLISH = { lang: 'tomlish', ext: '.tomlish', scope: 'source.tomlish', key: '#E06C75' }; | |
| 322 | +export function partialLangVsix() { | |
| 323 | + const g = { scopeName: TOMLISH.scope, patterns: [{ match: '^\\s*[a-z]+(?=\\s*=)', name: 'variable.other.key.tomlish' }, { match: '#.*$', name: 'comment.line.tomlish' }] }; | |
| 324 | + return paquete({ | |
| 325 | + name: 'tomlish', displayName: 'Tomlish Support', description: 'Fully-featured Tomlish support', | |
| 326 | + categories: ['Programming Languages', 'Formatters'], main: './dist/extension.js', browser: './dist/browser.js', | |
| 327 | + contributes: { | |
| 328 | + languages: [{ id: TOMLISH.lang, aliases: ['Tomlish'], extensions: [TOMLISH.ext], configuration: './conf.json' }], | |
| 329 | + grammars: [{ language: TOMLISH.lang, scopeName: TOMLISH.scope, path: './g.json' }], | |
| 330 | + commands: [{ command: 't.fmt', title: 'Format' }], configuration: { properties: {} }, | |
| 331 | + }, | |
| 332 | + }, [['extension/g.json', JSON.stringify(g)], ['extension/conf.json', JSON.stringify({ comments: { lineComment: '#' }, brackets: [['[', ']'], ['{', '}']], autoClosingPairs: [{ open: '[', close: ']' }, { open: '"', close: '"' }] })], | |
| 333 | + ['extension/dist/extension.js', 'throw new Error("must never run")', { method: 99 }]]); | |
| 334 | +} | |
| 335 | +// Solo temas, sin código. | |
| 336 | +export const PURE_DARK = '#2A1B3D'; | |
| 337 | +export function pureThemeVsix() { | |
| 338 | + const t = bg => JSON.stringify({ colors: { 'editor.background': bg, 'editor.foreground': '#F8F8F2' }, tokenColors: [{ scope: 'keyword', settings: { foreground: '#FF79C6' } }] }); | |
| 339 | + return paquete({ name: 'pure-theme', displayName: 'Pure Theme', categories: ['Themes'], contributes: { themes: [ | |
| 340 | + { label: 'Pure Night', uiTheme: 'vs-dark', path: './night.json' }, { label: 'Pure Dusk', uiTheme: 'vs-dark', path: './dusk.json' }, | |
| 341 | + ] } }, [['extension/night.json', t(PURE_DARK)], ['extension/dusk.json', t('#3A2B4D')]]); | |
| 342 | +} | |
| 343 | +// Snippets para JavaScript, sin código. | |
| 344 | +export function jsSnippetsVsix() { | |
| 345 | + const s = { | |
| 346 | + 'Console log': { prefix: 'clg', body: 'console.log($1);' }, | |
| 347 | + 'Import': { prefix: 'imp', body: "import $1 from '$2';" }, | |
| 348 | + 'Arrow': { prefix: 'fn', body: 'const $1 = ($2) => {$0};' }, | |
| 349 | + 'Group': { Inner: { prefix: 'thr', body: 'throw new Error($1);' } }, | |
| 350 | + }; | |
| 351 | + return paquete({ name: 'js-snips', displayName: 'JS Snips', categories: ['Snippets'], contributes: { snippets: [{ language: 'javascript', path: './s.json' }, { language: 'typescript', path: './s.json' }] } }, | |
| 352 | + [['extension/s.json', JSON.stringify(s)]]); | |
| 353 | +} |
modified tests/ext_unit.mjs +27 −0
| @@ -13,6 +13,7 @@ | ||
| 13 | 13 | import { sanitizeGrammar } from '../web/js/ext/grammars.js'; |
| 14 | 14 | import { textoError, textoAviso } from '../web/js/ext/panel.js'; |
| 15 | 15 | import { STRINGS } from '../web/js/ext/i18n.js'; |
| 16 | +import { describe as veredicto } from '../web/js/ext/verdict.js'; | |
| 16 | 17 | import tm from '../web/js/ext/vendor/vscode-textmate@9.3.2/main.js'; |
| 17 | 18 | import { zip, themeVsix, elfscriptVsix, THEME_DARK, ELFS, EVIL_GRAMMAR, brokenThemeVsix, noPublisherVsix, slowRegexVsix, SLOW } from './ext_fixtures.mjs'; |
| 18 | 19 | |
| @@ -290,5 +291,31 @@ | ||
| 290 | 291 | ok('textos del panel: ES y EN con las mismas claves', !faltan('es').length, faltan('es').join(' ')); |
| 291 | 292 | } |
| 292 | 293 | |
| 294 | +// ── veredicto en llano (verdict.js) y textos sin jerga ── | |
| 295 | +{ | |
| 296 | + const JERGA = /contributes|customEditors|extension host|host de extensiones|main\/browser|activationEvents|\bMonaco\b/i; | |
| 297 | + const malos = Object.entries(STRINGS).flatMap(([l, t]) => Object.entries(t).filter(([, v]) => JERGA.test(v)).map(([k]) => `${l}.${k}`)); | |
| 298 | + ok('textos del panel: ningún término interno (contributes, customEditors, main/browser, host…)', !malos.length, malos.join(' ')); | |
| 299 | + // como la extensión real de vista previa: código + editores propios + 2 lenguajes sin colores | |
| 300 | + const prev = veredicto({ hasCode: true, browserEntry: false, categories: ['Visualization', 'Other'], sizes: { languages: 2, commands: 9, customEditors: 8, menus: 3, configuration: 2 }, | |
| 301 | + ignored: [{ key: 'commands' }, { key: 'customEditors' }, { key: 'menus' }, { key: 'configuration' }], themes: [], highlight: [], settingsOnly: [], snippets: [] }); | |
| 302 | + ok('veredicto: solo código → no se ofrece instalar, y sin prometer «la siguiente versión» (editores propios)', prev.kind === 'code' && prev.button.disabled && prev.future === 'never' && !/next version/i.test(prev.verdict + prev.lines.join(' ')), JSON.stringify(prev)); | |
| 303 | + ok('veredicto: dice lo principal en llano («its own previews»)', /its own previews/.test(prev.verdict) && !JERGA.test(prev.verdict + prev.lines.join(' ')), prev.verdict); | |
| 304 | + const fmt = veredicto({ hasCode: true, browserEntry: true, categories: ['Formatters'], sizes: { commands: 2, configuration: 3 }, ignored: [{ key: 'commands' }, { key: 'configuration' }, { key: 'jsonValidation' }], themes: [], highlight: [], settingsOnly: [], snippets: [] }); | |
| 305 | + ok('veredicto: formateador con código para el navegador → «llegará con la siguiente versión»', fmt.kind === 'code' && fmt.future === 'next' && /formatting code/.test(fmt.verdict) && /next version/.test(fmt.lines.join(' ')), JSON.stringify(fmt)); | |
| 306 | + const toml = veredicto({ hasCode: true, browserEntry: true, categories: ['Programming Languages', 'Linters', 'Formatters'], sizes: { grammars: 3, languages: 1, commands: 5, menus: 1, configuration: 2 }, | |
| 307 | + ignored: [{ key: 'commands' }, { key: 'menus' }, { key: 'configuration' }, { key: 'semanticTokenTypes' }], themes: [], highlight: [{ id: 'toml', name: 'TOML', exts: ['.toml'] }], settingsOnly: [], snippets: [] }); | |
| 308 | + ok('veredicto: lenguaje + código → funciona en parte, nombra TOML, botón «solo el resaltado»', toml.kind === 'partial' && /TOML/.test(toml.verdict) && toml.button.key === 'installOnlyHighlight' && !toml.button.disabled, JSON.stringify(toml)); | |
| 309 | + const tema = veredicto({ hasCode: false, categories: ['Themes'], sizes: { themes: 2 }, ignored: [], themes: ['Dracula', 'Dracula Soft'], highlight: [], settingsOnly: [], snippets: [] }); | |
| 310 | + ok('veredicto: solo temas → «Works in Code» con los nombres y botón Instalar', tema.kind === 'full' && /Dracula/.test(tema.verdict) && tema.button.key === 'install', JSON.stringify(tema)); | |
| 311 | + const taller = veredicto({ hasCode: true, browserEntry: false, categories: ['Programming Languages', 'Snippets', 'Linters'], sizes: { commands: 46, views: 1, customEditors: 1, grammars: 16 }, webviews: true, | |
| 312 | + ignored: [{ key: 'commands' }, { key: 'views' }, { key: 'customEditors' }], themes: [], highlight: [{ id: 'latex', name: 'LaTeX', exts: ['.tex'] }], settingsOnly: [], snippets: [{ id: 'latex', name: 'LaTeX', count: null }] }); | |
| 313 | + ok('veredicto: sobre todo código → primero lo que no funciona, luego «Only … would apply», botón secundario', taller.kind === 'mostlyCode' && /does not work in Code/.test(taller.verdict) && /^Only/.test(taller.lines[0]) && /LaTeX/.test(taller.lines[0]) && taller.button.style === 'ghost', JSON.stringify(taller)); | |
| 314 | + const sinTraducir = veredicto({ hasCode: false, categories: ['Themes'], sizes: { themes: 1 }, ignored: [], themes: ['%themeLabel%'], highlight: [], settingsOnly: [], snippets: [] }); | |
| 315 | + ok('veredicto: un nombre sin traducir (%clave%) no se enseña: se cuenta', !/%/.test(sinTraducir.verdict) && /a colour theme/.test(sinTraducir.verdict), sinTraducir.verdict); | |
| 316 | + const nombres = veredicto({ hasCode: true, categories: ['Other'], sizes: { foo: 1 }, ignored: [{ key: 'someNewThing' }], themes: [], highlight: [], settingsOnly: [], snippets: [] }); | |
| 317 | + ok('veredicto: una contribución desconocida sale como «other features», no con su nombre', !/someNewThing/.test(nombres.verdict + nombres.lines.join(' ')), nombres.verdict); | |
| 318 | +} | |
| 319 | + | |
| 293 | 320 | console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ EXTENSIONES (Node): vsix, formatos, temas, lenguajes y snippets OK'); |
| 294 | 321 | process.exit(fails ? 1 : 0); |
modified tests/extensions.mjs +9 −8
| @@ -87,7 +87,7 @@ | ||
| 87 | 87 | await instalaFichero('elf-theme.vsix', themeVsix()); |
| 88 | 88 | ok('tema instalado desde .vsix', await hasta(async () => (await filaInstalada('elffuss-test.elf-theme').count()) === 1), await p.locator('#ext-msg').textContent()); |
| 89 | 89 | const textoFila = await filaInstalada('elffuss-test.elf-theme').innerText(); |
| 90 | -ok('la fila dice qué aplica y qué no (commands necesita código, main no se ejecuta)', /2 (temas|themes)/.test(textoFila) && /commands/.test(textoFila) && /(main\/browser)/.test(textoFila), textoFila.replace(/\s+/g, ' ').slice(0, 220)); | |
| 90 | +ok('la fila dice en llano qué hace ahora y qué no funciona (sus acciones necesitan su código)', /Active theme: “Elf Dark”/.test(textoFila) && /Does not work: .*its own actions/.test(textoFila) && !/commands|main\/browser|extension host/.test(textoFila), textoFila.replace(/\s+/g, ' ').slice(0, 320)); | |
| 91 | 91 | const chipOscuro = filaInstalada('elffuss-test.elf-theme').locator('.ext-theme-chips .ext-chip').first(); |
| 92 | 92 | await chipOscuro.click(); |
| 93 | 93 | ok('tema aplicado: fondo del editor', await hasta(async () => (await fondo()) === rgb(THEME_DARK.bg)), await fondo()); |
| @@ -321,10 +321,10 @@ | ||
| 321 | 321 | |
| 322 | 322 | // J3. lo que no se pudo leer se dice, en la fila y al instalar |
| 323 | 323 | const msgMedio = await instalaFichero('half.vsix', brokenThemeVsix()); |
| 324 | -ok('instalada, y el mensaje avisa de lo que no se pudo usar', msgMedio === '“Half Broken” installed. 1 part could not be used.', msgMedio); | |
| 324 | +ok('instalada, y el mensaje avisa de lo que no se pudo usar', msgMedio === '“Half Broken” installed. Theme “Good One” applied. 1 part could not be used.', msgMedio); | |
| 325 | 325 | ok('…anunciado (role=status)', (await p.getAttribute('#ext-msg', 'role')) === 'status'); |
| 326 | 326 | const filaMedio = filaInstalada('elffuss-test.half-broken'); |
| 327 | -ok('la fila: «Applies: 1 theme» y el aviso plegado', /Applies: 1 theme\b/.test(await filaMedio.innerText()) && (await filaMedio.locator('details.ext-warn summary').innerText()) === '1 part could not be used', (await filaMedio.innerText()).replace(/\s+/g, ' ')); | |
| 327 | +ok('la fila: «Active theme: “Good One”» y el aviso plegado', /Active theme: “Good One”/.test(await filaMedio.innerText()) && (await filaMedio.locator('details.ext-warn summary').innerText()) === '1 part could not be used', (await filaMedio.innerText()).replace(/\s+/g, ' ')); | |
| 328 | 328 | await filaMedio.locator('details.ext-warn summary').focus(); |
| 329 | 329 | await p.keyboard.press('Enter'); |
| 330 | 330 | const desplegado = await filaMedio.locator('details.ext-warn').evaluate(d => ({ open: d.open, li: d.querySelector('li')?.getClientRects().length > 0, texto: d.querySelector('li')?.textContent })); |
| @@ -335,7 +335,7 @@ | ||
| 335 | 335 | // J4. lo que no se aplica no se cuenta como aplicado |
| 336 | 336 | await instalaFichero('json.vsix', jsonGrammarVsix()); |
| 337 | 337 | const textoJson = (await filaInstalada('elffuss-test.json-x').innerText()).replace(/\s+/g, ' '); |
| 338 | -ok('gramática y configuración de JSON: «nada aplicable» y las dos en «Not applied»', textoJson.includes('Nothing in this extension can be applied here.') && textoJson.includes('Not applied: json grammar (Monaco keeps its built-in highlighting) · json settings (Monaco keeps its own)') && !/\b1 (grammar|language)\b/.test(textoJson), textoJson); | |
| 338 | +ok('gramática y configuración de JSON: «nada aplicable» y que Code mantiene su resaltado de JSON', textoJson.includes('Nothing in this extension can be applied here.') && textoJson.includes('Code already highlights JSON its own way and keeps it.') && !/Monaco|\b1 (grammar|language)\b/.test(textoJson), textoJson); | |
| 339 | 339 | |
| 340 | 340 | // J5. el foco no se pierde al repintar la lista de instaladas |
| 341 | 341 | await filaMedio.locator('.ext-theme-chips .ext-chip').first().focus(); |
| @@ -368,14 +368,15 @@ | ||
| 368 | 368 | await p.press('#ext-q', 'Enter'); |
| 369 | 369 | const filaFalsa = p.locator('#ext-results .ext-row[data-id="elffuss-test.fake"]'); |
| 370 | 370 | ok('búsqueda: el resultado llega y se anuncia («1 result»)', await hasta(async () => (await filaFalsa.count()) === 1 && (await p.textContent('#ext-status')) === '1 result'), await p.textContent('#ext-status')); |
| 371 | -ok('Install con nombre propio para el lector («Install Fake JSON»)', (await filaFalsa.locator('.ext-install').getAttribute('aria-label')) === 'Install Fake JSON'); | |
| 371 | +ok('el botón dice que no hay nada que aplicar, con nombre propio para el lector', await hasta(async () => (await filaFalsa.locator('.ext-install').getAttribute('aria-label')) === 'Nothing to apply: Fake JSON'), await filaFalsa.locator('.ext-install').getAttribute('aria-label')); | |
| 372 | 372 | await filaFalsa.locator('.ext-install').focus(); |
| 373 | 373 | await p.keyboard.press('Shift+Tab'); |
| 374 | 374 | const nombreBtn = await activo(); |
| 375 | 375 | ok('Shift+Tab desde Install: el nombre, que es un botón de detalle plegado', nombreBtn.cls === 'ext-name' && (await p.evaluate(() => document.activeElement.getAttribute('aria-expanded'))) === 'false', JSON.stringify(nombreBtn)); |
| 376 | 376 | await p.keyboard.press('Enter'); |
| 377 | -const detalleAbierto = await hasta(() => p.evaluate(() => { const b = document.activeElement, d = document.getElementById(b.getAttribute('aria-controls')); return b.getAttribute('aria-expanded') === 'true' && d && !d.hidden && /Nothing in this extension/.test(d.textContent) && d.textContent; })); | |
| 378 | -ok('Enter: el detalle se despliega (aria-expanded) y dice qué aplicaría, también lo de JSON', !!detalleAbierto && /Not applied: json grammar/.test(detalleAbierto), String(detalleAbierto)); | |
| 377 | +const detalleAbierto = await hasta(() => p.evaluate(() => { const b = document.activeElement, d = document.getElementById(b.getAttribute('aria-controls')); return b.getAttribute('aria-expanded') === 'true' && d && !d.hidden && /Licence/.test(d.textContent) && d.textContent; })); | |
| 378 | +const veredictoFalsa = await filaFalsa.locator('.ext-verdict').innerText().catch(() => ''); | |
| 379 | +ok('Enter: el detalle se despliega (aria-expanded) y la fila dice qué aplicaría, también lo de JSON', !!detalleAbierto && /Nothing in this extension/.test(veredictoFalsa) && /Code already highlights JSON/.test(veredictoFalsa), String(detalleAbierto) + ' | ' + veredictoFalsa); | |
| 379 | 380 | // (isDisabled() de Playwright cuenta aria-disabled como deshabilitado: aquí se |
| 380 | 381 | // mira la propiedad del DOM, que es la que le quitaría el foco) |
| 381 | 382 | const inst = await filaFalsa.locator('.ext-install').evaluate(b => { b.focus(); return { aria: b.getAttribute('aria-disabled'), disabled: b.disabled, foco: document.activeElement === b }; }); |
| @@ -492,7 +493,7 @@ | ||
| 492 | 493 | const fila = p.locator('#ext-results .ext-row[data-id="vscode.theme-monokai"]'); |
| 493 | 494 | ok('Open VSX: búsqueda con resultados', await hasta(async () => (await fila.count()) === 1, { tiempo: 20000 })); |
| 494 | 495 | await fila.locator('.ext-main').click(); |
| 495 | - ok('Open VSX: el detalle dice qué aplicaría (sin bajar el .vsix)', await hasta(async () => /1 (tema|theme)/.test(await fila.locator('.ext-detail').innerText()), { tiempo: 20000 }), await fila.locator('.ext-detail').innerText()); | |
| 496 | + ok('Open VSX: la fila dice qué aplicaría (sin bajar el .vsix), sin claves %sin traducir%', await hasta(async () => (t => /^Works in Code: adds a colour theme\.$/.test(t) && !/%\w+%/.test(t))(await fila.locator('.ext-verdict').innerText()), { tiempo: 20000 }), await fila.locator('.ext-verdict').innerText().catch(() => '')); | |
| 496 | 497 | await fila.locator('.ext-install').click(); |
| 497 | 498 | ok('Open VSX: vscode.theme-monokai instalada (SHA-256 comprobada)', await hasta(async () => (await filaInstalada('vscode.theme-monokai').count()) === 1, { tiempo: 30000 }) && /SHA-256/.test(await filaInstalada('vscode.theme-monokai').innerText())); |
| 498 | 499 | await filaInstalada('vscode.theme-monokai').locator('.ext-theme-chips .ext-chip').first().click(); |