import { describe, it } from 'node:test';
import { strict as assert } from 'node:assert';
import { readFileSync, existsSync } from 'node:fs';
import { resolve } from 'node:path';
const pagePath = resolve('src/pages/index.astro');
function readPage() {
return readFileSync(pagePath, 'utf-8');
}
describe('Index page', () => {
it('should exist at src/pages/index.astro', () => {
assert.ok(existsSync(pagePath), 'Index page file should exist');
});
describe('Imports', () => {
it('should import getCollection from astro:content', () => {
const content = readPage();
assert.match(content, /import\s+.*getCollection.*from\s+['"]astro:content['"]/, 'should import getCollection');
});
it('should import BaseLayout', () => {
const content = readPage();
assert.match(content, /import\s+BaseLayout\s+from\s+['"].*BaseLayout\.astro['"]/, 'should import BaseLayout');
});
it('should import NavBar', () => {
const content = readPage();
assert.match(content, /import\s+NavBar\s+from\s+['"].*NavBar\.astro['"]/, 'should import NavBar');
});
it('should import getReadingTime', () => {
const content = readPage();
assert.match(content, /import\s+.*getReadingTime.*from\s+['"].*reading-time['"]/, 'should import getReadingTime');
});
});
describe('Data fetching', () => {
it('should fetch all posts with getCollection', () => {
const content = readPage();
assert.match(content, /getCollection\s*\(\s*['"]posts['"]\s*\)/, 'should call getCollection("posts")');
});
});
describe('Hero section', () => {
it('should have a hero section', () => {
const content = readPage();
assert.match(content, /class="hero"/, 'should have a section with class hero');
});
it('should have the site title Crash Test Dev as a heading', () => {
const content = readPage();
assert.match(content, /
]*>Crash Test Dev<\/h1>/, 'should have h1 with site title');
});
it('should have a tagline in prose font', () => {
const content = readPage();
assert.match(content, /class="tagline"/, 'should have a tagline element');
});
it('should have an author byline', () => {
const content = readPage();
assert.match(content, /class="byline"/, 'should have a byline element');
});
it('should contain an inline SVG hero illustration', () => {
const content = readPage();
// The hero section should contain an SVG element
assert.match(content, /class="hero-illustration"/, 'should have a hero illustration');
assert.match(content, /