Datasets:
Download tasks/c14/repo/scripts/validate.mjs from Roy-DOU/Webdev-Bench: direct link, hf CLI and curl.
- Browser
- Download file 4.52 kB
-
https://huggingface.co/datasets/Roy-DOU/Webdev-Bench/resolve/main/tasks/c14/repo/scripts/validate.mjs
- Command line
-
hf download hf://datasets/Roy-DOU/Webdev-Bench/tasks/c14/repo/scripts/validate.mjs
-
curl -L -o validate.mjs https://huggingface.co/datasets/Roy-DOU/Webdev-Bench/resolve/main/tasks/c14/repo/scripts/validate.mjs
4.52 kB
| import { chromium } from 'playwright' | |
| import fs from 'node:fs' | |
| const url = process.env.APP_URL || 'http://localhost:4173/' | |
| const results = { | |
| timestamp: new Date().toISOString(), | |
| url, | |
| checks: [], | |
| consoleErrors: [], | |
| } | |
| const add = (name, passed, detail) => results.checks.push({ name, passed, detail }) | |
| const browser = await chromium.launch() | |
| const page = await browser.newPage({ viewport: { width: 1440, height: 900 } }) | |
| page.on('console', (msg) => { | |
| if (msg.type() === 'error') results.consoleErrors.push(msg.text()) | |
| }) | |
| page.on('pageerror', (err) => results.consoleErrors.push(String(err))) | |
| await page.goto(url, { waitUntil: 'networkidle' }) | |
| await page.evaluate(() => document.fonts.ready) | |
| // 1. App mounted via React root | |
| const rootChildren = await page.evaluate(() => document.getElementById('root').children.length) | |
| add('react-root-renders', rootChildren > 0, `#root has ${rootChildren} child(ren)`) | |
| // 2. Section order present | |
| const sectionsOk = await page.evaluate(() => { | |
| const order = ['.site-header', '.locations', '.studio-section', '.mission', '.cta-band-wrap', '.site-footer'] | |
| const tops = order.map((sel) => { | |
| const el = document.querySelector(sel) | |
| return el ? el.getBoundingClientRect().top + window.scrollY : null | |
| }) | |
| return tops.every((t, i) => t !== null && (i === 0 || t >= tops[i - 1])) | |
| }) | |
| add('section-order', sectionsOk, 'header → locations → studio(dark) → mission → cta → footer') | |
| // 3. Page height close to source (5055px) | |
| const height = await page.evaluate(() => document.documentElement.scrollHeight) | |
| add('page-height', Math.abs(height - 5055) <= 160, `rendered ${height}px vs source 5055px`) | |
| // 4. Menu toggle interaction | |
| await page.click('.menu-toggle') | |
| const menuVisible = await page.isVisible('#main-menu') | |
| add('menu-opens', menuVisible, 'menu panel appears after clicking Menu') | |
| await page.click('#main-menu a') | |
| const menuClosed = !(await page.isVisible('#main-menu')) | |
| add('menu-closes-on-link', menuClosed, 'menu panel closes after clicking a link') | |
| // 5. Video play button toggles | |
| const playBtn = page.locator('.play-btn').first() | |
| await playBtn.scrollIntoViewIfNeeded() | |
| await playBtn.click() | |
| const pressed = await playBtn.getAttribute('aria-pressed') | |
| add('play-button-toggles', pressed === 'true', `aria-pressed=${pressed} after click`) | |
| await playBtn.click() | |
| // 6. Email form submit shows confirmation | |
| await page.fill('.cta-field input', 'test@example.com') | |
| await page.click('.cta-submit') | |
| const confirm = (await page.textContent('.cta-confirm'))?.trim() | |
| add('form-submit-feedback', !!confirm && confirm.includes('test@example.com'), `confirmation: "${confirm}"`) | |
| // 7. Images all load | |
| const badImages = await page.evaluate(() => | |
| Array.from(document.images) | |
| .filter((img) => !img.complete || img.naturalWidth === 0) | |
| .map((img) => img.src), | |
| ) | |
| add('images-load', badImages.length === 0, badImages.length ? `broken: ${badImages.join(', ')}` : 'all <img> loaded') | |
| // 8. Key text content present | |
| const texts = [ | |
| 'Gros Horloge', | |
| 'Vieux Marché', | |
| 'Des bureaux fermés privatifs', | |
| 'Xavier Leboulanger', | |
| 'Julien Hesry', | |
| 'Bien plus qu\'un coworking', | |
| 'Testez gratuitement', | |
| '06 22 25 78 97', | |
| ] | |
| const body = await page.textContent('body') | |
| const missing = texts.filter((t) => !body.includes(t)) | |
| add('key-copy-present', missing.length === 0, missing.length ? `missing: ${missing.join('; ')}` : 'all key strings found') | |
| // 9. Responsive layouts render without horizontal overflow | |
| for (const [w, h, label] of [[900, 900, 'tablet'], [480, 900, 'mobile']]) { | |
| await page.setViewportSize({ width: w, height: h }) | |
| await page.waitForTimeout(250) | |
| const overflow = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth) | |
| add(`responsive-${label}`, overflow <= 1, `${w}px viewport, horizontal overflow ${overflow}px`) | |
| } | |
| await page.setViewportSize({ width: 1440, height: 900 }) | |
| await page.waitForTimeout(250) | |
| add('no-console-errors', results.consoleErrors.length === 0, results.consoleErrors.join(' | ') || 'clean console') | |
| results.passed = results.checks.filter((c) => c.passed).length | |
| results.failed = results.checks.filter((c) => !c.passed).length | |
| results.allPassed = results.failed === 0 | |
| fs.mkdirSync('/workspace/artifacts', { recursive: true }) | |
| fs.writeFileSync('/workspace/artifacts/validation-results.json', JSON.stringify(results, null, 2)) | |
| console.log(JSON.stringify({ passed: results.passed, failed: results.failed, allPassed: results.allPassed })) | |
| await browser.close() | |