Compare commits

...
Author SHA1 Message Date
l0ng-ai 33bb5c5597 fix(run): run Dart test files with flutter test / dart test
A *_test.dart file ran with `dart run`, which can't load Flutter code
(dart:ui) and doesn't run package:test suites as tests. In a Flutter app
it now runs with `flutter test <file>` from the app's folder, elsewhere
with `dart test <file>`.
2026-11-19 11:16:54 +08:00
2 changed files with 15 additions and 0 deletions

No files matched your search

+10
View File
@@ -789,6 +789,16 @@ describe("project producers", () => {
cwd: "app",
debugAdapter: "dart",
});
// Its tests run with `flutter test`, a Dart package's with `dart test`.
expect(run({ path: `${ROOT}/app/test/widget_test.dart`, root: ROOT, configs: flutter })).toMatchObject({
command: "flutter",
args: ["test", "test/widget_test.dart"],
cwd: "app",
});
expect(run({ path: `${ROOT}/tool/test/gen_test.dart`, root: ROOT, configs: flutter })).toMatchObject({
command: "/bin/dart",
args: ["test", "tool/test/gen_test.dart"],
});
// Outside the app (a Dart package next to it): `dart run`.
expect(run({ path: `${ROOT}/tool/gen.dart`, root: ROOT, configs: flutter })).toMatchObject({
command: "/bin/dart",
+5
View File
@@ -1001,12 +1001,17 @@ export function produceFile(input: ContextInput, env: ToolEnv): Produced | null
s.idPath,
)[0]
: undefined;
// A test file runs its tests (`flutter test` / `dart test`); `dart run` can't run Flutter code.
const test = /_test\.dart$/.test(s.file);
if (app && test)
return { name: s.file, scope: "file", config: fileConfig(s, "dart", app.command, ["test", s.arg]) };
if (app)
return {
name: s.file,
scope: "file",
config: fileConfig(s, "flutter", app.command, ["run", "-t", s.arg], "dart"),
};
if (test) return simple(lang, s, env, "dart", () => ["test", s.arg]);
return simple(lang, s, env, "dart", () => ["run", s.arg], "dart");
}
case "scala":