Files

54 lines
4.3 KiB
JavaScript

const path=require('path');
const root=path.resolve(__dirname,'../../..');
const {chromium} = require(path.join(root,'react/node_modules/playwright'));
const {default:AxeBuilder} = require(path.join(root,'react/node_modules/@axe-core/playwright'));
const fs=require('fs'), assert=require('assert/strict');
const dist=path.join(root,'react/dist'), out=path.join(root,'docs/visual-qa/bs-006');
const types={'.html':'text/html','.js':'text/javascript','.css':'text/css','.ttf':'font/ttf','.svg':'image/svg+xml','.png':'image/png'};
(async()=>{
fs.mkdirSync(out,{recursive:true});
const browser=await chromium.launch({headless:true});
const results=[];
for(const theme of ['dark','light']) for(const width of [1440,320]) {
const context=await browser.newContext({viewport:{width,height:1000}});
await context.addInitScript(t=>localStorage.setItem('bortstack-theme',t),theme);
const errors=[],requests=[];
await context.route('http://bs006.test/**',async route=>{
const u=new URL(route.request().url());
if(u.pathname.startsWith('/api/')){requests.push(u.pathname);return route.fulfill({json:{email:null,available:false}})}
let file=path.join(dist,decodeURIComponent(u.pathname));
if(!fs.existsSync(file)||fs.statSync(file).isDirectory()) file=path.join(dist,'index.html');
await route.fulfill({body:fs.readFileSync(file),contentType:types[path.extname(file)]||'application/octet-stream'});
});
const page=await context.newPage();page.on('pageerror',e=>errors.push(e.message));
for(const [url,heading] of [['/projects','Projects'],['/projects/roulettebuddy','RouletteBuddy'],['/projects/pitchinvader','PitchInvader'],['/projects/api-admin','API Admin'],['/projects/missing','Project not found']]) {
await page.goto('http://bs006.test'+url);await page.getByRole('heading',{level:1,name:heading,exact:true}).waitFor();await page.evaluate(()=>document.fonts.ready);
if(url==='/projects'||url==='/projects/roulettebuddy') {const link=page.getByRole('link',{name:'Visit RouletteBuddy',exact:true}); assert.equal(await link.getAttribute('href'),'https://roulettebuddy.app/'); assert.equal(await link.getAttribute('target'),null);}
assert(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth),`${theme} ${width} ${url} overflow`);
const violations=(await new AxeBuilder({page}).analyze()).violations;
assert.equal(violations.length,0,JSON.stringify({theme,width,url,violations}));
if(url==='/projects/missing')assert.equal(await page.locator('meta[name="robots"]').getAttribute('content'),'noindex, nofollow');
if(width===1440||width===320) await page.screenshot({path:path.join(out,`link-${url.split('/').filter(Boolean).join('-')}-${theme}-${width}.png`),fullPage:true});
}
await page.goto('http://bs006.test/projects');
await page.getByRole('link',{name:'View case study',exact:true}).focus();await page.keyboard.press('Enter');
await page.getByRole('heading',{level:1,name:'RouletteBuddy',exact:true}).waitFor();
assert((await page.title()).includes('RouletteBuddy'));
await page.getByRole('link',{name:'All projects',exact:true}).click();
await page.getByRole('link',{name:'Explore PitchInvader',exact:true}).click();
await page.getByRole('heading',{level:1,name:'PitchInvader',exact:true}).waitFor();
await page.getByRole('link',{name:'Discuss a Project',exact:true}).click();
await page.getByRole('heading',{level:1,name:'Have a project in mind?',exact:true}).waitFor();
for(const url of ['/','/services','/about','/contact','/privacy']) {
await page.goto('http://bs006.test'+url);await page.getByRole('heading',{level:1}).waitFor();
assert(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth),`regression ${theme} ${width} ${url}`);
}
assert.equal(errors.length,0,JSON.stringify(errors));
assert(requests.every(x=>x==='/api/contact/config'));
results.push({theme,width,projectRoutes:5,axe:'passed',navigation:'passed',regressionRoutes:5,pageErrors:errors,apiRequests:[...new Set(requests)]});
await context.close();
}
await browser.close();fs.writeFileSync(path.join(out,'link-results.json'),JSON.stringify(results,null,2)+'\n');
console.log('PASS: live-link checks in four theme/viewport combinations;20Projects-route axe/overflow checks and20existing-route overflow checks plus navigation. Contact config mocked unavailable; no server started.');
})().catch(e=>{console.error(e);process.exit(1)});