Skip to content

Commit 39fc99d

Browse files
committed
feat(testing): add test for optionDescriptions
1 parent 03e0bda commit 39fc99d

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/node/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ type Options<T> = {
124124
[P in keyof T]: Option<OptionType<T[P]>>
125125
}
126126

127-
const options: Options<Required<UserProvidedArgs>> = {
127+
export const options: Options<Required<UserProvidedArgs>> = {
128128
auth: { type: AuthType, description: "The type of authentication to use." },
129129
password: {
130130
type: "string",

test/unit/node/cli.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import {
1313
shouldOpenInExistingInstance,
1414
splitOnFirstEquals,
1515
toVsCodeArgs,
16+
optionDescriptions,
17+
options,
1618
} from "../../../src/node/cli"
1719
import { shouldSpawnCliProcess } from "../../../src/node/main"
1820
import { generatePassword, paths } from "../../../src/node/util"
@@ -753,3 +755,36 @@ describe("toVsCodeArgs", () => {
753755
})
754756
})
755757
})
758+
759+
describe("optionDescriptions", () => {
760+
it("should return the descriptions of all the available options", () => {
761+
const expectedOptionDescriptions = Object.entries(options)
762+
.flat()
763+
.filter((item: any) => {
764+
if (item.description) {
765+
return item.description
766+
}
767+
})
768+
.map((item: any) => item.description)
769+
const actualOptionDescriptions = optionDescriptions()
770+
// We need both the expected and the actual
771+
// Both of these are string[]
772+
// We then loop through the expectedOptionDescriptions
773+
// and check that this expectedDescription exists in the
774+
// actualOptionDescriptions
775+
776+
// To do that we need to loop through actualOptionDescriptions
777+
// and make sure we have a substring match
778+
expectedOptionDescriptions.forEach((expectedDescription) => {
779+
const exists = actualOptionDescriptions.find((desc) => {
780+
if (
781+
desc.replace(/\n/g, " ").replace(/ /g, "").includes(expectedDescription.replace(/\n/g, " ").replace(/ /g, ""))
782+
) {
783+
return true
784+
}
785+
return false
786+
})
787+
expect(exists).toBeTruthy()
788+
})
789+
})
790+
})

0 commit comments

Comments
 (0)