62 lines
2.3 KiB
JavaScript
62 lines
2.3 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { access, readFile } from 'node:fs/promises';
|
|
import path from 'node:path';
|
|
import test from 'node:test';
|
|
|
|
const exportRoot = path.resolve('out');
|
|
|
|
test('the production build exports a usable home page', async () => {
|
|
const indexPath = path.join(exportRoot, 'index.html');
|
|
const html = await readFile(indexPath, 'utf8');
|
|
|
|
assert.match(html, /<!DOCTYPE html>/i);
|
|
assert.match(html, /<html[^>]*lang=/i);
|
|
|
|
const assetPaths = [
|
|
...html.matchAll(/(?:src|href)="(\/_next\/static\/[^"?#]+)/g),
|
|
].map((match) => match[1]);
|
|
|
|
assert.ok(assetPaths.length > 0, 'expected the home page to reference built assets');
|
|
|
|
await Promise.all(
|
|
[...new Set(assetPaths)].map((assetPath) =>
|
|
access(path.join(exportRoot, assetPath.replace(/^\//, ''))),
|
|
),
|
|
);
|
|
});
|
|
|
|
test('the production build exports reciprocal English and Persian pages', async () => {
|
|
const englishHtml = await readFile(path.join(exportRoot, 'index.html'), 'utf8');
|
|
const persianHtml = await readFile(path.join(exportRoot, 'fa.html'), 'utf8');
|
|
|
|
assert.match(englishHtml, /<html[^>]*lang="en"[^>]*dir="ltr"/i);
|
|
assert.match(englishHtml, /href="\/fa"[^>]*hreflang="fa"/i);
|
|
assert.match(englishHtml, />Software Engineer</);
|
|
assert.match(englishHtml, />Quera</);
|
|
assert.doesNotMatch(englishHtml, />مهندس نرمافزار</);
|
|
assert.doesNotMatch(englishHtml, />کوئرا</);
|
|
|
|
assert.match(persianHtml, /<html[^>]*lang="fa"[^>]*dir="rtl"/i);
|
|
assert.match(persianHtml, /href="\/"[^>]*hreflang="en"/i);
|
|
assert.match(persianHtml, /سلام، من امیرحسین خلیلی هستم/);
|
|
assert.match(persianHtml, /از پیکسل تا محصول/);
|
|
assert.match(persianHtml, /بهمن ۱۴۰۴ تا امروز/);
|
|
assert.match(persianHtml, /آبان ۱۴۰۳ تا امروز/);
|
|
});
|
|
|
|
test('Persian source copy uses standard characters and punctuation', async () => {
|
|
const localizedFiles = [
|
|
'src/i18n/content.ts',
|
|
'src/data/projects.ts',
|
|
'src/data/experience.ts',
|
|
'src/data/education.ts',
|
|
'src/data/milestones.ts',
|
|
];
|
|
const source = (
|
|
await Promise.all(localizedFiles.map((file) => readFile(file, 'utf8')))
|
|
).join('\n');
|
|
|
|
assert.doesNotMatch(source, /[يك]/, 'use Persian ی and ک instead of Arabic forms');
|
|
assert.doesNotMatch(source, /[—–]/, 'use Persian punctuation instead of em/en dashes');
|
|
});
|