-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathutils.test.ts
More file actions
85 lines (78 loc) · 2.28 KB
/
utils.test.ts
File metadata and controls
85 lines (78 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
* @license
* Copyright 2026 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import assert from 'node:assert';
import {describe, it} from 'node:test';
import type {ParsedArguments} from '../../src/cli.js';
import {serializeArgs} from '../../src/daemon/utils.js';
import type {YargsOptions} from '../../src/third_party/index.js';
describe('serializeArgs', () => {
it('should ignore undefined or null values', () => {
const options: Record<string, YargsOptions> = {
foo: {},
bar: {},
baz: {},
};
const argv = {
foo: undefined,
bar: null,
baz: 'value',
_: [],
$0: 'test',
} as unknown as ParsedArguments;
const result = serializeArgs(options, argv);
assert.deepStrictEqual(result, ['--baz', 'value']);
});
it('should handle boolean values', () => {
const options: Record<string, YargsOptions> = {foo: {}, bar: {}};
const argv = {
foo: true,
bar: false,
_: [],
$0: 'test',
} as unknown as ParsedArguments;
const result = serializeArgs(options, argv);
assert.deepStrictEqual(result, ['--foo', '--no-bar']);
});
it('should handle array values', () => {
const options: Record<string, YargsOptions> = {foo: {}};
const argv = {
foo: ['val1', 'val2'],
_: [],
$0: 'test',
} as unknown as ParsedArguments;
const result = serializeArgs(options, argv);
assert.deepStrictEqual(result, ['--foo', 'val1', '--foo', 'val2']);
});
it('should handle primitive values', () => {
const options: Record<string, YargsOptions> = {foo: {}, bar: {}};
const argv = {
foo: 'string',
bar: 42,
_: [],
$0: 'test',
} as unknown as ParsedArguments;
const result = serializeArgs(options, argv);
assert.deepStrictEqual(result, ['--foo', 'string', '--bar', '42']);
});
it('should convert camelCase keys to kebab-case', () => {
const options: Record<string, YargsOptions> = {
camelCaseKey: {},
anotherKey: {},
};
const argv = {
camelCaseKey: 'value1',
anotherKey: true,
_: [],
$0: 'test',
} as unknown as ParsedArguments;
const result = serializeArgs(options, argv);
assert.deepStrictEqual(result, [
'--camel-case-key',
'value1',
'--another-key',
]);
});
});