Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
HerrCai0907 committed Nov 17, 2023
1 parent c6b89b9 commit 48c46be
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,15 @@
"build": "node scripts/build",
"watch": "node scripts/build --watch",
"coverage": "npx c8 -- npm test",
"test": "npm run test:parser && npm run test:compiler -- --parallel && npm run test:browser && npm run test:asconfig && npm run test:transform",
"test": "npm run test:parser && npm run test:compiler -- --parallel && npm run test:browser && npm run test:asconfig && npm run test:transform && npm run test:utils",
"test:parser": "node --enable-source-maps tests/parser",
"test:compiler": "node --enable-source-maps --no-warnings tests/compiler",
"test:browser": "node --enable-source-maps tests/browser",
"test:asconfig": "cd tests/asconfig && npm run test",
"test:transform": "npm run test:transform:esm && npm run test:transform:cjs",
"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",
"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",
"test:utils": "node tests/cli/options.js",
"asbuild": "npm run asbuild:debug && npm run asbuild:release",
"asbuild:debug": "node bin/asc --config src/asconfig.json --target debug",
"asbuild:release": "node bin/asc --config src/asconfig.json --target release",
Expand Down
42 changes: 23 additions & 19 deletions tests/cli/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@ import assert from "assert";
import * as optionsUtil from "../../util/options.js";

const config = {
"enable": {
"type": "S",
"mutuallyExclusive": "disable"
enable: {
type: "S",
mutuallyExclusive: "disable",
},
"disable": {
"type": "S",
"mutuallyExclusive": "enable"
disable: {
type: "S",
mutuallyExclusive: "enable",
},
other: {
type: "S",
default: ["x"],
},
bool_input_for_string: {
type: "s",
},
"other": {
"type": "S",
"default": ["x"]
}
};

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

// Populating defaults should work after the fact
optionsUtil.addDefaults(config, merged = {});
optionsUtil.addDefaults(config, (merged = {}));
assert.deepStrictEqual(merged.other, ["x"]);

optionsUtil.addDefaults(config, merged = { other: ["y"] });
optionsUtil.addDefaults(config, (merged = { other: ["y"] }));
assert.deepStrictEqual(merged.other, ["y"]);

// String test
assert.deepStrictEqual(merged.bool_input_for_string, undefined);
merged = optionsUtil.merge(config, {}, { bool_input_for_string: false });
assert.deepStrictEqual(merged.bool_input_for_string, undefined);
merged = optionsUtil.merge(config, {}, { bool_input_for_string: true });
assert.deepStrictEqual(merged.bool_input_for_string, "");

// Complete usage test
let result = optionsUtil.parse([
"--enable", "a",
"--disable", "b",
], config, false);
let result = optionsUtil.parse(["--enable", "a", "--disable", "b"], config, false);

merged = optionsUtil.merge(config, result.options, { enable: ["b", "c"] });
merged = optionsUtil.merge(config, merged, { disable: ["a", "d"] });
Expand All @@ -52,6 +59,3 @@ optionsUtil.addDefaults(config, merged);
assert.deepStrictEqual(merged.enable, ["a", "c"]);
assert.deepStrictEqual(merged.disable, ["b", "d"]);
assert.deepStrictEqual(merged.other, ["x"]);

let value = optionsUtil.sanitizeValue(false, "s");
assert.deepStrictEqual(value, null);
3 changes: 0 additions & 3 deletions util/options.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,3 @@ export function resolvePath(path: string, baseDir: string, useNodeResolution?: b

/** Populates default values on a parsed options result. */
export function addDefaults(config: Config, options: OptionSet): void;

/** Sanitizes an option value to be a valid value of the option's type. */
export function sanitizeValue(value: any, type: string): boolean | number | string | null | number[] | string[]; // eslint-disable-line @typescript-eslint/no-explicit-any
2 changes: 1 addition & 1 deletion util/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export function help(config, options) {
}

/** Sanitizes an option value to be a valid value of the option's type. */
export function sanitizeValue(value, type) {
function sanitizeValue(value, type) {
if (value != null) {
switch (type) {
case undefined:
Expand Down

0 comments on commit 48c46be

Please sign in to comment.