使用AI代理和AST迁移6000个React测试

Go to home page

November 21, 2025

2025年11月21日

The internet is flooded with very impressive vibe-style coding demos, but in my day-to-day job at Filestage we rarely start codebases from scratch and we have to deal with hundreds of thousands of lines of code and their dependencies.
I set out to explore if AI could help migrate our 970 test files with over 6000 test cases in our frontend from React Testing Library v13 to v14. How hard could it be...

互联网充斥着非常令人印象深刻的氛围风格编码演示,但在我在 Filestage 的日常工作中,我们很少从头开始构建代码库,我们必须处理 数十万行代码 及其依赖关系。
我开始探索 AI 是否可以帮助我们将前端的 970 个测试文件 和超过 6000 个测试用例 从 React Testing Library v13 迁移到 v14。 这会有多难呢……

Step 1: Preparing a migration guide

步骤1:准备迁移指南

At first, I naively told Claude Code CLI to migrate our codebase to the new package version. It started working, updated the package to the latest version, and then ran the tests. On every test failure, it tried to debug and fix the test, but there were too many test failures, so it started to spiral out of control.

起初,我天真地告诉 Claude Code CLI 将我们的代码库迁移到新包版本。它开始工作,更新了包到最新版本,然后运行测试。在每次测试失败时,它尝试调试并修复测试,但失败的测试 太多了,所以它开始 失控

I quickly understood this was not going to work, so I decided to dig deeper. I used the web version of Claude and using the research tool I asked it to build a migration guide and best practices. I read through this guide to learn about all the changes and oh boy there were a lot of them!

我很快意识到这行不通,所以我决定深入挖掘。我使用Claude的网页版,并利用研究工具请求它构建一个迁移指南和最佳实践。我阅读了这个指南,以了解所有的更改,哦,天哪,变化真多!

The update to v14 fundamentally changed how you write tests by making all APIs asynchronous and introducing a new setup pattern. This means a lot of code changes, but the worst part is that the timing behaviors also changed, which meant that many tests will start failing, others will have less coverage, and will require manual debugging to fix.

更新到v14 从根本上改变了你编写测试的方式,使所有API都变为异步并引入了一种新的设置模式。这意味着大量的代码更改,但最糟糕的是时序行为也发生了变化,这意味着许多测试将开始失败,其他测试的覆盖率会降低,并且需要手动调试来修复。

Step 2: Splitting into small changes

步骤 2:拆分为小更改

This update would require thousands of changes and would require days even with AI...

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

Accueil - Wiki
Copyright © 2011-2025 iteam. Current version is 2.148.1. UTC+08:00, 2025-12-02 02:50
浙ICP备14020137号-1 $Carte des visiteurs$