From a113970c1d1d5b677e411c94b724320cee3ddfc2 Mon Sep 17 00:00:00 2001 From: gmpassos Date: Sun, 10 Mar 2024 04:30:59 -0300 Subject: [PATCH] v2.5.3 - `testUI`: - Fix `tearDownAll`, declared before `setUpAll` (before call to `spawnHybridUri`). - `SpawnHybrid`: added field `finalizer`. --- CHANGELOG.md | 7 +++++ lib/src/bones_ui.dart | 2 +- lib/src/bones_ui_test_tools.dart | 52 +++++++++++++++++++++----------- pubspec.yaml | 2 +- 4 files changed, 44 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37dfd62..3d9465f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## 2.5.3 + +- `testUI`: + - Fix `tearDownAll`, declared before `setUpAll` (before call to `spawnHybridUri`). + +- `SpawnHybrid`: added field `finalizer`. + ## 2.5.2 - `UIElementExtension`: diff --git a/lib/src/bones_ui.dart b/lib/src/bones_ui.dart index a958b82..3effba8 100644 --- a/lib/src/bones_ui.dart +++ b/lib/src/bones_ui.dart @@ -1,3 +1,3 @@ class BonesUI { - static const String version = '2.5.2'; + static const String version = '2.5.3'; } diff --git a/lib/src/bones_ui_test_tools.dart b/lib/src/bones_ui_test_tools.dart index 34f20d7..fe33f25 100644 --- a/lib/src/bones_ui_test_tools.dart +++ b/lib/src/bones_ui_test_tools.dart @@ -377,7 +377,11 @@ class SpawnHybrid { /// Optional callback for the [StreamChannel] returned by [spawnHybridUri] spawn. dynamic Function(StreamChannel? channel)? callback; - SpawnHybrid(this.uri, {this.message, this.callback}); + /// Optional finalizer for the [StreamChannel] returned by [spawnHybridUri] spawn. + /// Called in teardown. + dynamic Function(StreamChannel? channel)? finalizer; + + SpawnHybrid(this.uri, {this.message, this.callback, this.finalizer}); @override String toString() { @@ -420,17 +424,20 @@ Future testMultipleUI(Map Function()> testsMain, print('testMultipleUI> shuflle(shuffleSeed: $shuffleSeed)'); } - print('testMultipleUI> tests:'); + print('testMultipleUI:'); for (var e in testsMain.entries) { var testPath = e.key; print(' -- $testPath'); } + print(''); + for (var e in entries) { var testPath = e.key; var main = e.value; _testMultipleUIPath = testPath; await main(); + await Future.delayed(Duration(milliseconds: 100)); } } @@ -490,8 +497,34 @@ void _testUIImpl( group(testUIName, () { U? uiRoot; + StreamChannel? channel; + + // Teardown needs to be added before call to `spawnHybridUri`, + // since `spawnHybridUri` will terminate the process with its + // own `addTearDown` beforehand: + tearDownAll(() async { + context.setTestWindowTitle('tearDown'); + + if (uiRoot != null) { + uiRoot!.close(); + await testUISleep(ms: 100); + } + + final finalizer = spawnHybrid?.finalizer; + if (finalizer != null) { + await finalizer(channel); + } + + if (teardown != null) { + teardown(context); + } + }); + setUpAll(() async { if (testMultipleUIPath != null) { + print(''); + print( + '--------------------------------------------------------------------------------'); print('[Bones_UI] testMultipleUI> path: $testMultipleUIPath'); } @@ -503,8 +536,6 @@ void _testUIImpl( await preSetup(); } - StreamChannel? channel; - if (spawnHybrid != null) { context.setTestWindowTitle('spawnHybridUri: ${spawnHybrid.uri} ...'); @@ -528,19 +559,6 @@ void _testUIImpl( } }); - tearDownAll(() async { - context.setTestWindowTitle('tearDown'); - - if (uiRoot != null) { - uiRoot!.close(); - await testUISleep(ms: 100); - } - - if (teardown != null) { - teardown(context); - } - }); - setUp(() { if (context.hasErrors) { fail("ABORTING TEST: `testUI` with a previous error!"); diff --git a/pubspec.yaml b/pubspec.yaml index d77aad9..9c59dc5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: bones_ui description: Bones_UI - An intuitive and user-friendly Web User Interface framework for Dart. -version: 2.5.2 +version: 2.5.3 homepage: https://github.com/Colossus-Services/bones_ui environment: