Skip to content

Commit 276cf3b

Browse files
committed
create a util function that normalizes and set default options
1 parent 11eed01 commit 276cf3b

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { type Options } from "../../types.ts";
2+
import { normalizeOptions, type NormalizedOptions } from "../normalizeOptions";
3+
4+
interface Test {
5+
name: string;
6+
input: {
7+
options: Options;
8+
};
9+
expected: NormalizedOptions;
10+
}
11+
12+
const tests: Test[] = [
13+
{
14+
name: "sets default values",
15+
input: {
16+
options: {},
17+
},
18+
expected: {
19+
telemetry: true,
20+
apiUrl: "https://api.codecov.io",
21+
dryRun: false,
22+
},
23+
},
24+
{
25+
name: "can override default values",
26+
input: {
27+
options: {
28+
apiUrl: "https://api.example.com",
29+
dryRun: true,
30+
telemetry: false,
31+
},
32+
},
33+
expected: {
34+
telemetry: false,
35+
apiUrl: "https://api.example.com",
36+
dryRun: true,
37+
},
38+
},
39+
];
40+
41+
describe("normalizeOptions", () => {
42+
it.each(tests)("$name", ({ input, expected }) => {
43+
const expectation = normalizeOptions(input.options);
44+
expect(expectation).toEqual(expected);
45+
});
46+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { type Options } from "../types.ts";
2+
3+
export type NormalizedOptions = ReturnType<typeof normalizeOptions>;
4+
5+
export const normalizeOptions = (userOptions: Options) => {
6+
const options = {
7+
...userOptions,
8+
telemetry: userOptions.telemetry ?? true,
9+
apiUrl: userOptions.apiUrl ?? "https://api.codecov.io",
10+
dryRun: userOptions.dryRun ?? false,
11+
};
12+
13+
return options;
14+
};

0 commit comments

Comments
 (0)