50 lines
1.8 KiB
JavaScript
50 lines
1.8 KiB
JavaScript
import { test, expect } from 'bun:test';
|
|
import { readFileSync } from 'fs';
|
|
import { join } from 'path';
|
|
import { parseBuildManifest, getBuildManifestPath } from '../../parser/manifests.js';
|
|
|
|
function loadTestFile(filename) {
|
|
const path = join(process.cwd(), '..', 'test', 'src', filename);
|
|
return readFileSync(path, 'utf-8');
|
|
}
|
|
|
|
test('parseBuildManifest parses valid manifest', () => {
|
|
const script = loadTestFile('nextjs_org_4mSOwJptzzPemGzzI8AOo_buildManifest.js');
|
|
const manifest = parseBuildManifest(script);
|
|
expect(manifest).not.toBeNull();
|
|
expect(typeof manifest).toBe('object');
|
|
});
|
|
|
|
test('parseBuildManifest throws on invalid manifest', () => {
|
|
const script = 'invalid manifest';
|
|
expect(() => parseBuildManifest(script)).toThrow('Invalid build manifest');
|
|
});
|
|
|
|
test('parseBuildManifest parses swag.live manifest', () => {
|
|
const script = loadTestFile('swag_live_giz3a1H7OUzfxgxRHIdMx_buildManifest.js');
|
|
const manifest = parseBuildManifest(script);
|
|
expect(manifest).not.toBeNull();
|
|
expect(typeof manifest).toBe('object');
|
|
});
|
|
|
|
test('parseBuildManifest parses runpod.io manifest', () => {
|
|
const script = loadTestFile('runpod_io_s4xe_TFYlTTFF_bw1HfD4_buildManifest.js');
|
|
const manifest = parseBuildManifest(script);
|
|
expect(manifest).not.toBeNull();
|
|
expect(typeof manifest).toBe('object');
|
|
});
|
|
|
|
test('getBuildManifestPath generates correct path', () => {
|
|
const path = getBuildManifestPath('abc123');
|
|
expect(path).toBe('/_next/static/abc123/_buildManifest.js');
|
|
});
|
|
|
|
test('getBuildManifestPath with base path', () => {
|
|
const path = getBuildManifestPath('abc123', '/base');
|
|
expect(path).toBe('/base/_next/static/abc123/_buildManifest.js');
|
|
});
|
|
|
|
test('getBuildManifestPath with empty base path', () => {
|
|
const path = getBuildManifestPath('abc123', '');
|
|
expect(path).toBe('/_next/static/abc123/_buildManifest.js');
|
|
});
|