-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Don't wrap multiline strings with double quotes #4183
Conversation
} | ||
}" |
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.
💩, it's so much more readable
can we not merge it for a few days? :) a want to land my diff to update jest in www first (i already have a diff open for it), with this PR my diff can explode to many hundred thousand lines changed :D |
Sure, I'll need to figure out what's wrong with these color tags on CI :< |
The example of object property value which is a multiline string looks 👍 to me. Could the snapshot module take responsibility to strip surrounding backticks when needed? Stripping them in
|
@pedrottimark you're right about stripping backticks in snapshots. I'll iterate over tomorrow. Thanks for your input! |
just a heads up, i landed my www diff! so it's good to go |
congrats! 🎉 |
Let's give it another day, CI is failing also fyi. |
aa072a7
to
785c732
Compare
packages/pretty-format/src/index.js
Outdated
@@ -106,7 +106,9 @@ function printBasicValue( | |||
return printNumber(val); | |||
} | |||
if (typeOf === 'string') { | |||
return '"' + val.replace(/"|\\/g, '\\$&') + '"'; | |||
return /\n/.test(val) | |||
? '`' + val.replace(/\\/g, '\\$&') + '`' |
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.
Turned out that not escaping backslashes (this code was previously ? '`' + val + '`'
) introduced differences in color output of child processes. ¯_(ツ)_/¯
cc @aaronabramov
e1ccc4a
to
5d220a8
Compare
Ok, looks like the |
5d220a8
to
4d4f0d9
Compare
Codecov Report
@@ Coverage Diff @@
## master #4183 +/- ##
========================================
Coverage ? 60.2%
========================================
Files ? 191
Lines ? 6768
Branches ? 6
========================================
Hits ? 4075
Misses ? 2690
Partials ? 3
Continue to review full report at Codecov.
|
BTW, we can postpone this PR to anytime later, it's not a blocker for me anymore. Nevertheless, I'd still like to land it one day. |
Alright, I think I really want us to adopt this and have a new version of the snapshot format for 21, however I think it would be great if we could do a simpler rollout of the new snapshot format for 21: How about for the current version of snapshots, we support printing the quotes, but if a snapshot changes, any update to that individual file will update to the new snapshot version? That way, Jest 21 can support the current format, and for all new and updated snapshots it will support the new format. I really think that we should prevent churning users when making an upgrade, and it will also make it much easier to upgrade Jest on large codebases. @thymikee what do you think? Could you make this change? |
Hopefully I'll find some time for this by the end of the week(end) |
Really looking forward to this! Does first branch of ternary need to escape backticks as other branch escapes double quotes: if (typeOf === 'string') {
return /\r\n?|\n/gm.test(val)
? '`' + val.replace(/\\/g, '\\$&') + '`'
: '"' + val.replace(/"|\\/g, '\\$&') + '"';
} |
I remember wrapping it because I needed a way to determine multi-line string while unescaping in jest-snapshot. |
Indeed, I forgot that Thinking about it again, hopefully with a clearer mind, I think what I should have meant to ask is when |
@thymikee when you come back to this pull request, I noticed while studying trailing newlines in https://github.com/facebook/jest/blob/master/packages/jest-snapshot/src/utils.js#L132-L133 instead of unrestricted https://github.com/facebook/jest/blob/master/packages/jest-snapshot/src/index.js#L89-L90 |
I still want this but I'm gonna close it for now because nobody is actively working on it. Let's create a new PR if we make this change. |
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. |
Summary
This is a breaking change and needs updating snapshot version to v2 (v1 was introduced in Jest 19)
This PR treats multiline strings specially and wrap them in back-ticks instead of double quotes.
pretty-format
strips extra back-ticks just before returning the value. This is because we wrap whole expression in such back-ticks when writing a snapshot.Fixes #4179.
Test plan
Updated the snapshots accordingly. This way we can discuss easier on whether this change is worth breaking next Jest version.
cc @cpojer @aaronabramov @vjeux @rogeliog