Repository navigation
Closed
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projecta: tests"flutter test", flutter_test, or one of our tests"flutter test", flutter_test, or one of our testsframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has partial patchThere is a PR awaiting someone to take it across the finish lineThere is a PR awaiting someone to take it across the finish lineteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Description
here is a patch against 3.29.2 that fixes two issues:
- cannot use experimental test against directory structure that has a '-' character somewhere
- support for dart workspaces
diff --git a/packages/flutter_tools/lib/src/test/runner.dart b/packages/flutter_tools/lib/src/test/runner.dart
index 49f9d5846c..e71b47586a 100644
--- a/packages/flutter_tools/lib/src/test/runner.dart
+++ b/packages/flutter_tools/lib/src/test/runner.dart
@@ -187,6 +187,31 @@ interface class FlutterTestRunner {
}
}
+ static PackageConfig _findPackageConfig({
+ required FlutterProject flutterProject
+ }) {
+ String path = flutterProject.directory.path;
+ while (path.isNotEmpty) {
+ final File projectPackageConfigFile = globals.fs
+ .directory(path)
+ .childDirectory('.dart_tool')
+ .childFile('package_config.json');
+
+ if (projectPackageConfigFile.existsSync()) {
+ print("package_config.json was found in ${path}");
+
+ return PackageConfig.parseBytes(
+ projectPackageConfigFile.readAsBytesSync(),
+ projectPackageConfigFile.uri,
+ );
+ }
+ List<String> parts = path.split("/");
+ parts.removeLast();
+ path = parts.join("/");
+ }
+ throw Exception("package_config.json not found");
+ }
+
// To compile root_test_isolate_spawner.dart and
// child_test_isolate_spawner.dart successfully, we will need to pass a
// package_config.json to the frontend server that contains the
@@ -196,14 +221,7 @@ interface class FlutterTestRunner {
required FlutterProject flutterProject,
required File isolateSpawningTesterPackageConfigFile,
}) async {
- final File projectPackageConfigFile = globals.fs
- .directory(flutterProject.directory.path)
- .childDirectory('.dart_tool')
- .childFile('package_config.json');
- final PackageConfig projectPackageConfig = PackageConfig.parseBytes(
- projectPackageConfigFile.readAsBytesSync(),
- projectPackageConfigFile.uri,
- );
+ final PackageConfig projectPackageConfig = _findPackageConfig(flutterProject: flutterProject);
// The flutter_tools package_config.json is guaranteed to include
// package:ffi and package:test_core.
@@ -259,6 +277,7 @@ import 'package:test_api/backend.dart'; // flutter_ignore: test_api_import
.replaceAll('.', '_')
.replaceAll(':', '_')
.replaceAll('/', '_')
+ .replaceAll('-', '_')
.replaceAll(r'\', '_')
.replaceRange(path.length - '.dart'.length, null, '');
}
@@ -480,6 +499,7 @@ String pathToImport(String path) {
.replaceAll('.', '_')
.replaceAll(':', '_')
.replaceAll('/', '_')
+ .replaceAll('-', '_')
.replaceAll(r'\', '_');
}
Metadata
Metadata
Assignees
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projecta: tests"flutter test", flutter_test, or one of our tests"flutter test", flutter_test, or one of our testsframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has partial patchThere is a PR awaiting someone to take it across the finish lineThere is a PR awaiting someone to take it across the finish lineteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Activity
time4tea commentedon May 12, 2025
(CLA Agreed)
darshankawar commentedon May 13, 2025
@time4tea
Have you raised PR for this as it looks more like changes you are proposing to make to include
-char and workspace.time4tea commentedon May 13, 2025
sorry i can't really invest in shepherding a PR through some process - the code change is here on offer if it is useful. Cheers!
vladimir-ionita commentedon Aug 8, 2026
The hyphen case appears to be fixed on current beta/master.
pathToImportinpackages/flutter_tools/lib/src/test/runner.dartchanged from an enumerated chain to a character-class regex:Verified present in
3.47.0-0.4.pre(034409942b) and absent in3.44.6(ee80f08bbf).One caveat before closing: fixing sanitization makes hyphenated paths reach a second, separate failure —
package:self-imports fail to resolve, becausePackageConfig.parseBytesis passed the project directory rather than thepackage_config.jsonURI. Filed separately as #190784. So a hyphenated-path project may still fail after this fix, for a different reason.[flutter_tools, flutter_test] Deprecate --experimental-faster-testing (…