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

Fix help text indentation #4531

Merged
merged 4 commits into from Jan 10, 2020
Merged

Fix help text indentation #4531

merged 4 commits into from Jan 10, 2020

Conversation

ybiquitous
Copy link
Member

@ybiquitous ybiquitous commented Jan 9, 2020

Because of TAB included in some lines, help text indentation is broken. This fixes the bug.

Two commits included:

  1. Check the current help text on system tests.
  2. Fix the help text.

Please compare the diff between each commit.

image

@ybiquitous ybiquitous marked this pull request as ready for review January 9, 2020 14:04
@hudochenkov
Copy link
Member

I would say having expectedHelp.txt is inconvenient because as soon we change text in a code we have to update the test. It makes that test a chore and don't really help.

Can we just update --help test so it verify that no tabs present in a help text?

@ybiquitous
Copy link
Member Author

@hudochenkov I understand what you say, but I'd like to test a broken indentation, not to test including TABs.

Also, I have the following reasons to test the help text:

  • I'd like to prevent an unexpected regression when we refactor cli.js. I have a plan to refactor cli.js for better type-checking on other PRs.
  • I think that the chore task updating expectedHelp.txt will rarely occur. Because we have changed rarely the help text content itself.

What do you think? I'm glad to accept if there is a better way! 😄

@ntwb
Copy link
Member

ntwb commented Jan 10, 2020

How about using the new Jest "inline snapsot" functionality instead?

https://jestjs.io/docs/en/snapshot-testing#inline-snapshots
"Inline snapshots behave identically to external snapshots (.snap files), except the snapshot values are written automatically back into the source code. This means you can get the benefits of automatically generated snapshots without having to switch to an external file to make sure the correct value was written."

@ybiquitous
Copy link
Member Author

@ntwb Thanks, looks good. But I'm unfamiliar with the functionality. If you can change soon, welcome to push your change to this PR! 🙌

@ybiquitous
Copy link
Member Author

I pushed e9ce817 using .toMatchInlineSnapshot(). Thank you @ntwb!

@hudochenkov How about this?

@vankop
Copy link
Member

vankop commented Jan 10, 2020

Looks like we need ability to generate help text =)

@ybiquitous Unfortunately this test does not make much sense, since it is just a copy paste.

From my perspective we need move each option description in meow settings aka:

const options = {
    'formatter': {
          description: `allowed formatters ${getFormatterOptionsText({ useOr: true })}`,
          default: 'string'
    },
    'no-color': {
         description: 'blabla'
    }
}

options.help = generateHelp(options);

@hudochenkov
Copy link
Member

.toMatchInlineSnapshot() is better, but it takes too much space in test file. Maybe we should use regular snapshots instead (toMatchSnapshot)?

@ybiquitous
Copy link
Member Author

@vankop Thanks for your feedback. The snapshot value is automatically generated when we run the test, so I don't think it's just a copy-paste.

generateHelp() sounds like an attractive idea to me but I think the idea is out of the scope of this PR.

@ybiquitous
Copy link
Member Author

@hudochenkov I can accept also toMatchSnapshot(), but don't we give up the auto-generation of a snapshot value?

@hudochenkov
Copy link
Member

@ybiquitous regular snapshot are generated by Jest. If snapshot doesn't match, we can tell Jest to update it. Shapshots are not supposed to be changed manually.

@ybiquitous
Copy link
Member Author

Make sense! 👍 I will fix to use toMatchSnapshot() soon.

Copy link
Member

@hudochenkov hudochenkov left a comment

Choose a reason for hiding this comment

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

Thanks!

@ybiquitous
Copy link
Member Author

@hudochenkov Thanks, too. After all approval, I will squash to one commit before merge.

@hudochenkov
Copy link
Member

No need for squashing, I'll do it on merge with a press of a single button :)

@fanich37 fanich37 self-requested a review January 10, 2020 10:01
@ntwb
Copy link
Member

ntwb commented Jan 10, 2020

I was also thinking along the lines of what @vankop wrote above in #4531 (comment)

Instead of testing for the entire output, each cli option could have it's own test to ensure the output of each command would match the test, this could use either toMatchSnapshot() or toMatchInlineSnapshot() and I suggested the inline snapshot as it saves and regenerates inline in the source file rather than another file.

Anyways, not a blocker for this PR, happy to see it merged and this could be considered in a follow up PR. It maybe beneficial to do something like this to improve the cli tests before adding types.

@ybiquitous
Copy link
Member Author

@ntwb Thanks for your reply.

Sadly, meow does not have the auto-generation of help text:
sindresorhus/meow#80

So, we have to write our own code or contribute to meow. There may be based implementation already: sindresorhus/meow#82

I suggested the inline snapshot as it saves and regenerates inline in the source file rather than another file.

If we test each description instead of the whole help text, the inline snapshot may be better. 👍

It maybe beneficial to do something like this to improve the cli tests before adding types.

I completely agree. 😃

@vankop
Copy link
Member

vankop commented Jan 10, 2020

I suggested the inline snapshot as it saves and regenerates inline in the source file rather than another file.

Damn it behave so unobviously =( I thought that @ybiquitous copy paste help info 🤦‍♂️ Maybe better to keep snapshots as separated files

@hudochenkov hudochenkov merged commit 18b1f99 into master Jan 10, 2020
@hudochenkov hudochenkov deleted the fix-help-text-indentation branch January 10, 2020 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants