@@ -15,6 +15,7 @@ import 'package:test_api/src/backend/runtime.dart'; // ignore: implementation_im
1515import 'package:test_core/src/executable.dart'
1616 as test; // ignore: implementation_imports
1717
18+ import 'exceptions.dart' ;
1819import 'integration_tests_manager.dart' ;
1920import 'supported_browsers.dart' ;
2021import 'test_platform.dart' ;
@@ -151,6 +152,26 @@ class TestCommand extends Command<bool> with ArgUtils {
151152 }
152153
153154 await _buildTests (targets: targetFiles);
155+
156+ // Many tabs will be left open after Safari runs, quit Safari during
157+ // cleanup.
158+ if (browser == 'safari' ) {
159+ cleanupCallbacks.add (() async {
160+ // Only close Safari if felt is running in CI environments. Do not close
161+ // Safari for the local testing.
162+ if (io.Platform .environment['LUCI_CONTEXT' ] != null || isCirrus) {
163+ print ('INFO: Safari tests ran. Quit Safari.' );
164+ await runProcess (
165+ 'sudo' ,
166+ ['pkill' , '-lf' , 'Safari' ],
167+ workingDirectory: environment.webUiRootDir.path,
168+ );
169+ } else {
170+ print ('INFO: Safari tests ran. Please quit Safari tabs.' );
171+ }
172+ });
173+ }
174+
154175 if (runAllTests) {
155176 await _runAllTests ();
156177 } else {
@@ -179,7 +200,7 @@ class TestCommand extends Command<bool> with ArgUtils {
179200 bool get runAllTests => targets.isEmpty;
180201
181202 /// The name of the browser to run tests in.
182- String get browser => stringArg ('browser' );
203+ String get browser => (argResults != null ) ? stringArg ('browser' ) : 'chrome' ;
183204
184205 /// Whether [browser] is set to "chrome".
185206 bool get isChrome => browser == 'chrome' ;
@@ -275,8 +296,7 @@ class TestCommand extends Command<bool> with ArgUtils {
275296
276297 void _checkExitCode () {
277298 if (io.exitCode != 0 ) {
278- io.stderr.writeln ('Process exited with exit code ${io .exitCode }.' );
279- io.exit (1 );
299+ throw ToolException ('Process exited with exit code ${io .exitCode }.' );
280300 }
281301 }
282302
@@ -290,9 +310,8 @@ class TestCommand extends Command<bool> with ArgUtils {
290310 );
291311
292312 if (exitCode != 0 ) {
293- io.stderr
294- .writeln ('Failed to run pub get. Exited with exit code $exitCode ' );
295- io.exit (1 );
313+ throw ToolException (
314+ 'Failed to run pub get. Exited with exit code $exitCode ' );
296315 }
297316 }
298317
@@ -333,9 +352,8 @@ class TestCommand extends Command<bool> with ArgUtils {
333352 );
334353
335354 if (exitCode != 0 ) {
336- io.stderr.writeln (
337- 'Failed to compile ${hostDartFile .path }. Compiler exited with exit code $exitCode ' );
338- io.exit (1 );
355+ throw ToolException ('Failed to compile ${hostDartFile .path }. Compiler '
356+ 'exited with exit code $exitCode ' );
339357 }
340358
341359 // Record the timestamp to avoid rebuilding unless the file changes.
@@ -363,9 +381,8 @@ class TestCommand extends Command<bool> with ArgUtils {
363381 );
364382
365383 if (exitCode != 0 ) {
366- io.stderr. writeln (
384+ throw ToolException (
367385 'Failed to compile tests. Compiler exited with exit code $exitCode ' );
368- io.exit (1 );
369386 }
370387 }
371388
0 commit comments