Files
doodle-store/apps/server/test/runtime-options.test.ts
T

28 lines
773 B
TypeScript

import assert from 'node:assert/strict';
import { test } from 'node:test';
import { getRuntimeOptions } from '../src/common/runtime-options';
test('使用本地默认 host 和 port', () => {
assert.deepEqual(getRuntimeOptions({}), {
host: '127.0.0.1',
port: 8800,
});
});
test('读取显式 host 和 port', () => {
assert.deepEqual(getRuntimeOptions({ HOST: '0.0.0.0', PORT: '4000' }), {
host: '0.0.0.0',
port: 4000,
});
});
test('拒绝非法端口', () => {
for (const port of ['', '0', '65536', '-1', '3000abc', '3.5', '1e3']) {
assert.throws(() => getRuntimeOptions({ PORT: port }), /PORT/);
}
});
test('拒绝空 host', () => {
assert.throws(() => getRuntimeOptions({ HOST: ' ' }), /HOST/);
});