Files
my-protfolio/tests/performance-architecture.test.mjs
Amirhossein Khalili f34bea05cd
Some checks failed
Test and deploy / Verify production build (push) Has been cancelled
Test and deploy / Deploy production (push) Has been cancelled
perf: optimize portfolio runtime delivery
Replace the blocking asset loader with progressive rendering, defer expensive media and Three.js work, and reduce hydration and animation costs. Move deployment from a static Nginx export to the standalone Next.js runtime with optimized dynamic images.
2026-09-09 12:43:37 +03:30

49 lines
1.8 KiB
JavaScript

import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import test from 'node:test';
test('Next runs as a standalone server with the image optimizer enabled', async () => {
const [config, packageJson] = await Promise.all([
readFile('next.config.mjs', 'utf8'),
readFile('package.json', 'utf8').then(JSON.parse),
]);
assert.match(config, /output:\s*['"]standalone['"]/);
assert.doesNotMatch(config, /unoptimized:\s*true/);
assert.match(config, /formats:\s*\[['"]image\/webp['"]\]/);
assert.match(config, /qualities:\s*\[60,\s*75,\s*85\]/);
assert.ok(packageJson.dependencies.sharp, 'sharp must be a direct production dependency');
});
test('the blocking loader and eager preload manifest are removed', async () => {
const [root, page] = await Promise.all([
readFile('src/app/SiteRoot.tsx', 'utf8'),
readFile('src/app/PortfolioPage.tsx', 'utf8'),
]);
assert.doesNotMatch(root, /siteLoading|site-loader/);
assert.doesNotMatch(page, /SiteLoader/);
});
test('Three.js is only imported by the deferred scene implementation', async () => {
const [boundary, scene] = await Promise.all([
readFile('src/components/scenes/DeferredAboutRiverScene.tsx', 'utf8'),
readFile('src/components/scenes/AboutRiverScene.tsx', 'utf8'),
]);
assert.doesNotMatch(boundary, /from ['"]three['"]/);
assert.match(boundary, /import\(['"].\/AboutRiverScene['"]\)/);
assert.match(boundary, /rootMargin:\s*['"]600px/);
assert.match(scene, /from ['"]three['"]/);
});
test('local font loading replaces remote CSS imports and TTF delivery', async () => {
const [root, css] = await Promise.all([
readFile('src/app/SiteRoot.tsx', 'utf8'),
readFile('src/styles/globals.css', 'utf8'),
]);
assert.match(root, /localFont/);
assert.doesNotMatch(css, /fonts\.googleapis\.com|@font-face|IRANYekanXVF\.ttf/);
});