gitoria

components

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmaina06fc778Reset virtual-list window when the host changes resetKeyAtlasmain/tests/virtual-list-reset.mjs

4.7 KB

  1. // node tests/virtual-list-reset.mjs — real wheel/click regression at 390 and 1280.
  2. // VL_BASELINE=1 adds only an inert resetKey declaration to the old component.
  3. // VL_PROOF=1 HL_CDP_URL=... VL_EXTERNAL=1 uses an already-started server and four sizes.
  4. import { spawn } from 'node:child_process';
  5. import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
  6. import { resolve } from 'node:path';
  7. import { launchBrowser, sleep } from './cdp.mjs';
  8. const app = resolve(import.meta.dirname, '..');
  9. const shots = process.env.COMPONENTS_SHOTS || app + '/.scratch/reset-shots';
  10. mkdirSync(shots, {recursive:true});
  11. let server, browser, beforePages, log='', passed=0, failed=0;
  12. const pageList = async () => (await (await fetch(process.env.HL_CDP_URL + '/json/list')).json()).filter(p => p.type === 'page');
  13. const check=(name,ok,detail)=>{ console.log((ok?'ok ':'FAIL ')+name+' '+JSON.stringify(detail)); ok?passed++:failed++; };
  14. // The old component has no resetKey input. For the red proof only, add an inert
  15. // declaration so the same demo compiles; no reset behaviour is supplied.
  16. const component = app + '/components/virtual-list/virtual-list.hl';
  17. const oldComponent = readFileSync(component, 'utf8');
  18. if (process.env.VL_BASELINE === '1') writeFileSync(component, oldComponent.replace('Number scrollTop = null', "Number scrollTop = null\nString resetKey = ''"));
  19. try {
  20. const port=process.env.COMPONENTS_GATE_PORT || '8812';
  21. if (!process.env.VL_EXTERNAL) {
  22. server=spawn(app+'/bin/hybriel',['project.hl'],{cwd:app,env:{...process.env,COMPONENTS_PORT:port,COMPONENTS_WATCH:'0',COMPONENTS_SESSIONS:app+'/.scratch/reset-sessions/'},stdio:['ignore','pipe','pipe']});
  23. console.log('server PID '+server.pid); server.stdout.on('data',d=>log+=d); server.stderr.on('data',d=>log+=d);
  24. }
  25. const base='http://127.0.0.1:'+port;
  26. for(const start=Date.now();;){try{if((await fetch(base+'/')).ok)break;}catch{} if(server?.exitCode != null || Date.now()-start>150000)throw Error(log);await sleep(300);}
  27. if (process.env.HL_CDP_URL) { beforePages = await pageList(); writeFileSync(shots+'/pages-before.json',JSON.stringify(beforePages,null,2)); }
  28. writeFileSync(shots+'/served.html',await (await fetch(base+'/virtual-list')).text());
  29. browser=await launchBrowser({debugPortRange: (process.env.COMPONENTS_GATE_CHROME || '8813-8819').split('-').map(Number)});console.log('Chrome PID '+(browser.proc?.pid || 'attached'));
  30. const page=await browser.newPage();
  31. for(const [width,height] of (process.env.VL_PROOF ? [[390,844],[800,1280],[1280,800],[1280,900]] : [[390,844],[1280,900]])){
  32. await page.send('Emulation.setDeviceMetricsOverride',{width,height,deviceScaleFactor:1,mobile:width===390});
  33. await page.goto(base+'/virtual-list');await page.waitForSelector('.vl-row');await sleep(1000);
  34. const ev=s=>page.evaluate(s);
  35. const state=()=>ev(`({top:document.querySelector('.vl-scroller').scrollTop,blank:document.querySelectorAll('.vl-row.blank').length,first:document.querySelector('.vl-row')?.dataset.index,title:document.querySelector('.vl-title')?.textContent})`);
  36. const down=async()=>{const b=await page.box('.vl-scroller');await page.send('Input.dispatchMouseEvent',{type:'mouseWheel',x:b.x,y:b.y,deltaX:0,deltaY:336000});await sleep(700);check(width+' far down', (await state()).top>300000,await state());};
  37. await down();await page.click('#sort-reset');await sleep(1000);
  38. let s=await state();check(width+' sort resets to top with descending rows',s.top===0 && s.blank===0 && s.first==='0' && s.title==='Song number 13448',s);
  39. writeFileSync(shots+'/sort-'+width+'-'+height+'.png',Buffer.from((await page.send('Page.captureScreenshot',{format:'png'})).data,'base64'));
  40. await down();await page.click('#offset-reset');await sleep(1000);
  41. s=await state();check(width+' reset applies supplied offset and loads window',s.top===11200 && s.blank===0 && Number(s.first)>=180,s);
  42. writeFileSync(shots+'/offset-'+width+'-'+height+'.png',Buffer.from((await page.send('Page.captureScreenshot',{format:'png'})).data,'base64'));
  43. await down();const before=(await state()).top;await page.click('#same-reset');await sleep(300);check(width+' same key preserves position',(await state()).top===before,await state());
  44. check(width+' console clean',page.problems().length===0,page.dumpConsole());
  45. }
  46. }catch(e){failed++;console.log('FAIL '+e.stack+' '+log.slice(-2000));}
  47. finally{if (process.env.VL_BASELINE === '1') writeFileSync(component,oldComponent);if(browser)await browser.close();if(beforePages){const after = await pageList();writeFileSync(shots+'/pages-after.json',JSON.stringify(after,null,2));check('own tab closed and original page list preserved',JSON.stringify(after.map(p=>p.id).sort())===JSON.stringify(beforePages.map(p=>p.id).sort()),after.map(p=>({id:p.id,url:p.url})));}if(server){server.kill('SIGTERM');await sleep(500);}}
  48. console.log(passed+' passed, '+failed+' failed');process.exitCode=failed?1:0;

Branches

Latest commits

  • a06fc778Reset virtual-list window when the host changes resetKeyAtlas
  • 3aab598cRe-vendor complete Hybriel day73 set for virtual-list resetAtlas
  • 337ca075MD1 gate check measures frames in the page, not milliseconds from outside, and takes the middle load (components#30)mre
  • f5f131c5Record AP29 autoplay comparisons and passing gatesmre
  • 51c38187Gate media autoplay on first load and after client mountmre
  • a3f2223dRecord successful B44 deployment and live proofmre
  • 06c1e021Record passing B44 browser rerunmre
  • c9861533Record B44 component proof and browser gate blockermre
  • 1b7413beIgnore detached media events and space demo option outputsmre
  • ca3b4959Re-vendor complete Hybriel plugins and runtime to day44mre
  • df9e7df9Last-item checks run in the browser gate (components#26 fixed on day41); media-player loop is a plain Booleanmre
  • 895a5afcRe-vendor complete Hybriel plugins and runtime to day41mre
  • 16006bb3Backup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre
  • 88397fc3Re-vendor complete Hybriel plugins and runtime to day39mre
  • 9b872cedRecord IC28 deployment and live icon verificationmre
  • 46fefaa7Count the icons entry in the offline home-page checkmre
  • c7e14cabRecord IC28 rerun and unchanged-main baseline comparisonmre
  • 5e090ffdRecord IC28 review evidence and gate resultsmre
  • adfe2c4dAdd shuffle, repeat and repeatOne shared iconsmre
  • c96709c8media-player: skip = false and repeat = 'one' options (jukebox#19)mre