Balancing Old Tricks with New Feats: AI-Powered Conversion From Enzyme to React Testing Library at Slack

Update (October 2024): In response to numerous requests from external developers, we have open-sourced a version of our Enzyme to React Testing Library (RTL) conversion tool. You can now find it on npm, along with detailed instructions on how to integrate and use it in your projects. In the world of frontend development, one thing remains…

Sergii Gorbachov
18 min readintermediate
--
View Original

Overview

This article discusses Slack's transition from Enzyme to React Testing Library (RTL) for frontend testing, highlighting the challenges and solutions encountered during the conversion of over 15,000 tests. It details the use of AI and Abstract Syntax Tree (AST) transformations to automate the process, achieving a significant conversion success rate.

What You'll Learn

1

How to automate the conversion of Enzyme tests to React Testing Library using AI and AST techniques

2

Why transitioning to React Testing Library is essential for supporting React 18

3

How to evaluate the effectiveness of AI-powered code conversion tools

Prerequisites & Requirements

  • Familiarity with React Testing Library and Enzyme testing frameworks
  • Access to AI models and coding tools for AST transformations(optional)

Key Questions Answered

What challenges did Slack face when transitioning from Enzyme to RTL?
Slack faced significant challenges in finding viable Enzyme adapters for React 18, leading to the decision to convert over 15,000 tests to React Testing Library. The absence of native support for React 18 by Enzyme prompted this transition, highlighting the need for a user-focused testing approach.
How did Slack achieve an 80% conversion success rate?
By integrating both AST transformations and AI techniques, Slack was able to automate the conversion process effectively. This hybrid approach allowed them to leverage the strengths of both methods, resulting in a significant improvement in conversion accuracy and efficiency.
What was the impact of the AI-powered codemod on developer time?
The AI-powered codemod led to a documented 22% time saving for developers by successfully converting approximately 500 test cases across 338 files. This efficiency allowed developers to focus more on building new features rather than manual test conversions.

Key Statistics & Figures

Number of tests converted
15,000
Slack converted over 15,000 frontend unit and integration tests from Enzyme to React Testing Library.
Conversion success rate
80%
Achieved through a hybrid approach of AST and AI techniques.
Time saved for developers
22%
This represents the documented time savings from the automated conversion of test cases.

Technologies & Tools

Frontend
React Testing Library
Used as the target framework for converting tests from Enzyme.
Backend
Abstract Syntax Tree (ast)
Utilized for performing automated code transformations during the conversion process.
Backend
AI
Integrated into the workflow to assist in the conversion of test cases.

Key Actionable Insights

1
Integrate AI tools into your testing framework to enhance automation and efficiency.
Using AI for code conversion can significantly reduce manual effort, as demonstrated by Slack's success in transitioning to React Testing Library. This approach allows teams to focus on more complex tasks while improving overall productivity.
2
Utilize a hybrid approach combining AST transformations with AI models for code conversion.
This strategy proved effective for Slack, achieving an 80% conversion success rate. By leveraging both methods, teams can enhance accuracy and reduce the need for extensive manual adjustments.

Common Pitfalls

1
Relying solely on AI for code conversion can lead to inconsistent results.
Slack's experience showed that while AI can assist in automation, it may not always produce reliable outcomes without human oversight, particularly in complex scenarios.

Related Concepts

Frontend Testing Frameworks
Automated Testing Strategies
AI In Software Development