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

Components: consistently use render from @ariakit/test #64180

Open
wants to merge 9 commits into
base: trunk
Choose a base branch
from

Conversation

DaniGuardiola
Copy link
Contributor

@DaniGuardiola DaniGuardiola commented Aug 1, 2024

What?

Enforce the use of @ariakit/test in tests in the components package, as discussed in #64066

Why?

The Ariakit test library addresses some shortcomings with RTL in relation to timers. I recommend looking at the linked issue for deeper context. This library also has nicer APIs.

How?

Restrict the use of render from RTL (event triggers will be addressed in a separate PR), and replace those with the equivalent @ariakit/test utilities. A codemod is used to facilitate the migration.

I've added the codemod code to the PR temporarily for reference (migration/ dir), but it will be removed before merge.

Tips for reviewing

I separated the codemod changes from manual changes, so I recommend reviewing the diff up till the codemod changes, then looking at the manual changes commit (and successive ones) independently. Please also read the comments since I've written important information throughout.

Follow ups

Read #64180 (comment) to understand follow-up tasks after this PR merges.

Copy link

github-actions bot commented Aug 1, 2024

Size Change: 0 B

Total Size: 1.77 MB

ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 951 B
build/annotations/index.min.js 2.26 kB
build/api-fetch/index.min.js 2.31 kB
build/autop/index.min.js 2.12 kB
build/blob/index.min.js 579 B
build/block-directory/index.min.js 7.29 kB
build/block-directory/style-rtl.css 1.01 kB
build/block-directory/style.css 1.01 kB
build/block-editor/content-rtl.css 4.56 kB
build/block-editor/content.css 4.56 kB
build/block-editor/default-editor-styles-rtl.css 394 B
build/block-editor/default-editor-styles.css 394 B
build/block-editor/index.min.js 255 kB
build/block-editor/style-rtl.css 16.3 kB
build/block-editor/style.css 16.3 kB
build/block-library/blocks/archives/editor-rtl.css 61 B
build/block-library/blocks/archives/editor.css 60 B
build/block-library/blocks/archives/style-rtl.css 90 B
build/block-library/blocks/archives/style.css 90 B
build/block-library/blocks/audio/editor-rtl.css 149 B
build/block-library/blocks/audio/editor.css 151 B
build/block-library/blocks/audio/style-rtl.css 132 B
build/block-library/blocks/audio/style.css 132 B
build/block-library/blocks/audio/theme-rtl.css 134 B
build/block-library/blocks/audio/theme.css 134 B
build/block-library/blocks/avatar/editor-rtl.css 115 B
build/block-library/blocks/avatar/editor.css 115 B
build/block-library/blocks/avatar/style-rtl.css 104 B
build/block-library/blocks/avatar/style.css 104 B
build/block-library/blocks/button/editor-rtl.css 310 B
build/block-library/blocks/button/editor.css 310 B
build/block-library/blocks/button/style-rtl.css 538 B
build/block-library/blocks/button/style.css 538 B
build/block-library/blocks/buttons/editor-rtl.css 336 B
build/block-library/blocks/buttons/editor.css 336 B
build/block-library/blocks/buttons/style-rtl.css 328 B
build/block-library/blocks/buttons/style.css 328 B
build/block-library/blocks/calendar/style-rtl.css 240 B
build/block-library/blocks/calendar/style.css 240 B
build/block-library/blocks/categories/editor-rtl.css 132 B
build/block-library/blocks/categories/editor.css 131 B
build/block-library/blocks/categories/style-rtl.css 152 B
build/block-library/blocks/categories/style.css 152 B
build/block-library/blocks/code/editor-rtl.css 53 B
build/block-library/blocks/code/editor.css 53 B
build/block-library/blocks/code/style-rtl.css 121 B
build/block-library/blocks/code/style.css 121 B
build/block-library/blocks/code/theme-rtl.css 122 B
build/block-library/blocks/code/theme.css 122 B
build/block-library/blocks/columns/editor-rtl.css 108 B
build/block-library/blocks/columns/editor.css 108 B
build/block-library/blocks/columns/style-rtl.css 420 B
build/block-library/blocks/columns/style.css 420 B
build/block-library/blocks/comment-author-avatar/editor-rtl.css 124 B
build/block-library/blocks/comment-author-avatar/editor.css 124 B
build/block-library/blocks/comment-content/style-rtl.css 90 B
build/block-library/blocks/comment-content/style.css 90 B
build/block-library/blocks/comment-template/style-rtl.css 200 B
build/block-library/blocks/comment-template/style.css 199 B
build/block-library/blocks/comments-pagination-numbers/editor-rtl.css 122 B
build/block-library/blocks/comments-pagination-numbers/editor.css 121 B
build/block-library/blocks/comments-pagination/editor-rtl.css 221 B
build/block-library/blocks/comments-pagination/editor.css 211 B
build/block-library/blocks/comments-pagination/style-rtl.css 234 B
build/block-library/blocks/comments-pagination/style.css 231 B
build/block-library/blocks/comments-title/editor-rtl.css 75 B
build/block-library/blocks/comments-title/editor.css 75 B
build/block-library/blocks/comments/editor-rtl.css 832 B
build/block-library/blocks/comments/editor.css 832 B
build/block-library/blocks/comments/style-rtl.css 632 B
build/block-library/blocks/comments/style.css 631 B
build/block-library/blocks/cover/editor-rtl.css 668 B
build/block-library/blocks/cover/editor.css 669 B
build/block-library/blocks/cover/style-rtl.css 1.62 kB
build/block-library/blocks/cover/style.css 1.6 kB
build/block-library/blocks/details/editor-rtl.css 65 B
build/block-library/blocks/details/editor.css 65 B
build/block-library/blocks/details/style-rtl.css 86 B
build/block-library/blocks/details/style.css 86 B
build/block-library/blocks/embed/editor-rtl.css 314 B
build/block-library/blocks/embed/editor.css 314 B
build/block-library/blocks/embed/style-rtl.css 419 B
build/block-library/blocks/embed/style.css 419 B
build/block-library/blocks/embed/theme-rtl.css 133 B
build/block-library/blocks/embed/theme.css 133 B
build/block-library/blocks/file/editor-rtl.css 326 B
build/block-library/blocks/file/editor.css 326 B
build/block-library/blocks/file/style-rtl.css 278 B
build/block-library/blocks/file/style.css 279 B
build/block-library/blocks/file/view.min.js 324 B
build/block-library/blocks/footnotes/style-rtl.css 198 B
build/block-library/blocks/footnotes/style.css 197 B
build/block-library/blocks/form-input/editor-rtl.css 229 B
build/block-library/blocks/form-input/editor.css 229 B
build/block-library/blocks/form-input/style-rtl.css 342 B
build/block-library/blocks/form-input/style.css 342 B
build/block-library/blocks/form-submission-notification/editor-rtl.css 344 B
build/block-library/blocks/form-submission-notification/editor.css 341 B
build/block-library/blocks/form-submit-button/style-rtl.css 69 B
build/block-library/blocks/form-submit-button/style.css 69 B
build/block-library/blocks/form/view.min.js 470 B
build/block-library/blocks/freeform/editor-rtl.css 2.6 kB
build/block-library/blocks/freeform/editor.css 2.6 kB
build/block-library/blocks/gallery/editor-rtl.css 955 B
build/block-library/blocks/gallery/editor.css 958 B
build/block-library/blocks/gallery/style-rtl.css 1.71 kB
build/block-library/blocks/gallery/style.css 1.71 kB
build/block-library/blocks/gallery/theme-rtl.css 108 B
build/block-library/blocks/gallery/theme.css 108 B
build/block-library/blocks/group/editor-rtl.css 344 B
build/block-library/blocks/group/editor.css 344 B
build/block-library/blocks/group/style-rtl.css 103 B
build/block-library/blocks/group/style.css 103 B
build/block-library/blocks/group/theme-rtl.css 79 B
build/block-library/blocks/group/theme.css 79 B
build/block-library/blocks/heading/style-rtl.css 188 B
build/block-library/blocks/heading/style.css 188 B
build/block-library/blocks/html/editor-rtl.css 346 B
build/block-library/blocks/html/editor.css 347 B
build/block-library/blocks/image/editor-rtl.css 894 B
build/block-library/blocks/image/editor.css 892 B
build/block-library/blocks/image/style-rtl.css 1.59 kB
build/block-library/blocks/image/style.css 1.59 kB
build/block-library/blocks/image/theme-rtl.css 137 B
build/block-library/blocks/image/theme.css 137 B
build/block-library/blocks/image/view.min.js 1.65 kB
build/block-library/blocks/latest-comments/style-rtl.css 355 B
build/block-library/blocks/latest-comments/style.css 354 B
build/block-library/blocks/latest-posts/editor-rtl.css 186 B
build/block-library/blocks/latest-posts/editor.css 183 B
build/block-library/blocks/latest-posts/style-rtl.css 509 B
build/block-library/blocks/latest-posts/style.css 510 B
build/block-library/blocks/list/style-rtl.css 107 B
build/block-library/blocks/list/style.css 107 B
build/block-library/blocks/loginout/style-rtl.css 61 B
build/block-library/blocks/loginout/style.css 61 B
build/block-library/blocks/media-text/editor-rtl.css 304 B
build/block-library/blocks/media-text/editor.css 303 B
build/block-library/blocks/media-text/style-rtl.css 516 B
build/block-library/blocks/media-text/style.css 515 B
build/block-library/blocks/more/editor-rtl.css 427 B
build/block-library/blocks/more/editor.css 427 B
build/block-library/blocks/navigation-link/editor-rtl.css 663 B
build/block-library/blocks/navigation-link/editor.css 664 B
build/block-library/blocks/navigation-link/style-rtl.css 192 B
build/block-library/blocks/navigation-link/style.css 191 B
build/block-library/blocks/navigation-submenu/editor-rtl.css 295 B
build/block-library/blocks/navigation-submenu/editor.css 294 B
build/block-library/blocks/navigation/editor-rtl.css 2.18 kB
build/block-library/blocks/navigation/editor.css 2.19 kB
build/block-library/blocks/navigation/style-rtl.css 2.25 kB
build/block-library/blocks/navigation/style.css 2.23 kB
build/block-library/blocks/navigation/view.min.js 1.03 kB
build/block-library/blocks/nextpage/editor-rtl.css 392 B
build/block-library/blocks/nextpage/editor.css 392 B
build/block-library/blocks/page-list/editor-rtl.css 378 B
build/block-library/blocks/page-list/editor.css 378 B
build/block-library/blocks/page-list/style-rtl.css 175 B
build/block-library/blocks/page-list/style.css 175 B
build/block-library/blocks/paragraph/editor-rtl.css 236 B
build/block-library/blocks/paragraph/editor.css 236 B
build/block-library/blocks/paragraph/style-rtl.css 341 B
build/block-library/blocks/paragraph/style.css 340 B
build/block-library/blocks/post-author/style-rtl.css 175 B
build/block-library/blocks/post-author/style.css 176 B
build/block-library/blocks/post-comments-form/editor-rtl.css 96 B
build/block-library/blocks/post-comments-form/editor.css 96 B
build/block-library/blocks/post-comments-form/style-rtl.css 527 B
build/block-library/blocks/post-comments-form/style.css 528 B
build/block-library/blocks/post-content/editor-rtl.css 74 B
build/block-library/blocks/post-content/editor.css 74 B
build/block-library/blocks/post-content/style-rtl.css 79 B
build/block-library/blocks/post-content/style.css 79 B
build/block-library/blocks/post-date/style-rtl.css 62 B
build/block-library/blocks/post-date/style.css 62 B
build/block-library/blocks/post-excerpt/editor-rtl.css 71 B
build/block-library/blocks/post-excerpt/editor.css 71 B
build/block-library/blocks/post-excerpt/style-rtl.css 155 B
build/block-library/blocks/post-excerpt/style.css 155 B
build/block-library/blocks/post-featured-image/editor-rtl.css 729 B
build/block-library/blocks/post-featured-image/editor.css 726 B
build/block-library/blocks/post-featured-image/style-rtl.css 341 B
build/block-library/blocks/post-featured-image/style.css 341 B
build/block-library/blocks/post-navigation-link/style-rtl.css 215 B
build/block-library/blocks/post-navigation-link/style.css 214 B
build/block-library/blocks/post-template/editor-rtl.css 99 B
build/block-library/blocks/post-template/editor.css 98 B
build/block-library/blocks/post-template/style-rtl.css 399 B
build/block-library/blocks/post-template/style.css 398 B
build/block-library/blocks/post-terms/style-rtl.css 96 B
build/block-library/blocks/post-terms/style.css 96 B
build/block-library/blocks/post-time-to-read/style-rtl.css 70 B
build/block-library/blocks/post-time-to-read/style.css 70 B
build/block-library/blocks/post-title/style-rtl.css 100 B
build/block-library/blocks/post-title/style.css 100 B
build/block-library/blocks/preformatted/style-rtl.css 125 B
build/block-library/blocks/preformatted/style.css 125 B
build/block-library/blocks/pullquote/editor-rtl.css 134 B
build/block-library/blocks/pullquote/editor.css 134 B
build/block-library/blocks/pullquote/style-rtl.css 342 B
build/block-library/blocks/pullquote/style.css 342 B
build/block-library/blocks/pullquote/theme-rtl.css 167 B
build/block-library/blocks/pullquote/theme.css 167 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 121 B
build/block-library/blocks/query-pagination-numbers/editor.css 118 B
build/block-library/blocks/query-pagination/editor-rtl.css 220 B
build/block-library/blocks/query-pagination/editor.css 208 B
build/block-library/blocks/query-pagination/style-rtl.css 287 B
build/block-library/blocks/query-pagination/style.css 283 B
build/block-library/blocks/query-title/style-rtl.css 64 B
build/block-library/blocks/query-title/style.css 64 B
build/block-library/blocks/query/editor-rtl.css 452 B
build/block-library/blocks/query/editor.css 451 B
build/block-library/blocks/query/view.min.js 958 B
build/block-library/blocks/quote/style-rtl.css 238 B
build/block-library/blocks/quote/style.css 238 B
build/block-library/blocks/quote/theme-rtl.css 221 B
build/block-library/blocks/quote/theme.css 225 B
build/block-library/blocks/read-more/style-rtl.css 138 B
build/block-library/blocks/read-more/style.css 138 B
build/block-library/blocks/rss/editor-rtl.css 101 B
build/block-library/blocks/rss/editor.css 101 B
build/block-library/blocks/rss/style-rtl.css 288 B
build/block-library/blocks/rss/style.css 287 B
build/block-library/blocks/search/editor-rtl.css 193 B
build/block-library/blocks/search/editor.css 193 B
build/block-library/blocks/search/style-rtl.css 672 B
build/block-library/blocks/search/style.css 671 B
build/block-library/blocks/search/theme-rtl.css 113 B
build/block-library/blocks/search/theme.css 113 B
build/block-library/blocks/search/view.min.js 475 B
build/block-library/blocks/separator/editor-rtl.css 100 B
build/block-library/blocks/separator/editor.css 100 B
build/block-library/blocks/separator/style-rtl.css 248 B
build/block-library/blocks/separator/style.css 248 B
build/block-library/blocks/separator/theme-rtl.css 195 B
build/block-library/blocks/separator/theme.css 195 B
build/block-library/blocks/shortcode/editor-rtl.css 286 B
build/block-library/blocks/shortcode/editor.css 286 B
build/block-library/blocks/site-logo/editor-rtl.css 806 B
build/block-library/blocks/site-logo/editor.css 803 B
build/block-library/blocks/site-logo/style-rtl.css 218 B
build/block-library/blocks/site-logo/style.css 218 B
build/block-library/blocks/site-tagline/editor-rtl.css 87 B
build/block-library/blocks/site-tagline/editor.css 87 B
build/block-library/blocks/site-tagline/style-rtl.css 65 B
build/block-library/blocks/site-tagline/style.css 65 B
build/block-library/blocks/site-title/editor-rtl.css 123 B
build/block-library/blocks/site-title/editor.css 123 B
build/block-library/blocks/site-title/style-rtl.css 90 B
build/block-library/blocks/site-title/style.css 90 B
build/block-library/blocks/social-link/editor-rtl.css 338 B
build/block-library/blocks/social-link/editor.css 338 B
build/block-library/blocks/social-links/editor-rtl.css 676 B
build/block-library/blocks/social-links/editor.css 675 B
build/block-library/blocks/social-links/style-rtl.css 1.51 kB
build/block-library/blocks/social-links/style.css 1.5 kB
build/block-library/blocks/spacer/editor-rtl.css 346 B
build/block-library/blocks/spacer/editor.css 346 B
build/block-library/blocks/spacer/style-rtl.css 48 B
build/block-library/blocks/spacer/style.css 48 B
build/block-library/blocks/table-of-contents/style-rtl.css 83 B
build/block-library/blocks/table-of-contents/style.css 83 B
build/block-library/blocks/table/editor-rtl.css 394 B
build/block-library/blocks/table/editor.css 394 B
build/block-library/blocks/table/style-rtl.css 640 B
build/block-library/blocks/table/style.css 639 B
build/block-library/blocks/table/theme-rtl.css 152 B
build/block-library/blocks/table/theme.css 152 B
build/block-library/blocks/tag-cloud/editor-rtl.css 63 B
build/block-library/blocks/tag-cloud/editor.css 63 B
build/block-library/blocks/tag-cloud/style-rtl.css 266 B
build/block-library/blocks/tag-cloud/style.css 265 B
build/block-library/blocks/template-part/editor-rtl.css 393 B
build/block-library/blocks/template-part/editor.css 393 B
build/block-library/blocks/template-part/theme-rtl.css 113 B
build/block-library/blocks/template-part/theme.css 113 B
build/block-library/blocks/term-description/style-rtl.css 126 B
build/block-library/blocks/term-description/style.css 126 B
build/block-library/blocks/text-columns/editor-rtl.css 95 B
build/block-library/blocks/text-columns/editor.css 95 B
build/block-library/blocks/text-columns/style-rtl.css 165 B
build/block-library/blocks/text-columns/style.css 165 B
build/block-library/blocks/verse/style-rtl.css 98 B
build/block-library/blocks/verse/style.css 98 B
build/block-library/blocks/video/editor-rtl.css 541 B
build/block-library/blocks/video/editor.css 542 B
build/block-library/blocks/video/style-rtl.css 192 B
build/block-library/blocks/video/style.css 192 B
build/block-library/blocks/video/theme-rtl.css 134 B
build/block-library/blocks/video/theme.css 134 B
build/block-library/classic-rtl.css 179 B
build/block-library/classic.css 179 B
build/block-library/common-rtl.css 1.1 kB
build/block-library/common.css 1.1 kB
build/block-library/editor-elements-rtl.css 75 B
build/block-library/editor-elements.css 75 B
build/block-library/editor-rtl.css 11.9 kB
build/block-library/editor.css 11.9 kB
build/block-library/elements-rtl.css 54 B
build/block-library/elements.css 54 B
build/block-library/index.min.js 217 kB
build/block-library/reset-rtl.css 472 B
build/block-library/reset.css 472 B
build/block-library/style-rtl.css 14.7 kB
build/block-library/style.css 14.7 kB
build/block-library/theme-rtl.css 702 B
build/block-library/theme.css 707 B
build/block-serialization-default-parser/index.min.js 1.12 kB
build/block-serialization-spec-parser/index.min.js 2.87 kB
build/blocks/index.min.js 52.4 kB
build/commands/index.min.js 16.1 kB
build/commands/style-rtl.css 955 B
build/commands/style.css 952 B
build/components/index.min.js 224 kB
build/components/style-rtl.css 12.1 kB
build/components/style.css 12.1 kB
build/compose/index.min.js 12.9 kB
build/core-commands/index.min.js 2.81 kB
build/core-data/index.min.js 73.1 kB
build/customize-widgets/index.min.js 11 kB
build/customize-widgets/style-rtl.css 1.35 kB
build/customize-widgets/style.css 1.35 kB
build/data-controls/index.min.js 641 B
build/data/index.min.js 8.98 kB
build/date/index.min.js 18 kB
build/deprecated/index.min.js 458 B
build/dom-ready/index.min.js 325 B
build/dom/index.min.js 4.65 kB
build/edit-post/classic-rtl.css 578 B
build/edit-post/classic.css 580 B
build/edit-post/index.min.js 12.6 kB
build/edit-post/style-rtl.css 2.31 kB
build/edit-post/style.css 2.31 kB
build/edit-site/index.min.js 215 kB
build/edit-site/posts-rtl.css 6.84 kB
build/edit-site/posts.css 6.85 kB
build/edit-site/style-rtl.css 12.2 kB
build/edit-site/style.css 12.2 kB
build/edit-widgets/index.min.js 17.7 kB
build/edit-widgets/style-rtl.css 4.2 kB
build/edit-widgets/style.css 4.2 kB
build/editor/index.min.js 100 kB
build/editor/style-rtl.css 9.34 kB
build/editor/style.css 9.33 kB
build/element/index.min.js 4.83 kB
build/escape-html/index.min.js 537 B
build/format-library/index.min.js 8.07 kB
build/format-library/style-rtl.css 476 B
build/format-library/style.css 476 B
build/hooks/index.min.js 1.54 kB
build/html-entities/index.min.js 445 B
build/i18n/index.min.js 3.58 kB
build/interactivity/debug.min.js 16.5 kB
build/interactivity/file.min.js 447 B
build/interactivity/image.min.js 1.78 kB
build/interactivity/index.min.js 13.4 kB
build/interactivity/navigation.min.js 1.16 kB
build/interactivity/query.min.js 742 B
build/interactivity/router.min.js 2.8 kB
build/interactivity/search.min.js 615 B
build/is-shallow-equal/index.min.js 526 B
build/keyboard-shortcuts/index.min.js 1.31 kB
build/keycodes/index.min.js 1.46 kB
build/list-reusable-blocks/index.min.js 2.16 kB
build/list-reusable-blocks/style-rtl.css 846 B
build/list-reusable-blocks/style.css 846 B
build/media-utils/index.min.js 2.92 kB
build/modules/importmap-polyfill.min.js 12.3 kB
build/notices/index.min.js 946 B
build/nux/index.min.js 1.59 kB
build/nux/style-rtl.css 749 B
build/nux/style.css 745 B
build/patterns/index.min.js 7.36 kB
build/patterns/style-rtl.css 687 B
build/patterns/style.css 685 B
build/plugins/index.min.js 1.81 kB
build/preferences-persistence/index.min.js 2.06 kB
build/preferences/index.min.js 2.9 kB
build/preferences/style-rtl.css 554 B
build/preferences/style.css 554 B
build/primitives/index.min.js 829 B
build/priority-queue/index.min.js 1.54 kB
build/private-apis/index.min.js 1.01 kB
build/react-i18n/index.min.js 630 B
build/react-refresh-entry/index.min.js 9.47 kB
build/react-refresh-runtime/index.min.js 6.76 kB
build/redux-routine/index.min.js 2.69 kB
build/reusable-blocks/index.min.js 2.54 kB
build/reusable-blocks/style-rtl.css 256 B
build/reusable-blocks/style.css 256 B
build/rich-text/index.min.js 10.1 kB
build/router/index.min.js 1.96 kB
build/server-side-render/index.min.js 1.94 kB
build/shortcode/index.min.js 1.4 kB
build/style-engine/index.min.js 2.03 kB
build/token-list/index.min.js 581 B
build/url/index.min.js 3.85 kB
build/vendors/react-dom.min.js 41.7 kB
build/vendors/react-jsx-runtime.min.js 560 B
build/vendors/react.min.js 4.02 kB
build/viewport/index.min.js 965 B
build/warning/index.min.js 250 B
build/widgets/index.min.js 7.19 kB
build/widgets/style-rtl.css 1.16 kB
build/widgets/style.css 1.16 kB
build/wordcount/index.min.js 1.03 kB

compressed-size-action

@DaniGuardiola
Copy link
Contributor Author

Did a first pass with the codemod. It seems to have worked pretty well (0fcf959), but there are some things to take care of manually. Some code would silently fail (renders outside of "it" functions) and there are a few errors due to the differences in API between RTL and the Ariakit test library.

@DaniGuardiola DaniGuardiola mentioned this pull request Aug 2, 2024
18 tasks
@DaniGuardiola DaniGuardiola changed the title Added lint rules. Components: consistently use rendering and event trigger utilities from @ariakit/test Aug 2, 2024
@DaniGuardiola
Copy link
Contributor Author

DaniGuardiola commented Aug 2, 2024

After the codemod pass, I did a manual pass (2919849) to fix all remaining type errors and test failures. Here's a comprehensive list of the types of changes I've had to manually execute and why:

  • @ariakit/test's render doesn't return a container, and the simple solution to this is to create it manually and pass it as input. In some cases, a container is needed once in a test file, so it is created inline. In most cases though, containers are used many times, and a simple createContainer utility is created in the file for simplicity.
  • @ariakit/test's render doesn't return a baseElement. However, unless configured otherwise in a render call, the base element is just document.body. Instead of obtaining baseElement from render, we can simply use document.body.
  • In my codemod, I forgot that it can also be called test, so it missed a few cases. I just manually added await to render and rerender calls, and made test functions async if they weren't already.
  • Some render calls weren't found and transformed by the codemod because it only targets calls inside test functions (it()). This happens when tests abstract render under utility functions like renderPanel, renderWrappedItemInPanel, etc. The solution is to manually add await to those, make the utility function async if it wasn't previously, and then await them where they're being called.
  • In some cases, tests are checking whether trying to render a certain tree throws an error. Before, render was synchronous so doing expect(() => render(...)).toThrow() was enough, but now that needs to be transformed into await expect(() => render(...)).rejects.toThrow() to account for the newly asynchronous nature of render.

This fixes everything except for:

  • Some snapshot tests in ToggleGroupControl tests fail and are very fragile, with different runs showing slightly different variants of the rendered HTML tree. This makes sense if there's some dynamic animations or transitions going on, which is natural. The new asynchronous nature of render means that these snapshots are more sensitive to this. I propose that we just remove these snapshots entirely. There are strong arguments against snapshot testing in general that I agree with.
  • There is one flaky assertion that seems tricky in the DropdownMenu tests: after rendering it with defaultOpen, it checks whether the menu element is focused. This sometimes passes, and sometimes it fails because the focused element is a menu item. even when commenting it out, the following assertions also fail sometimes, probably because the starting focused element is different and alters the sequence. This one will probably need a bit more debugging. I tried adding a long wait before the interactions but it doesn't seem to work.

Finally, there's a potential opportunity to remove the renderAndValidate function in composite tests (see TODO comment).

@DaniGuardiola DaniGuardiola changed the title Components: consistently use rendering and event trigger utilities from @ariakit/test Components: consistently use render from @ariakit/test Aug 2, 2024
@DaniGuardiola
Copy link
Contributor Author

DaniGuardiola commented Aug 2, 2024

Update: I decided to simply revert to the render utility from RTL (I called it renderSync for clarity) to work around the issue mentioned in the previous comment (snapshots + flaky menu test). This way, this PR can land without waiting for resolution on those two issues, which will be left for a follow up. See d48ad4d

I also decided to address user events in a separate PR, to keep this one focused - it's already pretty big as it is.

@DaniGuardiola DaniGuardiola self-assigned this Aug 2, 2024
@DaniGuardiola DaniGuardiola added [Type] Code Quality Issues or PRs that relate to code quality [Package] Components /packages/components labels Aug 2, 2024
@DaniGuardiola DaniGuardiola marked this pull request as ready for review August 2, 2024 16:09
Copy link

github-actions bot commented Aug 2, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: DaniGuardiola <daniguardiola@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>
Co-authored-by: diegohaz <hazdiego@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@DaniGuardiola DaniGuardiola requested a review from a team August 2, 2024 16:11
Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

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

Thanks for working on it @DaniGuardiola!

I'm a bit torn on having double standards for testing our components. I believe the entire repo should use a consistent approach for testing. With that in mind, to me it doesn't make much sense to force the components package to one approach, and leave the rest to use the other. If we all agree on a particular approach, then I'd advise we migrate the entire repository to it, update all documentation accordingly and announce it to the community properly.

Also, RTL is at this time the officially recommended testing library for React, and we need a really strong reason to move away from it. Especially considering that RTL might not necessarily be part of ariakit/test's future. I really wish there was a better way, even if we have to be more robust in our tests.

@DaniGuardiola
Copy link
Contributor Author

DaniGuardiola commented Aug 5, 2024

@tyxla that's a fair concern, though I would highlight a few observations:

  • The RTL render and user event utils unfortunately don't account for a technique that Ariakit uses extensively: taking advantage of microtasks, re-renders and frames (i.e. RAF). This technique has many advantages in some cases, such as being able to render something to the DOM, measuring something from the result, and then doing further changes (here's a specific example). This process can even take a few frames or ticks to finalize. There is no impact for the user, as these things mostly happen instantly under perceived human time.
  • React has act which is used in some of the RTL utils, but it is more limited and doesn't fully cover our needs when testing Ariakit-based components and their effects.
  • I think it's important to understand what RTL is doing under the hood. When testing the DOM, you could very easily just set up a barebones JSDOM environment, add some elements (e.g. document.createElement, someElement.appendChild, etc), and then use basic DOM methods to "query" and assert (e.g. document.querySelector, expect(element.getAttribute('something')).toBe('expected value')). Even with React, you could run React.createRoot and all that and get a test working. RTL utilities such as render, screen.queryBy or user events simply abstract this complexity into nicer APIs.
  • I do see a lot of value in utilities like this. However, as explained, the RTL ones fall short when components such as Ariakit's use the techniques outlined above. The Ariakit upgrade outlined this fact, and @ariakit/test provides alternative utilities that do work. These utilities are quite simple, and you can verify this by looking at the code. If we didn't have @ariakit/test, then we'd have to either bend RTL in hacky ways to work for us or create our own testing utilities that would look almost exactly like Ariakit's.
  • Under the hood, all of these use the same "DOM backend", namely JSDOM. Both are compatible.
  • In the components package, we use Ariakit extensively. This means that the shortcomings of RTL are gonna get in the way very often. An example of this is that when doing a bump of @ariakit/react to the next patch version, a bunch of tests started failing due to this reason. The changes that triggered this were not documented, because they're implementation details.
  • The pragmatic solution to reduce impact in developer time and frustration in the long run is to consistently use these APIs.

Regarding its use in the components package, I'd say the fact that we use Ariakit extensively is a good reason to enforce it. Whether it should be used across the monorepo is a separate discussion IMO, though my hunch is that yes, we probably should (at least render and user events, query utils are more a matter of taste). I do not know @diegohaz's long-term intentions with @ariakit/test, but it does seem to me like an improvement over RTL in many ways.

In any case, since both libraries can coexist I don't think this should be a big concern for now, and enforcing only in the components package is good enough to meet our pragmatic goals.

I recommend reading my discussion with @ciampo about enforcing in components package / use outside of it: #64066 (comment)

Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

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

Thanks for the thorough elaboration on it @DaniGuardiola! Makes a lot of sense, and I'm generally not opposed to using @ariakit/test, especially if we have really good reasons to prefer it. I do, however, have some concerns, as you will see below.

I've read the discussion with @ciampo you linked to, and I think a good reason to reach a compromise is to expose a layer with testing functionality and use that. This is what we do with Ariakit, too - we don't expose it directly; rather, we expose components that use it. Why not do the same with tests? If I understand correctly, this is what Marco suggested, too. Such an approach can help with concealing implementation details and would make an eventual migration to another testing approach a breeze. Unfortunately, it would still add some maintenance costs (we'll have to maintain that layer).

I do have a few concerns that are worth mentioning, too, and can help evaluate if the effort is worth the time, and if it's the right time for switching to @ariakit/test:

  • RTL is recommended as part of the React 19 migration. Yes, it's in the context of deprecating shallow rendering practices, but still, RTL is the preferred react testing library, and if we move away from that, we'll need to spend a larger effort on convincing developers why that's a good idea, educating them on the new best practices, and updating all documentation and examples (some of which we may not have control over) across all sources.
  • @ariakit/test falls behind on any developer documentation - there are no docs on the site or in the repo; it actually doesn't even have a README. If we're going to use it (and enforce it), it needs to be really well documented, otherwise it can really hurt the developer experience. I don't think there's a good way around that.
  • Consistency is important for the @wordpress/components package, but also beyond it and across the entire monorepo. I'd very much favor using the same approach for testing all components in Gutenberg, not just @wordpress/components. I don't see a good reason to limit any testing approach to solely @wordpress/components. That can make the effort bigger, which is worth considering.
  • Being future-proof is important as we're betting on WordPress living for many more years. When making choices for tools we use, we need to be careful about the bus factor of these tools, and I'm worried @ariakit/test has been worked on almost exclusively by a single person.

It can be helpful to get some more feedback on this one. I'm curious to hear what @ciampo, @mirka, and @jsnajdr could add to the discussion.

@jsnajdr
Copy link
Member

jsnajdr commented Aug 7, 2024

I don't think this is a controversial change or that there are some long-term consequences. The @ariakit/test methods are wrappers around @testing-library/{react,dom}, we're not switching to a new library. They introduce techniques that avoid running in the act() environment and better simulate what is really going on in the browser.

When I see Ariakit PRs like ariakit/ariakit#2894 I see that @diegohaz has been implementing my suggestions, which is another evidence that all this is a good idea 🙂

The @ariakit/test documentation could certainly be improved. Also there is probably no reason why Ariakit render shouldn't return all the fields returned by RTL render. Then it would be a drop-in replacement and we wouldn't have to worry about containers and baseElements. The only change in the API would be promisified render and rerender. But that's all an opportunity for contributon, not a blocker for this PR.

Another thing that I slightly dislike is that @testing-library/react is a direct dependency of @ariakit/test. The same library is also a dependency of my project, and they could possibly conflict, be duplicated etc. It would be better if RTL was just a peer dependency, and my project would do the wrapping myself:

// test-helpers.js
import { render } from '@testing-library/react';
import { wrapRender } from '@ariakit/test';
export const render = wrapRender( render );

Then my tests would import render from a local test-helpers module, not directly from a 3rd party library. This also implements the "custom render" pattern recommented by RTL documentation itself.

Yes, probably all unit tests should eventually use @ariakit/test, but it doesn't need to happen all at once.

@DaniGuardiola
Copy link
Contributor Author

@jsnajdr thanks for your thoughts, I agree for the most part. I would add that RTL is an implementation detail though, and @ariakit/test might remove it with no consequence or incompatibility problems since the effect is the same in the DOM (JSDOM in this case). Any RTL code will continue to co-exist in exactly the same way.

Also there is probably no reason why Ariakit render shouldn't return all the fields returned by RTL render.

See ariakit/ariakit#3939 (comment)

@tyxla
Copy link
Member

tyxla commented Aug 9, 2024

I agree it doesn't have to happen all at once - we just need a solid plan that covers all existing tests and execute on it step by step.

Realistically, the biggest concern right now is @ariakit/test's lack of documentation, as it can hurt developer experience, especially if we enforce it.

I wonder if @diegohaz considers adding documentation as one of the short-term project priorities.

@jsnajdr
Copy link
Member

jsnajdr commented Aug 9, 2024

Reading ariakit/ariakit#3939 I realize that @ariakit/test is more ambitious than I thought. It plans to be a standalone testing library completely independent from RTL. Here I would understand the concerns: RTL is certainly much better documented and has far bigger mindshare, and the benefits of migration are not very clear. What is for example the benefit of the @ariakit/test query API over the RTL query API?

What I think is not controversial is the rendering wrapper around render and rerender that makes them async and waits a little before all the rendering effects and timers settle down. But it seems to me that at this moment we don't need anything more. We need to flush microtasks and wait for RAFs only in render, don't we? Or does it also affect the query API?

The RTL render and user event utils unfortunately don't account for a technique that Ariakit uses extensively: taking advantage of microtasks, re-renders and frames (i.e. RAF). This technique has many advantages in some cases, such as being able to render something to the DOM, measuring something from the result, and then doing further changes

One thing I never understood about these Ariakit techniques is why the same can't be accomplished with effects and layout effects. If you want something to render in DOM and then be able to measure it, that's what useLayoutEffect is for! The layout effect runs after changes have been made in DOM and layout has been recalculated. You can measure anything and schedule a setState that does further modifications. And it all happens before actual paint, so the user ever sees only the final result on the screen.

@diegohaz
Copy link
Member

diegohaz commented Aug 9, 2024

I wonder if @diegohaz considers adding documentation as one of the short-term project priorities.

@ariakit/test is not a priority right now. We can add JSDocs as a short-term project, but proper documentation will have to wait a bit longer.

To clarify, @ariakit/test is not required for testing Ariakit components. I usually recommend testing against a real browser (using Playwright, for example). RTL is great, but it wasn't enough for us to test not only Ariakit but also other libraries like Framer Motion and Radix UI, for which we also have examples. There are no immediate plans to remove RTL as a dependency, but it's currently an implementation detail.

Alternatively, an issue could be raised in the RTL repo to address microtasks and other timers in render (or perhaps renderAsync) and user events. In summary, if something works in the browser, it should work in tests as long as JSDOM supports it. @ariakit/test was created for this reason. Testing browser behavior is essential to Ariakit, and we needed to iterate faster, which is why it's part of the Ariakit packages.

@tyxla
Copy link
Member

tyxla commented Aug 9, 2024

Thanks for chiming in @diegohaz, much appreciated!

@ariakit/test is not a priority right now. We can add JSDocs as a short-term project, but proper documentation will have to wait a bit longer.

That's a bummer, and a real blocker if we're to force @ariakit/test in my opinion.

I usually recommend testing against a real browser (using Playwright, for example)

Since e2e tests are slow and time-consuming, we try to use them mostly for testing entire flows. Component tests with RTL, flawed as they are, still provide a much faster way to test against components, and in many cases, that's enough. I think that in favor of developer experience, we need to maintain this tricky balance of having both e2es and component tests.

Alternatively, an issue could be raised in the RTL repo to address microtasks and other timers in render (or perhaps renderAsync) and user events.

That would make a lot of sense! I'd be surprised if we were the only ones to need that.

@DaniGuardiola
Copy link
Contributor Author

I'm not sure why it'd be a blocker. The render and event trigger utilities are quite straightforward, already do what we need, and are easy to contribute to at any time, or even fork locally if it's ever necessary (as I already did in the Ariakit upgrade).

With a bit of JSDOC we're pretty much set on the documentation side of things, and it's 100% compatible with anything else from RTL so we have zero lock-in and can mix and match.

What's the specific issue, short or long-term, that would make this a blocker?

@tyxla
Copy link
Member

tyxla commented Aug 12, 2024

The problem is that right now, only we know those details that you're explaining. Someone else who's aiming to contribute component tests will not be aware of those nuances and details, and that can be a blocker for them. This is undesirable, and we should not let it happen IMO.

So, if the @ariakit/test utils are 100% compatible with RTL like you're saying, let's document that. Let's link to the RTL docs where appropriate, so folks with less experience know where to look.

If you're still unsure, try to put yourself in the shoes of a new contributor. Where would they start? How would they know what and how to use without reading the testing library code? If that part is covered and we have sufficient documentation, we would have solved this blocker (for the most part).

@diegohaz
Copy link
Member

So, if the @ariakit/test utils are 100% compatible with RTL like you're saying, let's document that. Let's link to the RTL docs where appropriate, so folks with less experience know where to look.

I think @DaniGuardiola meant Ariakit Test and RTL can be used together (render, queries, user events, etc.) since they both deal with the (JS)DOM, not any unique aspect of either. The APIs are not equivalent, so linking to RTL docs may not be sufficient.

I agree with @tyxla that adopting something like this project-wide would require proper documentation. It's not only time-consuming, but Ariakit Test isn't quite ready for that yet. We've added a README to clarify this: https://www.npmjs.com/package/@ariakit/test

I initially suggested some Ariakit Test user events to @ciampo as a workaround for issues caused by RTL and as an easy way to check if the failure was due to microtasks or timers. However, I believe the best path for WordPress is to get the RTL packages to consider these factors.

render is not a big problem since you can write a helper to wait for microtasks/paint right after the render call (which is what Ariakit Test is currently doing). However, user events may require internal changes to the RTL package because microtasks should be flushed after every single event. For example, user.click will trigger mouseover, pointermove, mousedown, pointerdown, mouseup, etc., and microtasks should be flushed between each of them.

@DaniGuardiola
Copy link
Contributor Author

Honestly, I don't see any of this as a big deal. We simply need to wait for some microtasks to be flushed after render and events. The ariakit test library does this, so we use it.

I agree we need to document this (it already is one of the follow-up tasks in the Ariakit upgrade PR, along with this one), which can be done in about a 4 line paragraph.

If we really think ariakit test is not the way to go, then sure, let's fork it locally. I personally don't think that's the right call as it's added maintenance with no apparent (to me) advantages, but I'm fine with the decision for the sake of moving this forward and making tests work long term, which is the goal of this PR.

To be clear I also support the idea of having RTL add these features, though it seems unlikely to happen any time soon if it happens at all, so it shouldn't block this effort imo.

@tyxla
Copy link
Member

tyxla commented Aug 13, 2024

The APIs are not equivalent, so linking to RTL docs may not be sufficient.

That's my understanding as well. I was surprised when @DaniGuardiola claimed 100% compatibility. Especially considering that @ariakit/test may go in a different direction in the future, and to intentionally not follow the RTL APIs.

However, I believe the best path for WordPress is to get the RTL packages to consider these factors.

To be clear I also support the idea of having RTL add these features, though it seems unlikely to happen any time soon if it happens at all, so it shouldn't block this effort imo.

I agree with @diegohaz here. Can we realistically pursue contributing this upstream to RTL @DaniGuardiola?

Honestly, I don't see any of this as a big deal. We simply need to wait for some microtasks to be flushed after render and events. The ariakit test library does this, so we use it.

This is where we disagree. If we just use it where it's necessary, that's fine. But if we enforce the entire package to use that approach, then it becomes a bigger deal to me.

If we really think ariakit test is not the way to go, then sure, let's fork it locally.

I'm strongly against those local forks because this adds extra maintenance costs (we know how temporary solutions become permanent when we add the factor "time") and loses the opportunity to fix the issue upstream, which is the responsible, community-appreciative way to approach this problem IMHO.

@DaniGuardiola
Copy link
Contributor Author

Let me be clear: RTL and Ariakit Test are 100% compatible, in the same sense that jQuery and document.querySelector are compatible.

Both are libraries that do stuff in a shared DOM. I can render with RTL, get elements with Ariakit Test, and trigger events with RTL. I can render with Ariakit Test, get elements with RTL, and trigger events with Ariakit Test. I can render with React.createRoot, get elements with document.querySelector, and trigger events with element.click. It's all 100% compatible.

Of course, RTL's render has a different API to React.createRoot and Ariakit Tests' render. Different API's != incompatible.

@tyxla
Copy link
Member

tyxla commented Aug 13, 2024

Let me be clear: RTL and Ariakit Test are 100% compatible, in the same sense that jQuery and document.querySelector are compatible.

Both are libraries that do stuff in a shared DOM. I can render with RTL, get elements with Ariakit Test, and trigger events with RTL. I can render with Ariakit Test, get elements with RTL, and trigger events with Ariakit Test. I can render with React.createRoot, get elements with document.querySelector, and trigger events with element.click. It's all 100% compatible.

Of course, RTL's render has a different API to React.createRoot and Ariakit Tests' render. Different API's != incompatible.

Makes sense. But then you can see why documentation is so important, and why enforcing the different APIs without proper documentation is problematic.

As I recommended in my earlier reply, the best long-term solution would be to resolve this upstream in RTL. In the meantime, we could live with RTL and use @ariakit/test only when necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants