Skip to content

flutter test: (includes patch) experimental faster testing - support for paths with '-' character and also workspaces #168657

Closed

Description

@time4tea

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'\', '_');
 }
 

Activity

  1. time4tea commented on May 12, 2025

    @time4tea
    Author

    (CLA Agreed)

  2. darshankawar commented on May 13, 2025

    @darshankawar
    Member

    @time4tea
    Have you raised PR for this as it looks more like changes you are proposing to make to include - char and workspace.

  3. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on May 13, 2025
  4. time4tea commented on May 13, 2025

    @time4tea
    Author

    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!

  5. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on May 13, 2025
  6. added
    a: tests"flutter test", flutter_test, or one of our tests
    frameworkflutter/packages/flutter repository. See also f: labels.
    and removed
    in triagePresently being triaged by the triage team
    on May 14, 2025
  7. added
    has partial patchThere is a PR awaiting someone to take it across the finish line
    P3Issues that are less important to the Flutter project
    on Jun 4, 2025
  8. vladimir-ionita commented on Aug 8, 2026

    @vladimir-ionita

    The hyphen case appears to be fixed on current beta/master.

    pathToImport in packages/flutter_tools/lib/src/test/runner.dart changed from an enumerated chain to a character-class regex:

    // 3.44.6 stable (runner.dart:277-282) — omits '-'
    .replaceAll('.', '_').replaceAll(':', '_').replaceAll('/', '_')
    
    // 3.47.0-0.4.pre beta (runner.dart:283) — covers all non-alphanumerics
    .replaceAll(RegExp(r'[^a-zA-Z0-9]'), '_')

    Verified present in 3.47.0-0.4.pre (034409942b) and absent in 3.44.6 (ee80f08bbf).

    One caveat before closing: fixing sanitization makes hyphenated paths reach a second, separate failure — package: self-imports fail to resolve, because PackageConfig.parseBytes is passed the project directory rather than the package_config.json URI. Filed separately as #190784. So a hyphenated-path project may still fail after this fix, for a different reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projecta: tests"flutter test", flutter_test, or one of our testsframeworkflutter/packages/flutter repository. See also f: labels.has partial patchThere is a PR awaiting someone to take it across the finish lineteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions