-
-
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
Replace print with serialize in Immutable plugins #4189
Conversation
Updated 3 snapshot tests in packages/jest-matchers/src/__tests__/spy_matchers.test.js To replace copy-paste-reuse, wrote my first iterator with help from Understanding ECMAScript 6 |
AppVeyor build failed: spy_matchers.test.js 3 received values don’t show the changes to plugin Related to #4135 ? |
Two questions about possible additional (or should I say, subtractional) simplifications:
export const test = (val: any) => val && val[IS_MAP];
export const serialize = (
val: any,
config: Config,
indentation: string,
depth: number,
refs: Refs,
printer: Printer,
) =>
printImmutableEntries(
val,
config,
indentation,
depth,
refs,
printer,
val[IS_ORDERED] ? 'OrderedMap' : 'Map',
); export const test = (val: any) => val && val[IS_SET];
export const serialize = (
val: any,
config: Config,
indentation: string,
depth: number,
refs: Refs,
printer: Printer,
) =>
printImmutableValues(
val,
config,
indentation,
depth,
refs,
printer,
val[IS_ORDERED] ? 'OrderedSet' : 'Set',
); |
And then there was one! I worried that it’s a wrecking change, but |
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.
I like the change (wanted to do it myself at some point :D)
|
||
const IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@'; | ||
const IS_RECORD_SENTINEL = '@@__IMMUTABLE_RECORD__@@'; // v4 or later | ||
|
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.
I think we can remove these newlines between consts and between imports
printer: Printer, | ||
): string => { | ||
if (val[IS_SEQ_SENTINEL]) { | ||
return '[' + getName('Seq') + ']'; |
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.
Do we plan to support Immutable.Seq
?
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.
Because Record
doesn’t have a sentinel in immutable v3, serialize
needs to account for all types that do. The unified test
matches Seq
too, which seems easiest to understand. Do you mean support it better?
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.
Yup, was thinking about adding it later, if we need it. But not as a part of this PR, let's keep it tight
@@ -20,7 +20,7 @@ exports[`lastCalledWith works with Immutable.js objects 1`] = ` | |||
"<dim>expect(<red>jest.fn()</><dim>).not.lastCalledWith(<green>expected</><dim>) | |||
|
|||
Expected mock function to not have been last called with: | |||
<green>[Immutable.Map {a: {\\"b\\": \\"c\\"}}, Immutable.Map {a: {\\"b\\": \\"c\\"}}]</>" | |||
<green>[Immutable.Map {\\"a\\": {\\"b\\": \\"c\\"}}, Immutable.Map {\\"a\\": {\\"b\\": \\"c\\"}}]</>" |
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.
This is breaking, but we're more consistent 👍
' Immutable.Map {', | ||
' "key": "value",', | ||
' }: "immutable map",', | ||
'}', |
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.
I think at some point we should switch such tests to template literals plus dedent
|
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.
LGTM
Thank you for investing the time to review. I don’t take it for granted. |
Still need to wait until #4135 is resolved (same thing happening in my snapshot breaking PR) |
const getImmutableName = name => 'Immutable.' + name; | ||
const SPACE = ' '; | ||
|
||
const printImmutableEntries = ( |
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.
There's a lot of duplication in printImmutableEntries
and printImmutableValues
, but I think that extracting common logic would make it harder to understand what's going on. Not sure but I have no strong feelings about this though. Keep it as you like
* Replace print with serialize in Immutable plugins * Delete multiline string key to avoid conflict with 4183 * Update 3 snapshot tests * Replace printRecordProperties with getRecordIterator * Export 3 print functions from renamed immutable.js file * Move comment * Roll up immutable plugins * Replace getName with getImmutableName * Move Seq after all other types except Record * Delete newlines between adjacent import and sentinel lines
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
@cpenarrieta your feedback is welcome :) for more info, see #4114 and #4184
Breaking change in Map, OrderedMap, and Record to print the key:
[object Object]
if key is objectfalse
(and so on) from"false"
as stringBreaking changes for edge cases:
maxDepth
optionindentation
of immutable collection as child of non-immutable (the closing punctuation was incorrect in the same way as for closing tag in array of React elements)Question: Although I see a value in the line break between brackets/braces for non-minified empty Immutable collections (see #4121) now that
lib/immutable.js
calls the core helper functions, and the next version of Jest will have breaking changes for snapshots, it is a good time to review whether that difference is worth the extra code logic.Test plan
Updated: string keys in double quote marks
Added: