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

Conversation

jsjoeio
Copy link
Contributor

@jsjoeio jsjoeio commented Mar 9, 2022

This PR adds a test for optionDescriptions.

Fixes #4915

@jsjoeio jsjoeio added the testing Anything related to testing label Mar 9, 2022
@jsjoeio jsjoeio requested a review from a team March 9, 2022 22:27
@jsjoeio jsjoeio self-assigned this Mar 9, 2022
@jsjoeio jsjoeio linked an issue Mar 9, 2022 that may be closed by this pull request
@jsjoeio jsjoeio temporarily deployed to CI March 9, 2022 22:27 Inactive
@jsjoeio jsjoeio temporarily deployed to npm March 9, 2022 22:36 Inactive
@codecov
Copy link

codecov bot commented Mar 9, 2022

Codecov Report

Merging #4970 (6afc87b) into main (77296c7) will increase coverage by 0.89%.
The diff coverage is 100.00%.

❗ Current head 6afc87b differs from pull request most recent head 64e5bb0. Consider uploading reports for the commit 64e5bb0 to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4970      +/-   ##
==========================================
+ Coverage   70.56%   71.45%   +0.89%     
==========================================
  Files          29       29              
  Lines        1678     1678              
  Branches      372      373       +1     
==========================================
+ Hits         1184     1199      +15     
+ Misses        420      408      -12     
+ Partials       74       71       -3     
Impacted Files Coverage Δ
src/node/cli.ts 91.60% <100.00%> (+5.72%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 77296c7...64e5bb0. Read the comment docs.

@github-actions
Copy link

github-actions bot commented Mar 9, 2022

✨ code-server docs for PR #4970 is ready! It will be updated on every commit.

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.

Copy link
Member

@code-asher code-asher left a comment

Choose a reason for hiding this comment

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

What do you think about making optionDescriptions take an argument so we can test specific expectations? And possibly adding optionDescription so we can test a single option without having to wrap it in an array. nvm it needs to take an array of options otherwise it cannot align them so a single-option function is pretty much useless

For example:

it("should display option flag and description", () => {
  expect(optionDescriptions([{ type: "boolean": long: "foo", short: "f", description: "a foo flag")}]).toStrictEqual("-f --foo a foo flag")
})

it("should visually align multiple options", () => {
  const options = [
    { type: "boolean": long: "foo", short: "f", description: "a foo flag"}
    { type: "string": short: "r", description: "an r flag"}
    { type: "string[]": long: "somethingquitelong"}
  ]
  expect(optionDescriptions(options)).toStrictEqual([
    "-f --foo                a foo flag",
    "-r                      an r flag"
    "   --somethingquitelong"
  ].join("\n")
})

it("should add all valid options for enumerated types", () => {
  expect(optionDescriptions([{ type: AuthType: long: "auth", description: "some auth")}]).toStrictEqual("   --foo some auth [password, none]")
})

it("should show if an option is deprecated")

it("should show newlines in description")

@jsjoeio
Copy link
Contributor Author

jsjoeio commented Mar 10, 2022

@code-asher okay to be extra clear, you're saying I should do this:

What do you think about making optionDescriptions take an argument so we can test specific expectations?

and not do this:

single-option function is pretty much useless

right?

@code-asher
Copy link
Member

Yes!

@jsjoeio jsjoeio requested a review from code-asher March 11, 2022 19:16
@jsjoeio jsjoeio temporarily deployed to npm March 11, 2022 19:25 Inactive
Copy link
Member

@code-asher code-asher left a comment

Choose a reason for hiding this comment

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

Nicely done!

@jsjoeio jsjoeio merged commit 91cabbc into main Mar 11, 2022
@jsjoeio jsjoeio deleted the 4915-testing-write-tests-for-optiondescriptions branch March 11, 2022 20:27
TinLe pushed a commit to TinLe/code-server that referenced this pull request Apr 23, 2022
* feat(testing): add test for optionDescriptions

* refactor(cli): optional arg in optionDescriptions

* feat: add more tests for optionDescriptions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing Anything related to testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Testing]: write tests for optionDescriptions
2 participants