Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(testing): add test for optionDescriptions #4970

Merged
merged 4 commits into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ type Options<T> = {
[P in keyof T]: Option<OptionType<T[P]>>
}

const options: Options<Required<UserProvidedArgs>> = {
export const options: Options<Required<UserProvidedArgs>> = {
auth: { type: AuthType, description: "The type of authentication to use." },
password: {
type: "string",
Expand Down
35 changes: 35 additions & 0 deletions test/unit/node/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
shouldOpenInExistingInstance,
splitOnFirstEquals,
toVsCodeArgs,
optionDescriptions,
options,
} from "../../../src/node/cli"
import { shouldSpawnCliProcess } from "../../../src/node/main"
import { generatePassword, paths } from "../../../src/node/util"
Expand Down Expand Up @@ -753,3 +755,36 @@ describe("toVsCodeArgs", () => {
})
})
})

describe("optionDescriptions", () => {
it("should return the descriptions of all the available options", () => {
const expectedOptionDescriptions = Object.entries(options)
.flat()
.filter((item: any) => {
if (item.description) {
return item.description
}
})
.map((item: any) => item.description)
const actualOptionDescriptions = optionDescriptions()
// We need both the expected and the actual
// Both of these are string[]
// We then loop through the expectedOptionDescriptions
// and check that this expectedDescription exists in the
// actualOptionDescriptions

// To do that we need to loop through actualOptionDescriptions
// and make sure we have a substring match
expectedOptionDescriptions.forEach((expectedDescription) => {
const exists = actualOptionDescriptions.find((desc) => {
if (
desc.replace(/\n/g, " ").replace(/ /g, "").includes(expectedDescription.replace(/\n/g, " ").replace(/ /g, ""))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙈 Not proud of this line here but we replace line breaks with spaces, then remove spaces.

) {
return true
}
return false
})
expect(exists).toBeTruthy()
})
})
})