Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit f399a6a

Browse files
author
nturgut
committed
making changes to utils and adding cleanup after unit tests failed
1 parent 95393ef commit f399a6a

File tree

3 files changed

+38
-37
lines changed

3 files changed

+38
-37
lines changed

lib/web_ui/dev/felt.dart

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import 'package:args/command_runner.dart';
99

1010
import 'build.dart';
1111
import 'clean.dart';
12-
import 'common.dart';
13-
import 'environment.dart';
1412
import 'licenses.dart';
1513
import 'test_runner.dart';
1614
import 'utils.dart';
@@ -39,7 +37,7 @@ void main(List<String> args) async {
3937
final bool result = (await runner.run(args)) as bool;
4038
if (result == false) {
4139
print('Sub-command returned false: `${args.join(' ')}`');
42-
_cleanup();
40+
await cleanup();
4341
io.exit(1);
4442
}
4543
} on UsageException catch (e) {
@@ -48,38 +46,13 @@ void main(List<String> args) async {
4846
} catch (e) {
4947
rethrow;
5048
} finally {
51-
_cleanup();
49+
await cleanup(browser: testCommand.browser);
5250
}
5351

5452
// Sometimes the Dart VM refuses to quit.
5553
io.exit(io.exitCode);
5654
}
5755

58-
void _cleanup() {
59-
// Cleanup remaining processes if any.
60-
if (processesToCleanUp.length > 0) {
61-
for (io.Process process in processesToCleanUp) {
62-
process.kill();
63-
}
64-
}
65-
// Delete temporary directories.
66-
if (temporaryDirectories.length > 0) {
67-
for (io.Directory directory in temporaryDirectories) {
68-
directory.deleteSync(recursive: true);
69-
}
70-
}
71-
72-
// Many tabs left open after Safari runs, quit safari.
73-
if(testCommand.browser == 'safari') {
74-
print('INFO: Safari tests run. Quit Safari.');
75-
startProcess(
76-
'osascript',
77-
['dev/quit_safari.scpt'],
78-
workingDirectory: environment.webUiRootDir.path,
79-
);
80-
}
81-
}
82-
8356
void _listenToShutdownSignals() {
8457
io.ProcessSignal.sigint.watch().listen((_) {
8558
print('Received SIGINT. Shutting down.');

lib/web_ui/dev/test_runner.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class TestCommand extends Command<bool> with ArgUtils {
179179
bool get runAllTests => targets.isEmpty;
180180

181181
/// The name of the browser to run tests in.
182-
String get browser => stringArg('browser');
182+
String get browser => (argResults != null) ? stringArg('browser') : 'chrome';
183183

184184
/// Whether [browser] is set to "chrome".
185185
bool get isChrome => browser == 'chrome';
@@ -190,7 +190,7 @@ class TestCommand extends Command<bool> with ArgUtils {
190190

191191
Future<void> _runTargetTests(List<FilePath> targets) async {
192192
await _runTestBatch(targets, concurrency: 1, expectFailure: false);
193-
_checkExitCode();
193+
await _checkExitCode();
194194
}
195195

196196
Future<void> _runAllTests() async {
@@ -236,12 +236,12 @@ class TestCommand extends Command<bool> with ArgUtils {
236236
concurrency: 1,
237237
expectFailure: true,
238238
);
239-
_checkExitCode();
239+
await _checkExitCode();
240240
}
241241

242242
// Run all unit-tests as a single batch.
243243
await _runTestBatch(unitTestFiles, concurrency: 10, expectFailure: false);
244-
_checkExitCode();
244+
await _checkExitCode();
245245

246246
// Run screenshot tests one at a time.
247247
for (FilePath testFilePath in screenshotTestFiles) {
@@ -250,7 +250,7 @@ class TestCommand extends Command<bool> with ArgUtils {
250250
concurrency: 1,
251251
expectFailure: false,
252252
);
253-
_checkExitCode();
253+
await _checkExitCode();
254254
}
255255
} else {
256256
final List<FilePath> unitTestFiles = <FilePath>[];
@@ -269,13 +269,14 @@ class TestCommand extends Command<bool> with ArgUtils {
269269
}
270270
// Run all unit-tests as a single batch.
271271
await _runTestBatch(unitTestFiles, concurrency: 10, expectFailure: false);
272-
_checkExitCode();
272+
await _checkExitCode();
273273
}
274274
}
275275

276-
void _checkExitCode() {
276+
void _checkExitCode() async {
277277
if (io.exitCode != 0) {
278278
io.stderr.writeln('Process exited with exit code ${io.exitCode}.');
279+
await cleanup(browser: browser);
279280
io.exit(1);
280281
}
281282
}

lib/web_ui/dev/utils.dart

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ class ProcessException implements Exception {
130130
message
131131
..writeln(description)
132132
..writeln('Command: $executable ${arguments.join(' ')}')
133-
..writeln('Working directory: ${workingDirectory ?? io.Directory.current.path}')
133+
..writeln(
134+
'Working directory: ${workingDirectory ?? io.Directory.current.path}')
134135
..writeln('Exit code: $exitCode');
135136
return '$message';
136137
}
@@ -161,3 +162,29 @@ mixin ArgUtils<T> on Command<T> {
161162
return value;
162163
}
163164
}
165+
166+
/// Cleanup the remaning processes, close open browsers, delete temp files.
167+
void cleanup({String browser = 'chrome'}) async {
168+
// Cleanup remaining processes if any.
169+
if (processesToCleanUp.length > 0) {
170+
for (io.Process process in processesToCleanUp) {
171+
process.kill();
172+
}
173+
}
174+
// Delete temporary directories.
175+
if (temporaryDirectories.length > 0) {
176+
for (io.Directory directory in temporaryDirectories) {
177+
directory.deleteSync(recursive: true);
178+
}
179+
}
180+
181+
// Many tabs left open after Safari runs, quit safari.
182+
if (browser == 'safari') {
183+
print('INFO: Safari tests run. Quit Safari.');
184+
await runProcess(
185+
'osascript',
186+
['dev/quit_safari.scpt'],
187+
workingDirectory: environment.webUiRootDir.path,
188+
);
189+
}
190+
}

0 commit comments

Comments
 (0)