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'); }); });