Skip to content

Commit a52144d

Browse files
committed
update test
1 parent c6b89b9 commit a52144d

File tree

4 files changed

+26
-24
lines changed

4 files changed

+26
-24
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,15 @@
7777
"build": "node scripts/build",
7878
"watch": "node scripts/build --watch",
7979
"coverage": "npx c8 -- npm test",
80-
"test": "npm run test:parser && npm run test:compiler -- --parallel && npm run test:browser && npm run test:asconfig && npm run test:transform",
80+
"test": "npm run test:parser && npm run test:compiler -- --parallel && npm run test:browser && npm run test:asconfig && npm run test:transform && test:utils",
8181
"test:parser": "node --enable-source-maps tests/parser",
8282
"test:compiler": "node --enable-source-maps --no-warnings tests/compiler",
8383
"test:browser": "node --enable-source-maps tests/browser",
8484
"test:asconfig": "cd tests/asconfig && npm run test",
8585
"test:transform": "npm run test:transform:esm && npm run test:transform:cjs",
8686
"test:transform:esm": "node bin/asc tests/compiler/empty --transform ./tests/transform/index.js --noEmit && node bin/asc tests/compiler/empty --transform ./tests/transform/simple.js --noEmit",
8787
"test:transform:cjs": "node bin/asc tests/compiler/empty --transform ./tests/transform/cjs/index.js --noEmit && node bin/asc tests/compiler/empty --transform ./tests/transform/cjs/simple.js --noEmit",
88+
"test:utils": "node tests/cli/options.js",
8889
"asbuild": "npm run asbuild:debug && npm run asbuild:release",
8990
"asbuild:debug": "node bin/asc --config src/asconfig.json --target debug",
9091
"asbuild:release": "node bin/asc --config src/asconfig.json --target release",

tests/cli/options.js

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@ import assert from "assert";
22
import * as optionsUtil from "../../util/options.js";
33

44
const config = {
5-
"enable": {
6-
"type": "S",
7-
"mutuallyExclusive": "disable"
5+
enable: {
6+
type: "S",
7+
mutuallyExclusive: "disable",
88
},
9-
"disable": {
10-
"type": "S",
11-
"mutuallyExclusive": "enable"
9+
disable: {
10+
type: "S",
11+
mutuallyExclusive: "enable",
12+
},
13+
other: {
14+
type: "S",
15+
default: ["x"],
16+
},
17+
bool_input_for_string: {
18+
type: "s",
1219
},
13-
"other": {
14-
"type": "S",
15-
"default": ["x"]
16-
}
1720
};
1821

1922
// Present in both should concat
@@ -33,17 +36,21 @@ assert.deepStrictEqual(merged.enable, ["c"]);
3336
assert.deepStrictEqual(merged.disable, ["a", "b"]);
3437

3538
// Populating defaults should work after the fact
36-
optionsUtil.addDefaults(config, merged = {});
39+
optionsUtil.addDefaults(config, (merged = {}));
3740
assert.deepStrictEqual(merged.other, ["x"]);
3841

39-
optionsUtil.addDefaults(config, merged = { other: ["y"] });
42+
optionsUtil.addDefaults(config, (merged = { other: ["y"] }));
4043
assert.deepStrictEqual(merged.other, ["y"]);
4144

45+
// String test
46+
assert.deepStrictEqual(merged.bool_input_for_string, undefined);
47+
merged = optionsUtil.merge(config, {}, { bool_input_for_string: false });
48+
assert.deepStrictEqual(merged.bool_input_for_string, undefined);
49+
merged = optionsUtil.merge(config, {}, { bool_input_for_string: true });
50+
assert.deepStrictEqual(merged.bool_input_for_string, "");
51+
4252
// Complete usage test
43-
let result = optionsUtil.parse([
44-
"--enable", "a",
45-
"--disable", "b",
46-
], config, false);
53+
let result = optionsUtil.parse(["--enable", "a", "--disable", "b"], config, false);
4754

4855
merged = optionsUtil.merge(config, result.options, { enable: ["b", "c"] });
4956
merged = optionsUtil.merge(config, merged, { disable: ["a", "d"] });
@@ -52,6 +59,3 @@ optionsUtil.addDefaults(config, merged);
5259
assert.deepStrictEqual(merged.enable, ["a", "c"]);
5360
assert.deepStrictEqual(merged.disable, ["b", "d"]);
5461
assert.deepStrictEqual(merged.other, ["x"]);
55-
56-
let value = optionsUtil.sanitizeValue(false, "s");
57-
assert.deepStrictEqual(value, null);

util/options.d.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,3 @@ export function resolvePath(path: string, baseDir: string, useNodeResolution?: b
6868

6969
/** Populates default values on a parsed options result. */
7070
export function addDefaults(config: Config, options: OptionSet): void;
71-
72-
/** Sanitizes an option value to be a valid value of the option's type. */
73-
export function sanitizeValue(value: any, type: string): boolean | number | string | null | number[] | string[]; // eslint-disable-line @typescript-eslint/no-explicit-any

util/options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export function help(config, options) {
141141
}
142142

143143
/** Sanitizes an option value to be a valid value of the option's type. */
144-
export function sanitizeValue(value, type) {
144+
function sanitizeValue(value, type) {
145145
if (value != null) {
146146
switch (type) {
147147
case undefined:

0 commit comments

Comments
 (0)