feat: add content collection with schema and reading-time utility
- Created src/content.config.ts with Astro defineCollection using glob loader, pattern '**/*.{md,mdx}', base './src/content/posts', and Zod schema with 5 fields (title, date, type, tags, summary)
- Created src/content/posts/ directory for content storage
- Created src/utils/reading-time.ts with getReadingTime function (split whitespace, 200 WPM, Math.max(1, Math.ceil))
- All 23 new tests pass, all 61 total tests pass, npm run build succeeds
Generated with Amplifier
Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { describe, it } from 'node:test';
|
||||
import { strict as assert } from 'node:assert';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { resolve } from 'node:path';
|
||||
|
||||
const utilPath = resolve('src/utils/reading-time.ts');
|
||||
|
||||
function readUtil() {
|
||||
return readFileSync(utilPath, 'utf-8');
|
||||
}
|
||||
|
||||
describe('reading-time utility', () => {
|
||||
it('should exist at src/utils/reading-time.ts', () => {
|
||||
const content = readUtil();
|
||||
assert.ok(content.length > 0, 'Utility file should not be empty');
|
||||
});
|
||||
|
||||
it('should export a getReadingTime function', () => {
|
||||
const content = readUtil();
|
||||
assert.match(content, /export\s+(function\s+getReadingTime|const\s+getReadingTime|{[^}]*getReadingTime)/, 'should export getReadingTime');
|
||||
});
|
||||
|
||||
it('should accept a text: string parameter', () => {
|
||||
const content = readUtil();
|
||||
assert.match(content, /getReadingTime\s*\(\s*text\s*:\s*string\s*\)/, 'should accept text: string param');
|
||||
});
|
||||
|
||||
it('should return a number type', () => {
|
||||
const content = readUtil();
|
||||
assert.match(content, /:\s*number/, 'should have number return type');
|
||||
});
|
||||
|
||||
it('should split on whitespace', () => {
|
||||
const content = readUtil();
|
||||
assert.match(content, /split\s*\(\s*\/\\s\+\//, 'should split on whitespace regex');
|
||||
});
|
||||
|
||||
it('should divide by 200 WPM', () => {
|
||||
const content = readUtil();
|
||||
assert.match(content, /200/, 'should use 200 WPM');
|
||||
});
|
||||
|
||||
it('should use Math.max(1, Math.ceil(...))', () => {
|
||||
const content = readUtil();
|
||||
assert.match(content, /Math\.max\s*\(\s*1/, 'should use Math.max(1, ...)');
|
||||
assert.match(content, /Math\.ceil/, 'should use Math.ceil');
|
||||
});
|
||||
|
||||
it('should filter empty strings from split result', () => {
|
||||
const content = readUtil();
|
||||
assert.match(content, /filter/, 'should filter empty strings from split');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user