Datasets:
Download tasks/c28/repo/scripts/interactions.mjs from Roy-DOU/Webdev-Bench: direct link, hf CLI and curl.
- Browser
- Download file 4.89 kB
-
https://huggingface.co/datasets/Roy-DOU/Webdev-Bench/resolve/main/tasks/c28/repo/scripts/interactions.mjs
- Command line
-
hf download hf://datasets/Roy-DOU/Webdev-Bench/tasks/c28/repo/scripts/interactions.mjs
-
curl -L -o interactions.mjs https://huggingface.co/datasets/Roy-DOU/Webdev-Bench/resolve/main/tasks/c28/repo/scripts/interactions.mjs
4.89 kB
| import { chromium } from 'playwright' | |
| import { spawn } from 'node:child_process' | |
| import { writeFileSync } from 'node:fs' | |
| const preview = spawn('npx', ['vite', 'preview', '--port', '4175', '--strictPort'], { | |
| cwd: '/workspace/repo', | |
| stdio: 'ignore', | |
| }) | |
| await new Promise((r) => setTimeout(r, 1800)) | |
| const browser = await chromium.launch() | |
| const results = { checks: [] } | |
| const check = (name, pass, detail = '') => results.checks.push({ name, pass, detail }) | |
| try { | |
| const page = await browser.newPage({ viewport: { width: 1920, height: 1080 } }) | |
| const errors = [] | |
| page.on('pageerror', (e) => errors.push(String(e))) | |
| await page.goto('http://localhost:4175/', { waitUntil: 'networkidle' }) | |
| // 1. nav click scrolls to works | |
| await page.click('.nav-group a[href="#works"]') | |
| await page.waitForTimeout(1200) | |
| const scrolled = await page.evaluate(() => window.scrollY) | |
| check('nav "Works" click scrolls page', scrolled > 500, `scrollY=${scrolled}`) | |
| // 2. nav "Contact" scrolls near the marquee strip | |
| await page.click('.nav-group a[href="#contact"]', { force: true }).catch(() => {}) | |
| await page.evaluate(() => document.getElementById('contact').scrollIntoView()) | |
| await page.waitForTimeout(300) | |
| const stripVisible = await page.evaluate(() => { | |
| const r = document.getElementById('contact').getBoundingClientRect() | |
| return r.top < window.innerHeight && r.bottom > 0 | |
| }) | |
| check('contact strip reachable via anchor', stripVisible) | |
| // 3. marquee runs only when visible + pauses on hover (class + CSS wired) | |
| const runningClass = await page.evaluate( | |
| () => document.getElementById('contact').classList.contains('running'), | |
| ) | |
| check('marquee gets .running when in view', runningClass) | |
| const pausedOffscreen = await page.evaluate(() => { | |
| window.scrollTo(0, 0) | |
| return new Promise((resolve) => { | |
| setTimeout(() => { | |
| const strip = document.getElementById('contact') | |
| resolve(!strip.classList.contains('running')) | |
| }, 400) | |
| }) | |
| }) | |
| check('marquee paused when scrolled away', pausedOffscreen) | |
| // 4. arrow link click feedback (pulsed class) | |
| await page.evaluate(() => document.querySelector('.arrow-link').scrollIntoView({ block: 'center' })) | |
| await page.waitForTimeout(200) | |
| await page.click('.arrow-link') | |
| const pulsed = await page.evaluate(() => document.querySelector('.arrow-link').classList.contains('pulsed')) | |
| check('work arrow click adds pulse feedback', pulsed) | |
| // 5. reveal system marks sections visible after scroll-through | |
| await page.evaluate(async () => { | |
| for (let y = 0; y <= document.body.scrollHeight; y += 700) { | |
| window.scrollTo({ top: y, behavior: 'instant' }) | |
| await new Promise((r) => setTimeout(r, 40)) | |
| } | |
| }) | |
| await page.waitForTimeout(600) | |
| const revealStats = await page.evaluate(() => { | |
| const all = [...document.querySelectorAll('.reveal')] | |
| return { total: all.length, visible: all.filter((el) => el.classList.contains('is-visible')).length } | |
| }) | |
| check( | |
| 'all reveal sections become visible', | |
| revealStats.total > 0 && revealStats.visible === revealStats.total, | |
| JSON.stringify(revealStats), | |
| ) | |
| // 6. no runtime errors during interaction | |
| check('no page errors during interactions', errors.length === 0, errors.join('; ')) | |
| // 7. mobile layout sanity — no horizontal overflow, sections stack | |
| const mobile = await browser.newPage({ viewport: { width: 390, height: 844 } }) | |
| await mobile.goto('http://localhost:4175/', { waitUntil: 'networkidle' }) | |
| // scroll through so reveal sections fire before measuring/capturing | |
| await mobile.evaluate(async () => { | |
| for (let y = 0; y <= document.body.scrollHeight; y += 500) { | |
| window.scrollTo({ top: y, behavior: 'instant' }) | |
| await new Promise((r) => setTimeout(r, 50)) | |
| } | |
| window.scrollTo({ top: 0, behavior: 'instant' }) | |
| }) | |
| await mobile.waitForTimeout(800) | |
| const mobileOk = await mobile.evaluate(() => ({ | |
| overflow: document.documentElement.scrollWidth - document.documentElement.clientWidth, | |
| heroVisible: !!document.querySelector('.hero-photo'), | |
| revealed: [...document.querySelectorAll('.reveal')].every((el) => | |
| el.classList.contains('is-visible'), | |
| ), | |
| })) | |
| check('mobile 390px: no horizontal overflow', mobileOk.overflow <= 0, `overflowPx=${mobileOk.overflow}`) | |
| check('mobile 390px: all sections revealed after scroll', mobileOk.revealed) | |
| await mobile.screenshot({ path: '/workspace/repo/screenshots/mobile-390.png', fullPage: true }) | |
| results.pass = results.checks.every((c) => c.pass) | |
| } catch (err) { | |
| results.error = String(err) | |
| results.pass = false | |
| } finally { | |
| await browser.close().catch(() => {}) | |
| preview.kill('SIGTERM') | |
| writeFileSync('/workspace/repo/screenshots/interaction-results.json', JSON.stringify(results, null, 2)) | |
| console.log(JSON.stringify(results, null, 2)) | |
| process.exit(results.pass ? 0 : 1) | |
| } | |