|
| 1 | +import { expect, test } from '@playwright/test' |
| 2 | + |
| 3 | +test.describe('Landing Page - Build Integrity', () => { |
| 4 | + test.beforeEach(async ({ page }) => { |
| 5 | + await page.goto('/') |
| 6 | + }) |
| 7 | + |
| 8 | + test('page loads without console errors', async ({ page }) => { |
| 9 | + const errors: string[] = [] |
| 10 | + page.on('pageerror', (error) => { |
| 11 | + errors.push(error.message) |
| 12 | + }) |
| 13 | + |
| 14 | + // Re-navigate to capture errors from initial load |
| 15 | + await page.goto('/') |
| 16 | + await page.waitForLoadState('networkidle') |
| 17 | + |
| 18 | + expect(errors, 'Page should load without JS errors').toHaveLength(0) |
| 19 | + }) |
| 20 | + |
| 21 | + test('CSS stylesheets are present in <head>', async ({ page }) => { |
| 22 | + const stylesheetCount = await page.locator('link[rel="stylesheet"]').count() |
| 23 | + expect( |
| 24 | + stylesheetCount, |
| 25 | + 'Expected at least one CSS stylesheet link in <head>', |
| 26 | + ).toBeGreaterThan(0) |
| 27 | + }) |
| 28 | + |
| 29 | + test('CSS files contain devup-ui generated classes', async ({ page }) => { |
| 30 | + // devup-ui generates CSS with short class names (a, b, c, ..., aa, ab, ...) |
| 31 | + // Next.js bundles them into hashed chunk filenames, so we check CSS content |
| 32 | + const hasDevupStyles = await page.evaluate(async () => { |
| 33 | + const links = Array.from( |
| 34 | + document.querySelectorAll('link[rel="stylesheet"]'), |
| 35 | + ) |
| 36 | + for (const link of links) { |
| 37 | + const href = link.getAttribute('href') |
| 38 | + if (!href) continue |
| 39 | + try { |
| 40 | + const res = await fetch(href) |
| 41 | + const text = await res.text() |
| 42 | + // devup-ui uses CSS custom properties like --primary, --text, --background |
| 43 | + // and generates short class selectors |
| 44 | + if ( |
| 45 | + text.includes('--primary') || |
| 46 | + text.includes('--footerBg') || |
| 47 | + text.includes('--background') |
| 48 | + ) { |
| 49 | + return true |
| 50 | + } |
| 51 | + } catch { |
| 52 | + // skip fetch errors |
| 53 | + } |
| 54 | + } |
| 55 | + return false |
| 56 | + }) |
| 57 | + |
| 58 | + expect( |
| 59 | + hasDevupStyles, |
| 60 | + 'Expected CSS files to contain devup-ui generated styles (CSS variables like --primary, --footerBg)', |
| 61 | + ).toBe(true) |
| 62 | + }) |
| 63 | + |
| 64 | + test('no 404 errors on CSS or JS resources', async ({ page }) => { |
| 65 | + const failedRequests: string[] = [] |
| 66 | + |
| 67 | + page.on('response', (response) => { |
| 68 | + const url = response.url() |
| 69 | + if ( |
| 70 | + response.status() === 404 && |
| 71 | + (url.endsWith('.css') || url.endsWith('.js')) |
| 72 | + ) { |
| 73 | + failedRequests.push(`${response.status()} ${url}`) |
| 74 | + } |
| 75 | + }) |
| 76 | + |
| 77 | + await page.goto('/') |
| 78 | + await page.waitForLoadState('networkidle') |
| 79 | + |
| 80 | + expect( |
| 81 | + failedRequests, |
| 82 | + `Found 404 errors for resources: ${failedRequests.join(', ')}`, |
| 83 | + ).toHaveLength(0) |
| 84 | + }) |
| 85 | + |
| 86 | + test('page has actual visible content (not blank)', async ({ page }) => { |
| 87 | + // Check for the hero text that should always be present |
| 88 | + const heroText = page.getByText('Zero Config') |
| 89 | + await expect(heroText.first()).toBeVisible() |
| 90 | + |
| 91 | + // Check for the "Features" section heading |
| 92 | + const featuresHeading = page.getByText('Features') |
| 93 | + await expect(featuresHeading.first()).toBeVisible() |
| 94 | + |
| 95 | + // Check that body has non-trivial content |
| 96 | + const bodyText = await page.evaluate( |
| 97 | + () => document.body.innerText.trim().length, |
| 98 | + ) |
| 99 | + expect( |
| 100 | + bodyText, |
| 101 | + 'Page body should have substantial text content', |
| 102 | + ).toBeGreaterThan(100) |
| 103 | + }) |
| 104 | + |
| 105 | + test('page title is set correctly', async ({ page }) => { |
| 106 | + await expect(page).toHaveTitle(/Devup UI/) |
| 107 | + }) |
| 108 | +}) |
0 commit comments