Skip to content

Commit 1dccdc2

Browse files
committed
feat: add more tests for optionDescriptions
1 parent 1282e8f commit 1dccdc2

File tree

2 files changed

+66
-2
lines changed

2 files changed

+66
-2
lines changed

src/node/cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ type OptionType<T> = T extends boolean
120120
? "string[]"
121121
: "unknown"
122122

123-
type Options<T> = {
123+
export type Options<T> = {
124124
[P in keyof T]: Option<OptionType<T[P]>>
125125
}
126126

@@ -235,7 +235,7 @@ export const options: Options<Required<UserProvidedArgs>> = {
235235
},
236236
}
237237

238-
export const optionDescriptions = (opts = options): string[] => {
238+
export const optionDescriptions = (opts: Partial<Options<Required<UserProvidedArgs>>> = options): string[] => {
239239
const entries = Object.entries(opts).filter(([, v]) => !!v.description)
240240
const widths = entries.reduce(
241241
(prev, [k, v]) => ({

test/unit/node/cli.test.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import {
1515
toVsCodeArgs,
1616
optionDescriptions,
1717
options,
18+
Options,
19+
AuthType,
20+
OptionalString,
1821
} from "../../../src/node/cli"
1922
import { shouldSpawnCliProcess } from "../../../src/node/main"
2023
import { generatePassword, paths } from "../../../src/node/util"
@@ -787,4 +790,65 @@ describe("optionDescriptions", () => {
787790
expect(exists).toBeTruthy()
788791
})
789792
})
793+
it("should visually align multiple options", () => {
794+
const opts: Partial<Options<Required<UserProvidedArgs>>> = {
795+
"cert-key": { type: "string", path: true, description: "Path to certificate key when using non-generated cert." },
796+
"cert-host": {
797+
type: "string",
798+
description: "Hostname to use when generating a self signed certificate.",
799+
},
800+
"disable-update-check": {
801+
type: "boolean",
802+
description:
803+
"Disable update check. Without this flag, code-server checks every 6 hours against the latest github release and \n" +
804+
"then notifies you once every week that a new release is available.",
805+
},
806+
}
807+
expect(optionDescriptions(opts)).toStrictEqual([
808+
" --cert-key Path to certificate key when using non-generated cert.",
809+
" --cert-host Hostname to use when generating a self signed certificate.",
810+
` --disable-update-check Disable update check. Without this flag, code-server checks every 6 hours against the latest github release and
811+
then notifies you once every week that a new release is available.`,
812+
])
813+
})
814+
it("should add all valid options for enumerated types", () => {
815+
const opts: Partial<Options<Required<UserProvidedArgs>>> = {
816+
auth: { type: AuthType, description: "The type of authentication to use." },
817+
}
818+
expect(optionDescriptions(opts)).toStrictEqual([" --auth The type of authentication to use. [password, none]"])
819+
})
820+
821+
it("should show if an option is deprecated", () => {
822+
const opts: Partial<Options<Required<UserProvidedArgs>>> = {
823+
link: {
824+
type: OptionalString,
825+
description: `
826+
Securely bind code-server via our cloud service with the passed name. You'll get a URL like
827+
https://hostname-username.coder.co at which you can easily access your code-server instance.
828+
Authorization is done via GitHub.
829+
`,
830+
deprecated: true,
831+
},
832+
}
833+
expect(optionDescriptions(opts)).toStrictEqual([
834+
` --link (deprecated) Securely bind code-server via our cloud service with the passed name. You'll get a URL like
835+
https://hostname-username.coder.co at which you can easily access your code-server instance.
836+
Authorization is done via GitHub.`,
837+
])
838+
})
839+
840+
it("should show newlines in description", () => {
841+
const opts: Partial<Options<Required<UserProvidedArgs>>> = {
842+
"install-extension": {
843+
type: "string[]",
844+
description:
845+
"Install or update a VS Code extension by id or vsix. The identifier of an extension is `${publisher}.${name}`.\n" +
846+
"To install a specific version provide `@${version}`. For example: '[email protected]'.",
847+
},
848+
}
849+
expect(optionDescriptions(opts)).toStrictEqual([
850+
` --install-extension Install or update a VS Code extension by id or vsix. The identifier of an extension is \`\${publisher}.\${name}\`.
851+
To install a specific version provide \`@\${version}\`. For example: '[email protected]'.`,
852+
])
853+
})
790854
})

0 commit comments

Comments
 (0)