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

Port react-conformance tests to testing-library #22009

Merged
merged 10 commits into from
Mar 29, 2022

Conversation

ecraig12345
Copy link
Member

@ecraig12345 ecraig12345 commented Mar 8, 2022

Current Behavior

@fluentui/react-conformance uses enzyme, which we're trying to move away from. It also exposes enzyme APIs as part of its public API, leading to pollution of the global namespace with node types (see #17101).

New Behavior

Port all the tests in react-conformance that used enzyme to use testing-library instead. Note that I did NOT port the northstar-specific as prop tests (which were moved back into northstar in #21700) to enzyme due to uncertainty about some of the intended behavior.

This required some API updates in react-conformance (and corresponding updates in some component tests):

  • For customizing rendering: customMount (wrapper of enzyme's mount) => renderOptions (options for testing-library's render)
  • For finding the relevant component/element where props are applied: wrapperComponents, helperComponents, targetComponent => getTargetElement(renderResult, attr)

Note that northstar's isConformant still supports wrapperComponents, helperComponents, and targetComponent options for use with the legacy as prop tests.

Related Issue(s)

part of #21663, #21665, #17101

@DustyTheBot
Copy link

DustyTheBot commented Mar 8, 2022

Warnings
⚠️ There are no updates provided to CHANGELOG. Ensure there are no publicly visible changes introduced by this PR.

Generated by 🚫 dangerJS against 50cfdc4

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 8, 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 50cfdc4:

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

@size-auditor
Copy link

size-auditor bot commented Mar 8, 2022

Asset size changes

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

Baseline commit: 3e9421d1cf1545a8ab9fce425f3695e62ac99d73 (build)

@@ -66,22 +75,20 @@ export function isConformant(
} = options;

const defaultConfig: IsConformantOptions = {
customMount: mountWithProvider,
renderOptions: { wrapper: EmptyThemeProvider },
Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -8,5 +8,7 @@ describe('FormButton', () => {
constructorName: 'FormButton',
forwardsRefTo: `Button`,
targetComponent: Button,
getTargetElement: (result, attr) =>
attr === 'className' ? result.container.querySelector(`.${formButtonClassName}`) : result.getByRole('button'),
Copy link
Member Author

Choose a reason for hiding this comment

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

Since react-conformance no longer uses enzyme's find method to look for an instance of a particular component, we have to look for where attributes are applied in the DOM instead. Open to suggestions from the northstar team if there's a more appropriate way to do this.

@@ -53,13 +55,13 @@ describe('Radio', () => {
});

it('respects checked', () => {
const { getByRole } = render(<Radio checked />);
const { getByRole } = render(<Radio checked onChange={noOp} />);
Copy link
Member Author

Choose a reason for hiding this comment

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

This was just to get rid of a React warning creating noise while testing

@ecraig12345 ecraig12345 force-pushed the conformance-testing-lib branch from 21fbebb to ac936ab Compare March 8, 2022 23:50
@fabricteam
Copy link
Collaborator

fabricteam commented Mar 8, 2022

📊 Bundle size report

Unchanged fixtures
Package & Exports Size (minified/GZIP)
priority-overflow
createOverflowManager
2.836 kB
1.209 kB
react-accordion
Accordion (including children components)
74.792 kB
22.516 kB
react-avatar
Avatar
45.142 kB
13.111 kB
react-badge
Badge
20.895 kB
6.567 kB
react-badge
CounterBadge
21.848 kB
6.883 kB
react-badge
PresenceBadge
21.951 kB
6.565 kB
react-button
Button
28.013 kB
8.059 kB
react-button
CompoundButton
33.508 kB
9.092 kB
react-button
MenuButton
29.796 kB
8.665 kB
react-button
SplitButton
36.268 kB
9.863 kB
react-button
ToggleButton
37.395 kB
8.68 kB
react-card
Card - All
53.619 kB
15.372 kB
react-card
Card
48.904 kB
14.089 kB
react-card
CardFooter
7.686 kB
3.264 kB
react-card
CardHeader
9.251 kB
3.78 kB
react-card
CardPreview
7.658 kB
3.291 kB
react-combobox
Combobox
6.817 kB
2.901 kB
react-components
react-components: Accordion, Button, FluentProvider, Image, Menu, Popover
176.089 kB
49.113 kB
react-components
react-components: FluentProvider & webLightTheme
32.526 kB
10.645 kB
react-divider
Divider
15.385 kB
5.539 kB
react-image
Image
10.109 kB
3.958 kB
react-input
Input
21.661 kB
7.18 kB
react-label
Label
8.371 kB
3.504 kB
react-link
Link
11.106 kB
4.507 kB
react-menu
Menu (including children components)
105.852 kB
32.433 kB
react-menu
Menu (including selectable components)
109.031 kB
32.897 kB
react-popover
Popover
96.787 kB
29.559 kB
react-portal
Portal
6.272 kB
2.17 kB
react-positioning
usePopper
23.21 kB
8.084 kB
react-priority-overflow
hooks only
10.606 kB
4.087 kB
react-provider
FluentProvider
14.009 kB
5.25 kB
react-select
Select
7.853 kB
3.297 kB
react-slider
Slider
25.402 kB
8.251 kB
react-spinner
Spinner
6.815 kB
2.9 kB
react-switch
Switch
24.279 kB
8.001 kB
react-text
Text - Default
10.797 kB
4.233 kB
react-text
Text - Wrappers
14.113 kB
4.576 kB
react-theme
Single theme token import
69 B
89 B
react-theme
Teams: all themes
29.426 kB
6.551 kB
react-theme
Teams: Light theme
18.42 kB
5.27 kB
react-tooltip
Tooltip
42.837 kB
14.727 kB
react-utilities
SSRProvider
189 B
161 B
🤖 This report was generated against 3e9421d1cf1545a8ab9fce425f3695e62ac99d73

@fabricteam
Copy link
Collaborator

fabricteam commented Mar 8, 2022

Perf Analysis (@fluentui/react-northstar)

Perf tests with no regressions
Scenario Current PR Ticks Baseline Ticks Ratio
AttachmentMinimalPerf.default 140 130 1.08:1
AvatarMinimalPerf.default 179 166 1.08:1
ChatWithPopoverPerf.default 354 327 1.08:1
DividerMinimalPerf.default 317 299 1.06:1
FlexMinimalPerf.default 255 244 1.05:1
TreeWith60ListItems.default 156 148 1.05:1
AttachmentSlotsPerf.default 892 854 1.04:1
HeaderSlotsPerf.default 658 633 1.04:1
ButtonMinimalPerf.default 152 148 1.03:1
CardMinimalPerf.default 479 467 1.03:1
GridMinimalPerf.default 295 286 1.03:1
HeaderMinimalPerf.default 310 301 1.03:1
LabelMinimalPerf.default 328 317 1.03:1
ListCommonPerf.default 532 519 1.03:1
ListNestedPerf.default 473 459 1.03:1
RosterPerf.default 956 930 1.03:1
PortalMinimalPerf.default 154 150 1.03:1
RadioGroupMinimalPerf.default 382 371 1.03:1
StatusMinimalPerf.default 581 565 1.03:1
TableMinimalPerf.default 353 343 1.03:1
TextAreaMinimalPerf.default 420 406 1.03:1
VideoMinimalPerf.default 541 525 1.03:1
BoxMinimalPerf.default 294 287 1.02:1
ChatMinimalPerf.default 629 618 1.02:1
DropdownMinimalPerf.default 2610 2568 1.02:1
LoaderMinimalPerf.default 584 571 1.02:1
MenuMinimalPerf.default 734 722 1.02:1
PopupMinimalPerf.default 544 535 1.02:1
RefMinimalPerf.default 211 207 1.02:1
TooltipMinimalPerf.default 885 866 1.02:1
AnimationMinimalPerf.default 467 463 1.01:1
CheckboxMinimalPerf.default 2259 2246 1.01:1
DialogMinimalPerf.default 658 653 1.01:1
EmbedMinimalPerf.default 3517 3470 1.01:1
InputMinimalPerf.default 1113 1106 1.01:1
ItemLayoutMinimalPerf.default 1000 987 1.01:1
LayoutMinimalPerf.default 312 309 1.01:1
ListMinimalPerf.default 436 430 1.01:1
MenuButtonMinimalPerf.default 1432 1417 1.01:1
ReactionMinimalPerf.default 321 317 1.01:1
SkeletonMinimalPerf.default 298 294 1.01:1
SplitButtonMinimalPerf.default 3690 3648 1.01:1
TableManyItemsPerf.default 1626 1603 1.01:1
TextMinimalPerf.default 292 289 1.01:1
ButtonSlotsPerf.default 466 466 1:1
CarouselMinimalPerf.default 397 396 1:1
FormMinimalPerf.default 342 342 1:1
ProviderMergeThemesPerf.default 1467 1468 1:1
ProviderMinimalPerf.default 974 972 1:1
CustomToolbarPrototype.default 3527 3513 1:1
ToolbarMinimalPerf.default 793 794 1:1
TreeMinimalPerf.default 685 686 1:1
AccordionMinimalPerf.default 127 128 0.99:1
DatepickerMinimalPerf.default 4746 4775 0.99:1
ImageMinimalPerf.default 311 315 0.99:1
ListWith60ListItems.default 545 549 0.99:1
SegmentMinimalPerf.default 288 292 0.99:1
SliderMinimalPerf.default 1426 1439 0.99:1
ButtonOverridesMissPerf.default 1427 1451 0.98:1
ChatDuplicateMessagesPerf.default 257 263 0.98:1
AlertMinimalPerf.default 234 242 0.97:1
DropdownManyItemsPerf.default 567 582 0.97:1
IconMinimalPerf.default 524 556 0.94:1

@@ -5,7 +5,7 @@
"lib": ["DOM", "ES2019"],
"outDir": "dist",
"declaration": true,
"types": ["static-assets", "environment", "jest"],
"types": ["static-assets", "environment", "jest", "node"],
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 had to add this to make the build pass after enzyme types and their indirect node type leakage were removed

@fabricteam
Copy link
Collaborator

fabricteam commented Mar 9, 2022

Perf Analysis (@fluentui/react)

No significant results to display.

All results

Scenario Render type Master Ticks PR Ticks Iterations Status
BaseButton mount 924 949 5000
Breadcrumb mount 2747 2704 1000
Checkbox mount 1514 1517 5000
CheckboxBase mount 1310 1332 5000
ChoiceGroup mount 4841 4927 5000
ComboBox mount 1015 991 1000
CommandBar mount 10703 10733 1000
ContextualMenu mount 12088 12718 1000
DefaultButton mount 1183 1174 5000
DetailsRow mount 3892 3853 5000
DetailsRowFast mount 3891 3972 5000
DetailsRowNoStyles mount 3709 3743 5000
Dialog mount 2265 2286 1000
DocumentCardTitle mount 163 174 1000
Dropdown mount 3344 3418 5000
FocusTrapZone mount 1843 1875 5000
FocusZone mount 1955 1842 5000
IconButton mount 1842 1837 5000
Label mount 352 368 5000
Layer mount 3073 3032 5000
Link mount 479 474 5000
MenuButton mount 1553 1514 5000
MessageBar mount 2228 2201 5000
Nav mount 3429 3368 1000
OverflowSet mount 1127 1129 5000
Panel mount 2183 2228 1000
Persona mount 883 862 1000
Pivot mount 1447 1468 1000
PrimaryButton mount 1350 1334 5000
Rating mount 7996 7802 5000
SearchBox mount 1375 1339 5000
Shimmer mount 2617 2567 5000
Slider mount 2049 2010 5000
SpinButton mount 5135 5164 5000
Spinner mount 440 439 5000
SplitButton mount 3267 3247 5000
Stack mount 532 557 5000
StackWithIntrinsicChildren mount 2320 2290 5000
StackWithTextChildren mount 5294 5399 5000
SwatchColorPicker mount 12001 11772 5000
TagPicker mount 2741 2757 5000
TeachingBubble mount 98610 99836 5000
Text mount 455 445 5000
TextField mount 1419 1477 5000
ThemeProvider mount 1219 1220 5000
ThemeProvider virtual-rerender 662 651 5000
ThemeProvider virtual-rerender-with-unmount 1875 1888 5000
Toggle mount 827 797 5000
buttonNative mount 143 131 5000

@ecraig12345 ecraig12345 force-pushed the conformance-testing-lib branch from ac936ab to 28c5f0a Compare March 9, 2022 03:21
@layershifter layershifter self-requested a review March 9, 2022 09:07
@ecraig12345 ecraig12345 force-pushed the conformance-testing-lib branch 2 times, most recently from c8b0113 to 517e027 Compare March 15, 2022 00:25
@fabricteam
Copy link
Collaborator

fabricteam commented Mar 15, 2022

Perf Analysis (@fluentui/react-components)

No significant results to display.

All results

Scenario Render type Master Ticks PR Ticks Iterations Status
Avatar mount 1044 1107 5000
Button mount 662 687 5000
FluentProvider mount 2158 2167 5000
FluentProviderWithTheme mount 340 300 10
FluentProviderWithTheme virtual-rerender 293 264 10
FluentProviderWithTheme virtual-rerender-with-unmount 351 381 10
MakeStyles mount 1865 1870 50000

if (container) {
const ReactDOM = await import('react-dom');
ReactDOM.unmountComponentAtNode(container);
Copy link
Member Author

Choose a reason for hiding this comment

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

After removing the "nuclear" document.body.innerHTML = '' cleanup in react-conformance, the incomplete cleanup here was causing subsequent tests to fail if the component rendered anything outside of the container node (such as PopoverSurface rendering a Portal).

@ecraig12345 ecraig12345 force-pushed the conformance-testing-lib branch from 3371802 to a5dcccc Compare March 15, 2022 02:45
@ecraig12345 ecraig12345 requested a review from chrisdholt as a code owner March 15, 2022 02:45
@ecraig12345
Copy link
Member Author

Sorry for the brief web-components change...that wasn't supposed to be committed and has been reverted.

Can we remove Enzyme setup in v9 packages? For example, packages/react-image/config/tests.js.

Probably in a separate PR.

Good point, made an issue #22118

@ecraig12345 ecraig12345 force-pushed the conformance-testing-lib branch 2 times, most recently from b1e4885 to 9b70f07 Compare March 16, 2022 18:49
@ecraig12345 ecraig12345 force-pushed the conformance-testing-lib branch from 9b70f07 to f5307e6 Compare March 18, 2022 23:57
@andrefcdias andrefcdias removed their assignment Mar 24, 2022
@ecraig12345 ecraig12345 force-pushed the conformance-testing-lib branch from 01aa11a to 50cfdc4 Compare March 28, 2022 21:27
@ecraig12345
Copy link
Member Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

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

Successfully merging this pull request may close these issues.

6 participants