From fdd6c75c3ebba345a1c9dab2ca54e8d5b6cc9ad5 Mon Sep 17 00:00:00 2001 From: Oleksandr Leushchenko Date: Sun, 24 Aug 2025 16:35:11 +0300 Subject: [PATCH 1/2] Refactor error handling in hooks to use catch instead of on TestFailure --- lib/src/scenario_generator.dart | 2 +- test/feature_generator_test.dart | 2 +- test/feature_with_hooks_test.dart | 2 +- test/full_set_test.dart | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/src/scenario_generator.dart b/lib/src/scenario_generator.dart index e8ee957..75f5fd2 100644 --- a/lib/src/scenario_generator.dart +++ b/lib/src/scenario_generator.dart @@ -38,7 +38,7 @@ void parseScenario( } if (hasHooks) { - sb.writeln(' } on TestFailure {'); + sb.writeln(' } catch (_) {'); sb.writeln(' $testSuccessVariableName = false;'); sb.writeln(' rethrow;'); } diff --git a/test/feature_generator_test.dart b/test/feature_generator_test.dart index 30f2468..d320ea8 100644 --- a/test/feature_generator_test.dart +++ b/test/feature_generator_test.dart @@ -136,7 +136,7 @@ hookFolderName: hooksFolder ' try {\n' " await beforeEach('''Testing scenario''');\n" ' await theAppIsRunning(tester);\n' - ' } on TestFailure {\n' + ' } catch (_) {\n' ' success = false;\n' ' rethrow;\n' ' } finally {\n' diff --git a/test/feature_with_hooks_test.dart b/test/feature_with_hooks_test.dart index 1406958..f1fbe6b 100644 --- a/test/feature_with_hooks_test.dart +++ b/test/feature_with_hooks_test.dart @@ -36,7 +36,7 @@ void main() { try { await beforeEach(\'\'\'Testing scenario\'\'\' ); await theAppIsRunning(tester); - } on TestFailure { + } catch (_) { success = false; rethrow; } finally { diff --git a/test/full_set_test.dart b/test/full_set_test.dart index d60884d..a04166c 100644 --- a/test/full_set_test.dart +++ b/test/full_set_test.dart @@ -67,7 +67,7 @@ void main() { await theAppIsRunning(tester); await iRunCode(tester, 'func foo() {}; func bar() { print("hey!"); };'); await iSeeText(tester, '0'); - } on TestFailure { + } catch (_) { success = false; rethrow; } finally { @@ -96,7 +96,7 @@ void main() { await beforeEach(\'\'\'Initial counter value is 0\'\'\' ); await bddSetUp(tester); await theAppIsRunning(tester); - } on TestFailure { + } catch (_) { success = false; rethrow; } finally { From ea42d7aedcbdda77e3077ae0533f26126529a04c Mon Sep 17 00:00:00 2001 From: Oleksandr Leushchenko Date: Sun, 24 Aug 2025 16:38:14 +0300 Subject: [PATCH 2/2] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4dba83c..50625fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ * **BREAKING CHANGE**: The package doesn't provide pre-built steps anymore. Steps will appear in the `step` folder. * Drop unused dependencies * Upgrade `build` dependency +* Fix exceptions processing in hooks ## [1.8.2] - Ignore linter warnings