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: use fallback if prettier not found #11400

Merged
merged 5 commits into from May 20, 2021

Conversation

connorjclark
Copy link
Contributor

ref #11386

This allows the require for prettier to fail, without bubbling up as an error.

An alternative to this approach would be to change Defaults.ts to attempt setting prettier to require.resolve(prettier) (or something), but I am not familiar enough with the codebase to know if that'd be OK. The current approach works, but may hide an accidental misconfiguration if a user manually sets prettierPath.

@facebook-github-bot
Copy link
Contributor

Hi @connorjclark!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@@ -73,6 +73,36 @@ expect(a).toMatchInlineSnapshot(\`[1, 2]\`);
);
});

test('saveInlineSnapshots() with bad prettier path leaves formatting outside of snapshots alone', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is literally a copy/paste of the previous test case, but with a phony install path.

@jeysal
Copy link
Contributor

jeysal commented May 12, 2021

I think this approach is fine since the prettier path you're dealing with is already the default 'prettier' if not user-specified, or a fully resolved path if user-specified (by jest-config), so if it were invalid it would already throw there.

@jeysal jeysal added this to the Jest 27 milestone May 12, 2021
Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

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

thanks! could you add a changelog entry as well?

try {
// @ts-expect-error requireOutside Babel transform
prettier = requireOutside(prettierPath) as Prettier;
} catch (_) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
} catch (_) {
} catch {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haha, TIL you can use no arguments. Didn't realize you just have to leave off the parentheses. thx.

@connorjclark
Copy link
Contributor Author

Sorry for delay–been driving cross-country last couple days. updated the PR.

I am also hunting down the right person to email the FB CLA address.

@codecov-commenter
Copy link

Codecov Report

Merging #11400 (09e9efb) into master (4453901) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #11400      +/-   ##
==========================================
+ Coverage   64.20%   64.22%   +0.02%     
==========================================
  Files         309      309              
  Lines       13525    13527       +2     
  Branches     3294     3294              
==========================================
+ Hits         8684     8688       +4     
+ Misses       4126     4125       -1     
+ Partials      715      714       -1     
Impacted Files Coverage Δ
packages/jest-snapshot/src/InlineSnapshots.ts 81.45% <100.00%> (+0.30%) ⬆️
packages/expect/src/utils.ts 96.10% <0.00%> (+1.29%) ⬆️

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 4453901...09e9efb. Read the comment docs.

@SimenB
Copy link
Member

SimenB commented May 20, 2021

@connorjclark hey, any news? 🙂 We're just about ready to release v27, and this is in the milestone. As it's not breaking in and of itself we can probably land it later, tho 👍

@jeysal
Copy link
Contributor

jeysal commented May 20, 2021

We need this in for 27, without it inline snapshots without Prettier don't work as advertised

@SimenB
Copy link
Member

SimenB commented May 20, 2021

😞

@connorjclark
Copy link
Contributor Author

connorjclark commented May 20, 2021

hey, any news?

Haven't heard back from cla@fb.com, I'll send another email.

@SimenB
Copy link
Member

SimenB commented May 20, 2021

@JoelMarcey do you know why the CLA might be stuck?

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@jeysal
Copy link
Contributor

jeysal commented May 20, 2021

Yay! Thanks!

@jeysal jeysal merged commit 50451df into jestjs:master May 20, 2021
try {
// @ts-expect-error requireOutside Babel transform
prettier = requireOutside(prettierPath) as Prettier;
} catch {
Copy link
Member

Choose a reason for hiding this comment

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

thinking about it, we should probably just swallow MODULE_NOT_FOUND and rethrow other errors. Meh 🤷

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants