mirror of
https://github.com/dromara/hertzbeat.git
synced 2026-10-02 05:59:03 +00:00
Refine entity, monitor, alert, settings, observability, and shared operator workflows; add scale guards, route compatibility, release validation, and Product Design coverage. AI assistance: used for draft implementation and test iteration.\nHuman validation: Node 22 production build; 426 frontend files and 3,398 tests; 59-route matrix; release budget 7.84 MiB / 8.00 MiB; focused backend tests and Browser QA.\nRisk notes: local scale proof covers 2,005 entities; sustained concurrent-ingestion SLA remains deployment-specific.
55 lines
2.0 KiB
TypeScript
55 lines
2.0 KiB
TypeScript
import { mkdir, mkdtemp, writeFile } from 'node:fs/promises';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
import {
|
|
parseStartArgs,
|
|
prepareStandaloneAssets,
|
|
resolveStandalonePaths
|
|
} from './standalone-server.mjs';
|
|
|
|
describe('standalone-server', () => {
|
|
const originalDistDir = process.env.NEXT_DIST_DIR;
|
|
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
if (originalDistDir === undefined) {
|
|
delete process.env.NEXT_DIST_DIR;
|
|
} else {
|
|
process.env.NEXT_DIST_DIR = originalDistDir;
|
|
}
|
|
});
|
|
|
|
it('keeps npm start port flags compatible with the previous next start command', () => {
|
|
expect(parseStartArgs(['-p', '4300'], {})).toEqual({
|
|
port: '4300',
|
|
hostname: '0.0.0.0'
|
|
});
|
|
expect(parseStartArgs(['--port=4400', '--host', '127.0.0.1'], {})).toEqual({
|
|
port: '4400',
|
|
hostname: '127.0.0.1'
|
|
});
|
|
expect(parseStartArgs([], { PORT: '4500', HOSTNAME: '127.0.0.2' })).toEqual({
|
|
port: '4500',
|
|
hostname: '127.0.0.2'
|
|
});
|
|
});
|
|
|
|
it('copies public and next static assets into the standalone app tree', async () => {
|
|
const root = await mkdtemp(path.join(os.tmpdir(), 'hertzbeat-standalone-'));
|
|
await mkdir(path.join(root, 'public'), { recursive: true });
|
|
await mkdir(path.join(root, '.next', 'static', 'chunks'), { recursive: true });
|
|
await mkdir(path.join(root, '.next', 'standalone', 'web-next'), { recursive: true });
|
|
await writeFile(path.join(root, 'public', 'placeholder'), '');
|
|
await writeFile(path.join(root, '.next', 'static', 'chunks', 'main.js'), 'console.log("ready");');
|
|
await writeFile(path.join(root, '.next', 'standalone', 'web-next', 'server.js'), 'server');
|
|
|
|
const result = await prepareStandaloneAssets(root);
|
|
|
|
expect(result.copiedStatic).toBe(true);
|
|
expect(result.copiedPublic).toBe(true);
|
|
expect(resolveStandalonePaths(root).targetStaticDir).toBe(path.join(root, '.next', 'standalone', 'web-next', '.next', 'static'));
|
|
});
|
|
});
|