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

test: migrate plugin-options-string tests #38

Merged
merged 3 commits into from
Mar 6, 2025

Conversation

43081j
Copy link
Contributor

@43081j 43081j commented Feb 15, 2025

Copies the tests from prettier.

Notable changes:

  • A failed plugin load throws an uncaught exception before this change. This catches it and logs an error to stderr
  • A snapshot-diff package was being used to create a git diff like diff as a jest snapshot. We can pick the unique lines out instead of using this

Skipped tests:

Notable hiccups:

  • Parsing argv seems to fall over on things like --plugin=--foo--, so the test has been changed for now to use --plugin=totally-invalid

@43081j 43081j marked this pull request as ready for review February 15, 2025 21:29
@fabiospampinato
Copy link
Collaborator

A snapshot-diff package was being used to create a git diff like diff as a jest snapshot. We can pick the unique lines out instead of using this

💯

Parsing argv seems to fall over on things like --plugin=--foo--, so the test has been changed for now to use --plugin=totally-invalid

That got fixed in the dependency that parses this stuff. Can you update the PR?

Let me know once the PR is ready to me merged, let's handle the stdin test later, it's tricky.

@43081j 43081j force-pushed the test-plugin-options-string branch 3 times, most recently from 50ec203 to d010dd4 Compare February 23, 2025 15:43
@43081j
Copy link
Contributor Author

43081j commented Feb 23, 2025

this should be all sorted now 👍

@fabiospampinato
Copy link
Collaborator

I'd like to change three things if you don't mind, if you can do them it'd be much quicker to merge this, or I can do these myself once I get a bit more time:

  1. Can we have a getPluginOrExit utility function instead of hard-coding this in bin.ts?
  2. Can we have a getPluginsOrExit that is basically the analogous of getPlugins, and use that instead?
  3. I think we can keep getPlugin and getPlugins even if they are not used, for completeness.
  4. snapshot-diff seems to approximately import the whole universe, so let's not use that, but in the original test we were also testing not only that the help text got updated, but also where the updates happened, and I think it'd be nice to be able to preserve testing for that 🤔 Not a blocker though.

@43081j
Copy link
Contributor Author

43081j commented Feb 23, 2025

i've added getPluginOrExit, but can you clarify what you mean for getPluginsOrExit? (plural)

at the minute we don't exit inside getPlugins since we must've already called getPluginOrExit when starting up

edit: weirdly the ci run complains about snapshots but i don't get that locally and have no changes

@fabiospampinato
Copy link
Collaborator

at the minute we don't exit inside getPlugins since we must've already called getPluginOrExit when starting up

Right but I don't think the code should be making that kind of assumption 🤔 better to be explicit about what we want, I think.

@fabiospampinato
Copy link
Collaborator

edit: weirdly the ci run complains about snapshots but i don't get that locally and have no changes

I forgot to update the snapshots, I didn't even notice that caused the jest to "fail". If you work now if you rebase.

Copies the tests from prettier.

Notable changes:

- A failed plugin load throws an uncaught exception before this change.
  This catches it and logs an error to stderr
- A `snapshot-diff` package was being used to create a `git diff` like
  diff as a jest snapshot. We can pick the unique lines out instead of
using this

Skipped tests:

- `--help {option}` is not supported in prettier CLI
- `--config-path` with stdin is not yet supported (see prettier#21)
@43081j 43081j force-pushed the test-plugin-options-string branch from 6080008 to c4f6166 Compare February 24, 2025 10:54
@43081j
Copy link
Contributor Author

43081j commented Feb 24, 2025

should all be good again now 👍

@fabiospampinato
Copy link
Collaborator

snapshot-diff seems to approximately import the whole universe, so let's not use that, but in the original test we were also testing not only that the help text got updated, but also where the updates happened, and I think it'd be nice to be able to preserve testing for that 🤔 Not a blocker though.

It seems that we are not doing that 🤔 for now it's not a blocker, I'm merging, thanks 👍

@fabiospampinato fabiospampinato merged commit e4370c2 into prettier:main Mar 6, 2025
2 checks passed
@43081j 43081j deleted the test-plugin-options-string branch March 6, 2025 08:06
@43081j
Copy link
Contributor Author

43081j commented Mar 6, 2025

I totally forgot about that comment, my bad. We can look into it in a separate PR 👍 Will probably need a text diff dependency

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants