-
Notifications
You must be signed in to change notification settings - Fork 6k
feat(testing): add test for optionDescriptions #4970
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
Merged
jsjoeio
merged 4 commits into
main
from
4915-testing-write-tests-for-optiondescriptions
Mar 11, 2022
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
39fc99d
feat(testing): add test for optionDescriptions
jsjoeio 1282e8f
refactor(cli): optional arg in optionDescriptions
jsjoeio 1dccdc2
feat: add more tests for optionDescriptions
jsjoeio 64e5bb0
Merge branch 'main' into 4915-testing-write-tests-for-optiondescriptions
jsjoeio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,11 @@ import { | |
shouldOpenInExistingInstance, | ||
splitOnFirstEquals, | ||
toVsCodeArgs, | ||
optionDescriptions, | ||
options, | ||
Options, | ||
AuthType, | ||
OptionalString, | ||
} from "../../../src/node/cli" | ||
import { shouldSpawnCliProcess } from "../../../src/node/main" | ||
import { generatePassword, paths } from "../../../src/node/util" | ||
|
@@ -753,3 +758,97 @@ 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, "")) | ||
) { | ||
return true | ||
} | ||
return false | ||
}) | ||
expect(exists).toBeTruthy() | ||
}) | ||
}) | ||
it("should visually align multiple options", () => { | ||
const opts: Partial<Options<Required<UserProvidedArgs>>> = { | ||
"cert-key": { type: "string", path: true, description: "Path to certificate key when using non-generated cert." }, | ||
"cert-host": { | ||
type: "string", | ||
description: "Hostname to use when generating a self signed certificate.", | ||
}, | ||
"disable-update-check": { | ||
type: "boolean", | ||
description: | ||
"Disable update check. Without this flag, code-server checks every 6 hours against the latest github release and \n" + | ||
"then notifies you once every week that a new release is available.", | ||
}, | ||
} | ||
expect(optionDescriptions(opts)).toStrictEqual([ | ||
" --cert-key Path to certificate key when using non-generated cert.", | ||
" --cert-host Hostname to use when generating a self signed certificate.", | ||
` --disable-update-check Disable update check. Without this flag, code-server checks every 6 hours against the latest github release and | ||
then notifies you once every week that a new release is available.`, | ||
]) | ||
}) | ||
it("should add all valid options for enumerated types", () => { | ||
const opts: Partial<Options<Required<UserProvidedArgs>>> = { | ||
auth: { type: AuthType, description: "The type of authentication to use." }, | ||
} | ||
expect(optionDescriptions(opts)).toStrictEqual([" --auth The type of authentication to use. [password, none]"]) | ||
}) | ||
|
||
it("should show if an option is deprecated", () => { | ||
const opts: Partial<Options<Required<UserProvidedArgs>>> = { | ||
link: { | ||
type: OptionalString, | ||
description: ` | ||
Securely bind code-server via our cloud service with the passed name. You'll get a URL like | ||
https://hostname-username.coder.co at which you can easily access your code-server instance. | ||
Authorization is done via GitHub. | ||
`, | ||
deprecated: true, | ||
}, | ||
} | ||
expect(optionDescriptions(opts)).toStrictEqual([ | ||
` --link (deprecated) Securely bind code-server via our cloud service with the passed name. You'll get a URL like | ||
https://hostname-username.coder.co at which you can easily access your code-server instance. | ||
Authorization is done via GitHub.`, | ||
]) | ||
}) | ||
|
||
it("should show newlines in description", () => { | ||
const opts: Partial<Options<Required<UserProvidedArgs>>> = { | ||
"install-extension": { | ||
type: "string[]", | ||
description: | ||
"Install or update a VS Code extension by id or vsix. The identifier of an extension is `${publisher}.${name}`.\n" + | ||
"To install a specific version provide `@${version}`. For example: '[email protected]'.", | ||
}, | ||
} | ||
expect(optionDescriptions(opts)).toStrictEqual([ | ||
` --install-extension Install or update a VS Code extension by id or vsix. The identifier of an extension is \`\${publisher}.\${name}\`. | ||
To install a specific version provide \`@\${version}\`. For example: '[email protected]'.`, | ||
]) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.