Skip to content

[tool] Migrate TestCompiler and WebTestCompiler to modular dependency injection - #192923

Merged
auto-submit[bot] merged 4 commits into
flutter:masterfrom
bkonyi:di/21a-test-compiler
Sep 17, 2026
Merged

auto-submit[bot] merged 4 commits into
flutter:masterfrom
bkonyi:di/21a-test-compiler

Conversation

@bkonyi

@bkonyi bkonyi commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Description

This pull request migrates TestCompiler and WebTestCompiler in flutter_tools to modular dependency injection using ToolContext.

This is Layer 21a in the modular dependency injection migration for the testing subsystem.

Fork Compare Link

Tests

  • test/general.shard/test/test_compiler_test.dart
  • test/general.shard/test/web_test_compiler_test.dart

@bkonyi bkonyi added tool Affects the "flutter" command-line tool. See also t: labels. CICD Run CI/CD labels Sep 17, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors TestCompiler and WebTestCompiler to accept a ToolContext parameter, facilitating dependency injection and improving testability by reducing reliance on global variables. The review feedback suggests simplifying the WebTestCompiler constructor by making artifacts nullable to eliminate the custom sentinel class, avoiding redundant fallback context evaluations in TestCompiler by handling nullable contexts internally within _computeTestFilePath, and making the _FallbackToolContext constructor const.

Comment thread packages/flutter_tools/lib/src/test/web_test_compiler.dart Outdated
Comment thread packages/flutter_tools/lib/src/test/test_compiler.dart Outdated
Comment on lines +149 to +154
static String _computeTestFilePath(
ToolContext toolContext,
FlutterProject? flutterProject,
BuildInfo buildInfo,
) {
final ToolContext(:Config config, :FileSystem fs) = toolContext;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Update _computeTestFilePath to accept a nullable ToolContext? and fall back to const _FallbackToolContext() internally. This simplifies the call site in the constructor.

Suggested change
static String _computeTestFilePath(
ToolContext toolContext,
FlutterProject? flutterProject,
BuildInfo buildInfo,
) {
final ToolContext(:Config config, :FileSystem fs) = toolContext;
static String _computeTestFilePath(
ToolContext? toolContext,
FlutterProject? flutterProject,
BuildInfo buildInfo,
) {
final ToolContext context = toolContext ?? const _FallbackToolContext();
final ToolContext(:Config config, :FileSystem fs) = context;

Comment thread packages/flutter_tools/lib/src/test/test_compiler.dart Outdated
@bkonyi
bkonyi requested a review from dcharkes September 17, 2026 16:01
dcharkes
dcharkes previously approved these changes Sep 17, 2026
fileSystem: fs,
shutdownHooks: shutdownHooks,
config: config,
targetPlatform: TargetPlatform.tester,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spurious change because AI does not know shorthands?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does know about it, but chose to ignore it. Switch this back to use a dot shorthand.

pull Bot pushed a commit to fucheng-guo-sun/flutter that referenced this pull request Sep 25, 2026
…tter#192924)

## Description

This pull request migrates `CoverageCollector` in `flutter_tools` to
modular dependency injection using `ToolContext`.

This is Layer 21b in the modular dependency injection migration for the
testing subsystem (stacked on Layer 21a
[flutter#192923](flutter#192923)).

### Fork Compare Link
* Compare:
bkonyi/flutter@master...di/21b-coverage-collector

Part of [flutter#188471](flutter#188471).

## Tests
* `test/general.shard/coverage_collector_test.dart`
DanTup pushed a commit to DanTup/flutter that referenced this pull request Sep 28, 2026
…tter#192924)

## Description

This pull request migrates `CoverageCollector` in `flutter_tools` to
modular dependency injection using `ToolContext`.

This is Layer 21b in the modular dependency injection migration for the
testing subsystem (stacked on Layer 21a
[flutter#192923](flutter#192923)).

### Fork Compare Link
* Compare:
bkonyi/flutter@master...di/21b-coverage-collector

Part of [flutter#188471](flutter#188471).

## Tests
* `test/general.shard/coverage_collector_test.dart`
DanTup pushed a commit to DanTup/flutter that referenced this pull request Sep 28, 2026
…tter#192924)

## Description

This pull request migrates `CoverageCollector` in `flutter_tools` to
modular dependency injection using `ToolContext`.

This is Layer 21b in the modular dependency injection migration for the
testing subsystem (stacked on Layer 21a
[flutter#192923](flutter#192923)).

### Fork Compare Link
* Compare:
bkonyi/flutter@master...di/21b-coverage-collector

Part of [flutter#188471](flutter#188471).

## Tests
* `test/general.shard/coverage_collector_test.dart`
pull Bot pushed a commit to TheRakeshPurohit/flutter that referenced this pull request Sep 30, 2026
…injection (flutter#190789)

## Description

This pull request migrates `TestCommand`, `FlutterTestRunner`,
`FlutterPlatform`, `FlutterWebPlatform`, and `TestGoldenComparator` to
modular dependency injection using `ToolContext`.

This is Layer 21c in the modular dependency injection migration for the
testing subsystem (Layer 21a
[flutter#192923](flutter#192923) and Layer 21b
[flutter#192924](flutter#192924) have merged
into `master`).

### Fork Compare Link
* Compare:
bkonyi/flutter@master...di/21-testing-subsystem

Part of [flutter#188471](flutter#188471).

## Tests
* `test/commands.shard/hermetic/test_test.dart`
* `test/general.shard/flutter_platform_test.dart`
* `test/commands.shard/hermetic/flutter_web_platform_test.dart`
* `test/general.shard/test/test_golden_comparator_test.dart`
* `test/integration.shard/test_golden_comparator_test.dart`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants