dart-migrate-to-checks-package
Replace the usage of `expect` and similar functions from `package:matcher` to `package:checks` equivalents.
от flutter★ 3 224 звезды на GitHub
Установить dart-migrate-to-checks-package в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Migrating Dart Tests to Package Checks
Use this skill when you need to migrate a Dart test suite from the legacy
package:matcher (which is exported by default from package:test/test.dart)
to the modern, type-safe, and literate package:checks assertion library.
Contents
- When to Use This Skill
- How to Use This Skill (The Workflow)
- Key Syntax Differences and Pitfalls
- Matcher-to-Checks Mapping Table
- Matchers with No Direct Replacements
- Strategies for Discovery
- Examples
When to Use This Skill
- When asked to "migrate tests to checks", "use package:checks", or "modernize test assertions".
- When updating legacy test suites where static type safety, better autocomplete in IDEs, and highly detailed failure diagnostics are desired.
How to Use This Skill (The Workflow)
Follow this structured workflow to safely and systematically migrate a test suite:
1. Dependency Setup
- Add
package:checksas adev_dependencyinpubspec.yaml:dart pub add dev:checks - Remove
package:matcherif it is explicitly listed underdev_dependencies(it is typically transitively included bypackage:test, which is fine).
2. Identify and Plan Target Files
- Use the grep patterns in Strategies for Discovery
to locate all test files containing legacy
expectorexpectLatercalls. - Decide whether to migrate files fully or incrementally.
3. Migrating a File (Incremental or Full)
For any target test file:
- Update Imports:
- Replace the generic
import 'package:test/test.dart';with:import 'package:test/scaffolding.dart'; import 'package:checks/checks.dart'; - For Incremental Migration: If you only want to migrate some test cases
in the file, or want to migrate one step at a time, add:
import 'package:test/expect.dart'; // Temporarily allows legacy expect()
- Replace the generic
- Translate Assertions: Rewrite legacy
expectandexpectLatercalls tochecksyntax following the Key Syntax Differences and Pitfalls and the Matcher-to-Checks Mapping Table. - Verify via Compiler: If migrating fully, remove the
import 'package:test/expect.dart';line. Any remaining un-migratedexpectcalls will immediately surface as compiler errors, making them easy to find and fix.
4. Verification and Feedback Loops
- Static Analysis: Run static analysis on the target package:
Pay close attention to generic type parameters ondart analyze.isA<Type>()and ensure asynchronous expectations are properly awaited (check forunawaited_futureswarnings). - Run Tests: Execute the tests to verify both behavior and correct
assertion runtime logic:
If a test fails, review the extremely detailed failure output ofdart testpackage:checksto diagnose if the test is genuinely failing or if the expectation was translated incorrectly.
Key Syntax Differences and Pitfalls
[!IMPORTANT] A line-for-line translation can sometimes introduce subtle bugs or false passes. Always review these key differences carefully:
1. Collection Equality Pitfall (equals vs deepEquals)
- Legacy Matcher:
expect(actual, expected)orexpect(actual, equals(expected))performed a deep equality check if the arguments were collections (Lists, Maps, Sets). - Package Checks:
.equals(expected)corresponds strictly tooperator ==. Since Dart collections do not overrideoperator ==for element-wise comparison, using.equalson a collection will check for identity and almost certainly fail at runtime. - Remediation: You must replace collection equality assertions with
.deepEquals(expected).// BEFORE (Matcher) expect(myList, [1, 2, 3]); // AFTER (Checks) check(myList).deepEquals([1, 2, 3]);
2. The reason Parameter is now because
- Legacy Matcher: The explanation was passed as a trailing named
argument
reasontoexpect:expect(actual, expectation, reason: 'Explanation'); - Package Checks: The explanation is passed as the named argument
becauseto thecheckfunction before the actual subject:check(because: 'Explanation', actual).expectation();
3. Regular Expression Matching (matches vs matchesPattern)
- Legacy Matcher: The
matches(pattern)matcher automatically converted aStringargument into aRegExp(e.g.,matches(r'\d')matched'1'). - Package Checks:
.matchesPattern(pattern)treats aStringargument as a literal string pattern. - **Remedi
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл dart-migrate-to-checks-package?
Replace the usage of `expect` and similar functions from `package:matcher` to `package:checks` equivalents.
Как установить скилл dart-migrate-to-checks-package?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл dart-migrate-to-checks-package запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
AnthropicToolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
access
AnthropicManage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
configure
AnthropicSet up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
access
AnthropicManage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…