dart-migrate-to-checks-package
Original:🇺🇸 English
Translated
Replace the usage of `expect` and similar functions from `package:matcher` to `package:checks` equivalents.
13installs
Sourcedart-lang/skills
Added on
NPX Install
npx skill4agent add dart-lang/skills dart-migrate-to-checks-packageTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Migrating Dart Tests to Package Checks
Contents
- Dependency Management
- Syntax Migration Guidelines
- Utilizing Dart MCP Tools
- Migration Workflow
- Examples
Dependency Management
Manage dependencies using the Dart Tooling MCP Server tool or standard CLI commands.
pub- Add as a
package:checksusingdev_dependency.dart pub add dev:checks - Remove if it is explicitly listed in the
package:matcher(note: it is often transitively included bypubspec.yaml, which is fine).package:test - Import in all test files undergoing migration.
package:checks/checks.dart
Syntax Migration Guidelines
Transition test assertions from the syntax to the literate API provided by .
package:matcherpackage:checks- Basic Equality: Replace or
expect(actual, equals(expected))withexpect(actual, expected).check(actual).equals(expected) - Type Checking: Replace with
expect(actual, isA<Type>()).check(actual).isA<Type>() - Property Extraction: Replace with
expect(actual.property, expected).check(actual).has((a) => a.property, 'property name').equals(expected) - Cascades for Multiple Checks: Use Dart's cascade operator () to chain multiple expectations on a single subject.
.. - Asynchronous Expectations:
- If checking a ,
Futuretheawaitcall:check.await check(someFuture).completes((r) => r.equals(expected)); - If checking a , wrap it in a
Streamfor multiple checks, or useStreamQueuefor single/broadcast checks..withQueue
- If checking a
Utilizing Dart MCP Tools
Leverage the Dart MCP Server tools to automate and validate the migration process.
- Use to run
pubordart pub get.dart pub add - Use to run static analysis on the project or specific paths.
analyze_files - Use to execute Dart or Flutter tests with an agent-centric UX. ALWAYS use this instead of shell commands like
run_tests.dart test - Use to apply automated fixes if applicable.
dart_fix
Migration Workflow
Copy and use the following checklist to track progress when migrating a test suite:
- Task Progress
- Add as a dev dependency.
package:checks - Identify all test files using (
package:matchercalls).expect - Import in target test files.
package:checks/checks.dart - Rewrite all statements to
expect(...)statements.check(...) - Run static analyzer ().
analyze_files - Run tests ().
run_tests
- Add
Feedback Loop: Static Analysis
- Run the tool on the modified test directories.
analyze_files - Review any static analysis warnings or errors (e.g., missing imports, incorrect generic types on , unawaited futures).
isA - Fix the warnings.
- Repeat until the analyzer returns zero issues.
Feedback Loop: Test Validation
- Run the tool.
run_tests - If tests fail, review the failure output. provides detailed context (e.g.,
package:checks).Which: has length of <2> - Adjust the expectations or the underlying code to resolve the failure.
check() - Repeat until all tests pass.
Examples
Basic Assertions
Input ():
matcherdart
expect(someList.length, 1);
expect(someString, startsWith('a'));
expect(someObject, isA<Map>());Output ():
checksdart
check(someList).length.equals(1);
check(someString).startsWith('a');
check(someObject).isA<Map>();Composed Expectations
Input ():
matcherdart
expect('foo,bar,baz', allOf([
contains('foo'),
isNot(startsWith('bar')),
endsWith('baz')
]));Output ():
checksdart
check('foo,bar,baz')
..contains('foo')
..not((s) => s.startsWith('bar'))
..endsWith('baz');Asynchronous Futures
Input ():
matcherdart
expect(Future.value(10), completion(equals(10)));
expect(Future.error('oh no'), throwsA(equals('oh no')));Output ():
checksdart
await check(Future.value(10)).completes((it) => it.equals(10));
await check(Future.error('oh no')).throws<String>().equals('oh no');Asynchronous Streams
Input ():
matcherdart
var stdout = StreamQueue(Stream.fromIterable(['Ready', 'Go']));
await expectLater(stdout, emitsThrough('Ready'));Output ():
checksdart
var stdout = StreamQueue(Stream.fromIterable(['Ready', 'Go']));
await check(stdout).emitsThrough((it) => it.equals('Ready'));