9 lines
4.6 KiB
JavaScript
9 lines
4.6 KiB
JavaScript
const{chromium}=require('playwright'),assert=require('node:assert/strict'),fs=require('node:fs');
|
|
const base=process.env.PUBLIC_BASE_URL||'http://127.0.0.1:5238',live=new URL(base).hostname==='dev.plotdirector.com';
|
|
(async()=>{const b=await chromium.launch(),results=[];try{for(const width of [390,768,1440,1920]){const c=await b.newContext({viewport:{width,height:1000},reducedMotion:'reduce'});await c.addCookies([{name:'solver-anonymous',value:'true',url:base}]);await c.addInitScript(()=>{localStorage.setItem('plotdirector.applicationTheme','modern-dark');localStorage.setItem('plotline.theme','dark')});const p=await c.newPage();
|
|
for(const [name,path]of [['home',live?'/':'/public-fixture/home?anonymous=true'],['tour',live?'/features':'/public-fixture/tour?anonymous=true'],['pricing',live?'/pricing':'/public-fixture/pricing?anonymous=true']]){assert.equal((await p.goto(base+path)).status(),200);await p.waitForLoadState('networkidle');assert.equal(await p.locator('html').getAttribute('data-site-theme'),'public');assert.equal(await p.locator('html').getAttribute('data-app-theme'),null);const layer=p.locator('.public-scene'),img=layer.locator('img');assert.equal(await layer.getAttribute('aria-hidden'),'true');assert.equal(await img.getAttribute('loading'),'eager');assert.equal(await img.getAttribute('fetchpriority'),'high');await img.evaluate(e=>e.decode());const selected=await img.evaluate(e=>e.currentSrc);assert(selected.endsWith('.avif'));assert(selected.includes(name+'-'+(width<=600?'mobile':'wide')));assert(!selected.includes('writing-solver'));const box=await layer.boundingBox();assert(Math.abs(box.x)<1&&Math.abs(box.width-width)<1,'Photo is boxed into the content container');assert.equal(await p.evaluate(()=>document.documentElement.scrollWidth>innerWidth),false);const resources=await p.evaluate(()=>performance.getEntriesByType('resource').filter(r=>r.name.includes('/images/public/scenes/')).map(r=>({url:r.name,bytes:r.transferSize,encoded:r.encodedBodySize})));assert.equal(resources.length,1,'Duplicate background variants downloaded');assert(resources[0].encoded<(width<=600?100000:300000));if(width===390)assert(selected.includes('480'));if(name==='home'){assert((await p.locator('h1').innerText()).includes('Finally finish the novel'));assert.equal(await p.locator('.manuscript-sheet').count(),1);}if(name==='tour')assert((await p.locator('.tour-stop').count())>=9);if(name==='pricing')assert((await p.locator('.pricing-card').count())>=1);results.push({name,width,selected,resources});if(process.env.PUBLIC_CAPTURE_DIR){fs.mkdirSync(process.env.PUBLIC_CAPTURE_DIR,{recursive:true});await p.screenshot({path:`${process.env.PUBLIC_CAPTURE_DIR}/${name}-${width}.png`});}}
|
|
for(const path of ['/help','/problem-solver/browse','/problem-solver/timeline-doesnt-add-up','/features/plot-lines','/about','/contact','/privacy','/terms',live?'/Account/Login':'/public-fixture/login?anonymous=true',live?'/Account/Register':'/public-fixture/register?anonymous=true']){assert.equal((await p.goto(base+path)).status(),200);assert.equal(await p.locator('html').getAttribute('data-site-theme'),'public');assert.equal(await p.locator('html').getAttribute('data-app-theme'),null);assert.equal(await p.locator('.public-scene').count(),0);assert.equal(await p.evaluate(()=>document.documentElement.scrollWidth>innerWidth),false,`${path}/${width}`);if(process.env.PUBLIC_CAPTURE_DIR&&width===390&&['/help','/about',live?'/Account/Login':'/public-fixture/login?anonymous=true'].includes(path))await p.screenshot({path:`${process.env.PUBLIC_CAPTURE_DIR}/other-${path.split('/').at(-1).split('?')[0]}-${width}.png`});}
|
|
await c.close();}
|
|
// A real WebP path when the browser does not support AVIF.
|
|
const c=await b.newContext({viewport:{width:390,height:1000}}),p=await c.newPage();const path=live?'/':'/public-fixture/home?anonymous=true';await p.route(base+path,async route=>{const r=await route.fetch();await route.fulfill({response:r,body:(await r.text()).replaceAll('type="image/avif"','type="image/unsupported"')})});await p.goto(base+path);await p.locator('.public-scene img').evaluate(e=>e.decode());assert((await p.locator('.public-scene img').evaluate(e=>e.currentSrc)).endsWith('mobile-480.webp'));await c.close();fs.writeFileSync(process.env.PUBLIC_METRICS||'/tmp/public-identity-assets.json',JSON.stringify(results,null,2));console.log('PASS coordinated unique scenes at four widths; one responsive AVIF per page, WebP fallback, mobile crop, eager high-priority hero, full-width canvas, no overflow, intact hero/plan/tour structure; ten other public page types remain public and without extra photography despite saved dark app preferences.');}finally{await b.close()}})().catch(e=>{console.error(e);process.exit(1)});
|