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: Conformance tests should unmount components #21423

Closed
wants to merge 3 commits into from

Conversation

ling1726
Copy link
Member

@ling1726 ling1726 commented Jan 25, 2022

Enzyme does not unmount automatically at the end of a test
test suite which leads to cryptic bugs when queryselectors return
multiple elements, or the wrong element.

Current Behavior

Conformance tests leave DOM elements in the document after test

New Behavior

Conformance tests don't leave DOM elements in the document after test

Related Issue(s)

Fixes #

Enzyme does not unmount automatically at the end of a test
test suite which leads to cryptic bugs when queryselectors return
multiple elements, or the wrong element.
@ling1726 ling1726 marked this pull request as ready for review January 25, 2022 10:17
@@ -254,6 +255,7 @@ export const defaultTests: TestObject = {
const defaultEl = customMount(<Component {...requiredProps} />);
const defaultComponent = getComponent(defaultEl, helperComponents, wrapperComponent);
const defaultClassNames = defaultComponent.getDOMNode().getAttribute('class')?.split(' ') || [];
defaultEl.unmount();
Copy link
Member Author

Choose a reason for hiding this comment

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

The odd test that calls mount more than once. This kind of test cannot be used with a 'global' mount.

I think this is 🤮 but can't think of a better, idea. Suggestions welcome

Copy link
Member

Choose a reason for hiding this comment

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

A bit confused, where's the other call? Also not quite understanding what the problem is (but I also don't have a deep understanding of how mount works without attachTo).

Copy link
Member Author

Choose a reason for hiding this comment

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

I created a mountWithCleanup module which is generally how the enzyme community seems to handle the unmounting, however that solution breaks down when mount is used more than once in a test.

Unfortunately, this is the only time in all conformance tests this is done. The alternative would be to explicitly unmount in each test.

Copy link
Member

Choose a reason for hiding this comment

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

Ah now I see the second mount below this one. I'm still not convinced this is a problem given that the test is comparing classNames in two different cases, but theoretically you could do the same thing by mounting the component once and updating props. Or to be certain of avoiding interference/retained state, maybe the test could mount both versions at once inside a fragment?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah that's a good shout, I'll try to update the test to use a single mount

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 25, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 8484c3f:

Sandbox Source
@fluentui/react 8 starter Configuration
@fluentui/react-components 9 starter Configuration

@size-auditor
Copy link

size-auditor bot commented Jan 25, 2022

Asset size changes

Size Auditor did not detect a change in bundle size for any component!

Baseline commit: d8fe0da13e1d34028a51e5d740e7bdc78c3a6862 (build)

@fabricteam
Copy link
Collaborator

fabricteam commented Jan 25, 2022

📊 Bundle size report

Unchanged fixtures
Package & Exports Size (minified/GZIP)
react-accordion
Accordion (including children components)
54.888 kB
17.524 kB
react-avatar
Avatar
43.858 kB
12.488 kB
react-badge
Badge
24.258 kB
7.128 kB
react-badge
CounterBadge
25.126 kB
7.429 kB
react-badge
PresenceBadge
22.314 kB
6.544 kB
react-button
Button
28.265 kB
8.113 kB
react-button
CompoundButton
33.562 kB
9.074 kB
react-button
MenuButton
29.92 kB
8.69 kB
react-button
SplitButton
36.006 kB
9.757 kB
react-button
ToggleButton
37.502 kB
8.711 kB
react-card
Card - All
48.475 kB
14.343 kB
react-card
Card
43.984 kB
13.191 kB
react-card
CardFooter
7.686 kB
3.254 kB
react-card
CardHeader
8.953 kB
3.693 kB
react-card
CardPreview
7.879 kB
3.381 kB
react-components
react-components: Accordion, Button, FluentProvider, Image, Menu, Popover
166.076 kB
47.056 kB
react-components
react-components: FluentProvider & webLightTheme
32.489 kB
10.636 kB
react-divider
Divider
15.337 kB
5.544 kB
react-image
Image
10.143 kB
3.969 kB
react-input
Input
21.542 kB
7.139 kB
react-label
Label
8.391 kB
3.5 kB
react-link
Link
11.14 kB
4.521 kB
react-menu
Menu (including children components)
103.149 kB
31.833 kB
react-menu
Menu (including selectable components)
105.4 kB
32.191 kB
react-popover
Popover
95.33 kB
29.008 kB
react-portal
Portal
6.249 kB
2.163 kB
react-provider
FluentProvider
13.972 kB
5.237 kB
react-slider
Slider
22.922 kB
7.748 kB
react-switch
Switch
25.383 kB
8.204 kB
react-text
Text - Default
10.837 kB
4.248 kB
react-text
Text - Wrappers
14.139 kB
4.589 kB
react-tooltip
Tooltip
44.973 kB
15.628 kB
🤖 This report was generated against d8fe0da13e1d34028a51e5d740e7bdc78c3a6862

Comment on lines +13 to +15
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
wrapper = enzymeWrapper;
Copy link
Member

Choose a reason for hiding this comment

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

Why it's not assignable?

Copy link
Member Author

Choose a reason for hiding this comment

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

enzyme mount is generic, which takes the props of the component passed in. SInce the wrapper is never exported or returned I decided not to recreate all those generic types

Copy link
Member

Choose a reason for hiding this comment

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

Can you cast instead of ts-ignore so it's less "nuclear"?

@layershifter
Copy link
Member

This is really "strange" fix, but it's how Enzyme works unfortunately. Another one reason to rewrite these tests away from Enzyme.

@fabricteam
Copy link
Collaborator

Perf Analysis (@fluentui/react)

Scenario Render type Master Ticks PR Ticks Iterations Status
ContextualMenu mount 14626 7283 1000 Possible regression
All results

Scenario Render type Master Ticks PR Ticks Iterations Status
Avatar mount 778 769 5000
BaseButton mount 746 792 5000
Breadcrumb mount 2288 2090 1000
ButtonNext mount 442 451 5000
Checkbox mount 1352 1291 5000
CheckboxBase mount 1049 1131 5000
ChoiceGroup mount 3989 3813 5000
ComboBox mount 849 868 1000
CommandBar mount 8902 9069 1000
ContextualMenu mount 14626 7283 1000 Possible regression
DefaultButton mount 990 1014 5000
DetailsRow mount 3265 3259 5000
DetailsRowFast mount 3246 3240 5000
DetailsRowNoStyles mount 3088 3154 5000
Dialog mount 2216 2219 1000
DocumentCardTitle mount 154 166 1000
Dropdown mount 2770 2787 5000
FluentProviderNext mount 1712 1815 5000
FluentProviderWithTheme mount 150 160 10
FluentProviderWithTheme virtual-rerender 95 99 10
FluentProviderWithTheme virtual-rerender-with-unmount 168 146 10
FocusTrapZone mount 1596 1611 5000
FocusZone mount 1600 1556 5000
IconButton mount 1531 1518 5000
Label mount 324 326 5000
Layer mount 2571 2568 5000
Link mount 454 426 5000
MakeStyles mount 1481 1459 50000
MenuButton mount 1310 1287 5000
MessageBar mount 1731 1743 5000
Nav mount 2796 2847 1000
OverflowSet mount 975 972 5000
Panel mount 2161 2164 1000
Persona mount 776 750 1000
Pivot mount 1262 1257 1000
PrimaryButton mount 1143 1121 5000
Rating mount 6603 6596 5000
SearchBox mount 1160 1188 5000
Shimmer mount 2182 2165 5000
Slider mount 1724 1708 5000
SpinButton mount 4338 4326 5000
Spinner mount 389 398 5000
SplitButton mount 2748 2726 5000
Stack mount 464 465 5000
StackWithIntrinsicChildren mount 1975 1991 5000
StackWithTextChildren mount 4510 4488 5000
SwatchColorPicker mount 9910 9745 5000
TagPicker mount 2296 2271 5000
TeachingBubble mount 11293 11395 5000
Text mount 385 395 5000
TextField mount 1221 1212 5000
ThemeProvider mount 1018 1037 5000
ThemeProvider virtual-rerender 546 555 5000
ThemeProvider virtual-rerender-with-unmount 1595 1641 5000
Toggle mount 707 706 5000
buttonNative mount 133 138 5000

Perf Analysis (@fluentui/react-northstar)

Perf tests with no regressions
Scenario Current PR Ticks Baseline Ticks Ratio
ReactionMinimalPerf.default 340 319 1.07:1
ChatDuplicateMessagesPerf.default 262 248 1.06:1
TableMinimalPerf.default 357 338 1.06:1
BoxMinimalPerf.default 309 295 1.05:1
LayoutMinimalPerf.default 320 305 1.05:1
RefMinimalPerf.default 209 200 1.05:1
ButtonSlotsPerf.default 476 457 1.04:1
ChatMinimalPerf.default 645 622 1.04:1
ImageMinimalPerf.default 325 313 1.04:1
TextMinimalPerf.default 301 290 1.04:1
TextAreaMinimalPerf.default 440 423 1.04:1
AlertMinimalPerf.default 236 230 1.03:1
CarouselMinimalPerf.default 405 394 1.03:1
ListMinimalPerf.default 449 438 1.03:1
RadioGroupMinimalPerf.default 393 381 1.03:1
StatusMinimalPerf.default 589 572 1.03:1
TreeMinimalPerf.default 682 665 1.03:1
VideoMinimalPerf.default 561 547 1.03:1
AvatarMinimalPerf.default 172 169 1.02:1
CardMinimalPerf.default 479 470 1.02:1
DropdownManyItemsPerf.default 574 563 1.02:1
FormMinimalPerf.default 345 337 1.02:1
GridMinimalPerf.default 298 293 1.02:1
LabelMinimalPerf.default 334 329 1.02:1
ListCommonPerf.default 538 527 1.02:1
SliderMinimalPerf.default 1433 1410 1.02:1
TreeWith60ListItems.default 153 150 1.02:1
AccordionMinimalPerf.default 137 136 1.01:1
AnimationMinimalPerf.default 465 461 1.01:1
ButtonOverridesMissPerf.default 1440 1427 1.01:1
ChatWithPopoverPerf.default 320 318 1.01:1
DatepickerMinimalPerf.default 4718 4661 1.01:1
DialogMinimalPerf.default 656 650 1.01:1
DropdownMinimalPerf.default 2566 2551 1.01:1
FlexMinimalPerf.default 254 251 1.01:1
ListNestedPerf.default 479 474 1.01:1
LoaderMinimalPerf.default 587 582 1.01:1
MenuButtonMinimalPerf.default 1420 1404 1.01:1
SplitButtonMinimalPerf.default 3646 3625 1.01:1
TableManyItemsPerf.default 1621 1600 1.01:1
CustomToolbarPrototype.default 3479 3450 1.01:1
AttachmentSlotsPerf.default 901 897 1:1
CheckboxMinimalPerf.default 2277 2282 1:1
EmbedMinimalPerf.default 3490 3482 1:1
HeaderSlotsPerf.default 645 644 1:1
InputMinimalPerf.default 1102 1100 1:1
ListWith60ListItems.default 548 546 1:1
PopupMinimalPerf.default 522 524 1:1
ProviderMinimalPerf.default 964 961 1:1
SkeletonMinimalPerf.default 301 301 1:1
ToolbarMinimalPerf.default 792 795 1:1
HeaderMinimalPerf.default 304 308 0.99:1
ItemLayoutMinimalPerf.default 1006 1012 0.99:1
MenuMinimalPerf.default 712 717 0.99:1
ProviderMergeThemesPerf.default 1464 1473 0.99:1
TooltipMinimalPerf.default 872 882 0.99:1
SegmentMinimalPerf.default 295 302 0.98:1
IconMinimalPerf.default 501 511 0.98:1
ButtonMinimalPerf.default 146 150 0.97:1
DividerMinimalPerf.default 302 311 0.97:1
RosterPerf.default 993 1022 0.97:1
PortalMinimalPerf.default 146 153 0.95:1
AttachmentMinimalPerf.default 126 135 0.93:1

@ling1726
Copy link
Member Author

closing since #21664 also addresses this

@ling1726 ling1726 closed this Feb 11, 2022
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.

None yet

5 participants