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

Commit 809d68b

Browse files
author
nturgut
committed
making changes to utils and adding cleanup after unit tests failed
1 parent f30da96 commit 809d68b

File tree

3 files changed

+38
-36
lines changed

3 files changed

+38
-36
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);
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: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ class TestCommand extends Command<bool> {
178178
/// Whether all tests should run.
179179
bool get runAllTests => targets.isEmpty;
180180

181-
String get browser => argResults['browser'];
181+
/// Can be null if `felt clean` is called which also checks the browser,
182+
/// uring cleanup phase.
183+
String get browser => (argResults != null) ? argResults['browser'] : '';
182184

183185
bool get isChrome => argResults['browser'] == 'chrome';
184186

@@ -188,7 +190,7 @@ class TestCommand extends Command<bool> {
188190

189191
Future<void> _runTargetTests(List<FilePath> targets) async {
190192
await _runTestBatch(targets, concurrency: 1, expectFailure: false);
191-
_checkExitCode();
193+
await _checkExitCode();
192194
}
193195

194196
Future<void> _runAllTests() async {
@@ -234,12 +236,12 @@ class TestCommand extends Command<bool> {
234236
concurrency: 1,
235237
expectFailure: true,
236238
);
237-
_checkExitCode();
239+
await _checkExitCode();
238240
}
239241

240242
// Run all unit-tests as a single batch.
241243
await _runTestBatch(unitTestFiles, concurrency: 10, expectFailure: false);
242-
_checkExitCode();
244+
await _checkExitCode();
243245

244246
// Run screenshot tests one at a time.
245247
for (FilePath testFilePath in screenshotTestFiles) {
@@ -248,7 +250,7 @@ class TestCommand extends Command<bool> {
248250
concurrency: 1,
249251
expectFailure: false,
250252
);
251-
_checkExitCode();
253+
await _checkExitCode();
252254
}
253255
} else {
254256
final List<FilePath> unitTestFiles = <FilePath>[];
@@ -267,13 +269,14 @@ class TestCommand extends Command<bool> {
267269
}
268270
// Run all unit-tests as a single batch.
269271
await _runTestBatch(unitTestFiles, concurrency: 10, expectFailure: false);
270-
_checkExitCode();
272+
await _checkExitCode();
271273
}
272274
}
273275

274-
void _checkExitCode() {
276+
void _checkExitCode() async {
275277
if (io.exitCode != 0) {
276278
io.stderr.writeln('Process exited with exit code ${io.exitCode}.');
279+
await cleanup(browser: browser);
277280
io.exit(1);
278281
}
279282
}

lib/web_ui/dev/utils.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,29 @@ class ProcessException implements Exception {
134134
return '$message';
135135
}
136136
}
137+
138+
/// Cleanup the remaning processes, close open browsers, delete temp files.
139+
void cleanup({String browser = 'chrome'}) async {
140+
// Cleanup remaining processes if any.
141+
if (processesToCleanUp.length > 0) {
142+
for (io.Process process in processesToCleanUp) {
143+
process.kill();
144+
}
145+
}
146+
// Delete temporary directories.
147+
if (temporaryDirectories.length > 0) {
148+
for (io.Directory directory in temporaryDirectories) {
149+
directory.deleteSync(recursive: true);
150+
}
151+
}
152+
153+
// Many tabs left open after Safari runs, quit safari.
154+
if(browser == 'safari') {
155+
print('INFO: Safari tests run. Quit Safari.');
156+
await runProcess(
157+
'osascript',
158+
['dev/quit_safari.scpt'],
159+
workingDirectory: environment.webUiRootDir.path,
160+
);
161+
}
162+
}

0 commit comments

Comments
 (0)