Files
ChuSQL/chusql-web/frontend/bin/lib/args.test.js
T

18 lines
771 B
JavaScript
Raw Normal View History

2026-09-25 17:41:51 +08:00
import { describe, expect, it } from 'vitest';
import { parseArgs } from './args.js';
// 覆盖 CLI 参数解析与非法取值拒绝。
describe('parseArgs', () => {
it('parses command-specific and global options', () => {
expect(parseArgs(['web', '--port', '9000', '--no-open', '--adapter', 'rest'])).toMatchObject({
command: 'web', port: 9000, autoOpenBrowser: false, adapter: 'rest',
});
});
it('rejects unsafe or invalid values', () => {
expect(() => parseArgs(['web', '--port', 'nope'])).toThrow('Port must be an integer');
expect(() => parseArgs(['web', '--host', 'x & calc'])).toThrow('Host contains invalid characters');
expect(() => parseArgs(['web', '--adapter', 'other'])).toThrow('Adapter must be mock or rest');
});
});