平衡旧技巧与新成就:Slack中基于人工智能的从Enzyme到React Testing Library的转换

In the world of frontend development, one thing remains certain: change is the only constant. New frameworks emerge, and libraries can become obsolete without warning. Keeping up with the ever-changing ecosystem involves handling code conversions, both big and small. One significant shift for us was the transition from Enzyme to React Testing Library (RTL), prompting many engineers to convert their test code to a more user-focused RTL approach. While both Enzyme and RTL have their own strengths and weaknesses, the absence of native support for React 18 by Enzyme presented a compelling rationale for transitioning to RTL. It’s so compelling that we at Slack decided to convert more than 15,000 of our frontend unit and integration Enzyme tests to RTL, as part of the update to React 18.

在前端开发的世界中,有一件事是确定的:变化是唯一的常数。新的框架出现,库可能会突然过时。跟上不断变化的生态系统需要处理各种大小的代码转换。对我们来说,一个重大的转变是从Enzyme转向React Testing Library(RTL),促使许多工程师将他们的测试代码转换为更注重用户的RTL方法。虽然Enzyme和RTL都有各自的优点和缺点,但Enzyme对React 18的原生支持的缺失为转向RTL提供了有力的理由。这一理由如此强大,以至于我们在Slack决定将超过15,000个前端单元测试和集成测试的Enzyme测试转换为RTL,作为升级到React 18的一部分。

We started by exploring the most straightforward avenue of seeking out potential Enzyme adapters for React 18. Unfortunately, our search yielded no viable options. In his article titled “Enzyme is dead. Now what?“, Wojciech Maj, the author of the React 17 adapter, unequivocally suggested, “you should consider looking for Enzyme alternative right now.”

我们首先尝试了寻找React 18的潜在Enzyme适配器的最直接途径。不幸的是,我们的搜索没有找到可行的选项。在他的文章《Enzyme is dead. Now what?》中,React 17适配器的作者Wojciech Maj毫不含糊地建议说:“你应该考虑立即寻找Enzyme的替代品。”

complicated adapter

Adapter illustrating the mismatch and incompatibility of React 18 and Enzyme

适配器展示了React 18和Enzyme之间的不匹配和不兼容

Considering our ultimate goal of updating to React 18, which Enzyme does not support, we started with a thorough analysis of the problem’s scope and ways to automate this process. Our initiative began with a monumental task of converting more than 15,000 Enzyme test cases, which translated to more than 10,000 potential engineering hours. At that scale ...

开通本站会员,查看完整译文。

首页 - Wiki
Copyright © 2011-2024 iteam. Current version is 2.139.0. UTC+08:00, 2024-12-22 19:05
浙ICP备14020137号-1 $访客地图$