|
| 1 | +/** |
| 2 | + * Smoke tests against the live deployed site. |
| 3 | + * |
| 4 | + * Run manually after deploys: |
| 5 | + * npx vitest run scripts/smoke.test.ts |
| 6 | + * |
| 7 | + * These tests hit forkzero.ai over HTTPS and verify HTTP status codes, |
| 8 | + * redirects, headers, and basic content expectations. |
| 9 | + */ |
| 10 | + |
| 11 | +import { describe, it, expect } from 'vitest' |
| 12 | +import { blogPosts } from '../src/data/blog-posts.js' |
| 13 | + |
| 14 | +const BASE = process.env.SITE_URL ?? 'https://forkzero.ai' |
| 15 | + |
| 16 | +async function head(path: string, opts?: { redirect?: RequestRedirect }) { |
| 17 | + const res = await fetch(`${BASE}${path}`, { |
| 18 | + method: 'HEAD', |
| 19 | + redirect: opts?.redirect ?? 'manual', |
| 20 | + }) |
| 21 | + return res |
| 22 | +} |
| 23 | + |
| 24 | +async function get(path: string) { |
| 25 | + const res = await fetch(`${BASE}${path}`, { redirect: 'manual' }) |
| 26 | + const text = await res.text() |
| 27 | + return { res, text } |
| 28 | +} |
| 29 | + |
| 30 | +// --- HTTP status codes --- |
| 31 | + |
| 32 | +describe('status codes', () => { |
| 33 | + it.each(['/', '/blog', '/getting-started', '/privacy', '/reader'])('%s returns 200', async (path) => { |
| 34 | + const res = await head(path) |
| 35 | + expect(res.status).toBe(200) |
| 36 | + }) |
| 37 | + |
| 38 | + it.each(blogPosts.map((p) => `/blog/${p.slug}`))('%s returns 200', async (path) => { |
| 39 | + const res = await head(path) |
| 40 | + expect(res.status).toBe(200) |
| 41 | + }) |
| 42 | + |
| 43 | + it('non-existent page returns 404', async () => { |
| 44 | + const res = await head('/this-page-does-not-exist-' + Date.now()) |
| 45 | + expect(res.status).toBe(404) |
| 46 | + }) |
| 47 | +}) |
| 48 | + |
| 49 | +// --- Trailing slash redirects --- |
| 50 | + |
| 51 | +describe('trailing slash redirects', () => { |
| 52 | + it.each(['/blog/', '/getting-started/', '/privacy/', '/reader/'])('%s redirects to non-trailing', async (path) => { |
| 53 | + const res = await head(path) |
| 54 | + expect(res.status).toBe(301) |
| 55 | + const location = res.headers.get('location') |
| 56 | + expect(location).toBe(path.slice(0, -1)) |
| 57 | + }) |
| 58 | +}) |
| 59 | + |
| 60 | +// --- Security headers --- |
| 61 | + |
| 62 | +describe('security headers', () => { |
| 63 | + it('has HSTS', async () => { |
| 64 | + const res = await head('/') |
| 65 | + expect(res.headers.get('strict-transport-security')).toContain('max-age=') |
| 66 | + }) |
| 67 | + |
| 68 | + it('has X-Frame-Options', async () => { |
| 69 | + const res = await head('/') |
| 70 | + expect(res.headers.get('x-frame-options')).toBe('DENY') |
| 71 | + }) |
| 72 | + |
| 73 | + it('has X-Content-Type-Options', async () => { |
| 74 | + const res = await head('/') |
| 75 | + expect(res.headers.get('x-content-type-options')).toBe('nosniff') |
| 76 | + }) |
| 77 | + |
| 78 | + it('has Referrer-Policy', async () => { |
| 79 | + const res = await head('/') |
| 80 | + expect(res.headers.get('referrer-policy')).toBe('strict-origin-when-cross-origin') |
| 81 | + }) |
| 82 | + |
| 83 | + it('has Permissions-Policy', async () => { |
| 84 | + const res = await head('/') |
| 85 | + expect(res.headers.get('permissions-policy')).toContain('geolocation=()') |
| 86 | + }) |
| 87 | +}) |
| 88 | + |
| 89 | +// --- Content checks --- |
| 90 | + |
| 91 | +describe('page content', () => { |
| 92 | + it('homepage has correct title', async () => { |
| 93 | + const { text } = await get('/') |
| 94 | + expect(text).toContain('<title>Lattice by Forkzero') |
| 95 | + }) |
| 96 | + |
| 97 | + it('homepage has JSON-LD', async () => { |
| 98 | + const { text } = await get('/') |
| 99 | + expect(text).toContain('application/ld+json') |
| 100 | + expect(text).toContain('"@type":"Organization"') |
| 101 | + }) |
| 102 | + |
| 103 | + it('blog post has BlogPosting schema', async () => { |
| 104 | + const { text } = await get(`/blog/${blogPosts[0].slug}`) |
| 105 | + expect(text).toContain('"@type":"BlogPosting"') |
| 106 | + }) |
| 107 | + |
| 108 | + it('404 page has noindex', async () => { |
| 109 | + const { text } = await get('/this-does-not-exist-' + Date.now()) |
| 110 | + expect(text).toContain('content="noindex"') |
| 111 | + }) |
| 112 | + |
| 113 | + it('404 page has correct title', async () => { |
| 114 | + const { text } = await get('/this-does-not-exist-' + Date.now()) |
| 115 | + expect(text).toContain('<title>Page not found') |
| 116 | + }) |
| 117 | +}) |
| 118 | + |
| 119 | +// --- Static assets --- |
| 120 | + |
| 121 | +describe('static assets', () => { |
| 122 | + it('robots.txt is accessible', async () => { |
| 123 | + const { res, text } = await get('/robots.txt') |
| 124 | + expect(res.status).toBe(200) |
| 125 | + expect(text).toContain('Sitemap:') |
| 126 | + }) |
| 127 | + |
| 128 | + it('sitemap.xml is accessible', async () => { |
| 129 | + const { res, text } = await get('/sitemap.xml') |
| 130 | + expect(res.status).toBe(200) |
| 131 | + expect(text).toContain('<urlset') |
| 132 | + expect(text).toContain('forkzero.ai') |
| 133 | + }) |
| 134 | + |
| 135 | + it('llms.txt is accessible', async () => { |
| 136 | + const { res, text } = await get('/llms.txt') |
| 137 | + expect(res.status).toBe(200) |
| 138 | + expect(text).toContain('Lattice') |
| 139 | + }) |
| 140 | + |
| 141 | + it('og-default.png is accessible', async () => { |
| 142 | + const res = await head('/og-default.png') |
| 143 | + expect(res.status).toBe(200) |
| 144 | + }) |
| 145 | + |
| 146 | + it('hashed assets have immutable cache', async () => { |
| 147 | + // Fetch homepage to find a hashed asset URL |
| 148 | + const { text } = await get('/') |
| 149 | + const match = text.match(/\/assets\/[^"]+\.js/) |
| 150 | + expect(match).not.toBeNull() |
| 151 | + |
| 152 | + const res = await head(`${match![0]}`) |
| 153 | + expect(res.status).toBe(200) |
| 154 | + expect(res.headers.get('cache-control')).toContain('immutable') |
| 155 | + }) |
| 156 | +}) |
0 commit comments