From 55bcb784a784846c36a2835d3979736fc2b4862f Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Mon, 5 Dec 2022 13:33:46 -0800 Subject: [PATCH] Do not parse stack traces in _findResponsibleMethod on Web platforms that use a different format (#115500) See https://github.com/flutter/flutter/issues/107099 --- .../lib/src/test_async_utils.dart | 9 +++++ .../test/test_async_utils_test.dart | 33 +++++++++++++++---- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/packages/flutter_test/lib/src/test_async_utils.dart b/packages/flutter_test/lib/src/test_async_utils.dart index 4479132df4..653df82f43 100644 --- a/packages/flutter_test/lib/src/test_async_utils.dart +++ b/packages/flutter_test/lib/src/test_async_utils.dart @@ -267,6 +267,11 @@ class TestAsyncUtils { '\nWhen the first $originalName was called, this was the stack', scope.creationStack, )); + } else { + information.add(DiagnosticsStackTrace( + '\nWhen the first function was called, this was the stack', + scope.creationStack, + )); } throw FlutterError.fromParts(information); } @@ -302,6 +307,10 @@ class TestAsyncUtils { static _StackEntry? _findResponsibleMethod(StackTrace rawStack, String method, List information) { assert(method == 'guard' || method == 'guardSync'); + // Web/JavaScript stack traces use a different format. + if (kIsWeb) { + return null; + } final List stack = rawStack.toString().split('\n').where(_stripAsynchronousSuspensions).toList(); assert(stack.last == ''); stack.removeLast(); diff --git a/packages/flutter_test/test/test_async_utils_test.dart b/packages/flutter_test/test/test_async_utils_test.dart index 67d667229f..15858235f0 100644 --- a/packages/flutter_test/test/test_async_utils_test.dart +++ b/packages/flutter_test/test/test_async_utils_test.dart @@ -60,7 +60,7 @@ void main() { } expect(await f1, isNull); expect(f2, isNull); - }); + }, skip: kIsWeb); // [intended] depends on platform-specific stack traces. test('TestAsyncUtils - two classes, all callers in superclass', () async { final TestAPI testAPI = TestAPISubclass(); @@ -82,7 +82,7 @@ void main() { } expect(await f1, isNull); expect(f2, isNull); - }); + }, skip: kIsWeb); // [intended] depends on platform-specific stack traces. test('TestAsyncUtils - two classes, mixed callers', () async { final TestAPISubclass testAPI = TestAPISubclass(); @@ -104,7 +104,7 @@ void main() { } expect(await f1, isNull); expect(f2, isNull); - }); + }, skip: kIsWeb); // [intended] depends on platform-specific stack traces. test('TestAsyncUtils - expect() catches pending async work', () async { final TestAPI testAPI = TestAPISubclass(); @@ -126,7 +126,7 @@ void main() { real_test.expect(lines.length, greaterThan(7)); } expect(await f1, isNull); - }); + }, skip: kIsWeb); // [intended] depends on platform-specific stack traces. testWidgets('TestAsyncUtils - expect() catches pending async work', (WidgetTester tester) async { Future? f1, f2; @@ -168,7 +168,7 @@ void main() { } await f1; await f2; - }); + }, skip: kIsWeb); // [intended] depends on platform-specific stack traces. testWidgets('TestAsyncUtils - expect() catches pending async work', (WidgetTester tester) async { Future? f1; @@ -193,7 +193,7 @@ void main() { real_test.expect(information[3].level, DiagnosticLevel.info); } await f1; - }); + }, skip: kIsWeb); // [intended] depends on platform-specific stack traces. testWidgets('TestAsyncUtils - expect() catches pending async work', (WidgetTester tester) async { Future? f1; @@ -218,7 +218,7 @@ void main() { real_test.expect(information[3].level, DiagnosticLevel.info); } await f1; - }); + }, skip: kIsWeb); // [intended] depends on platform-specific stack traces. testWidgets('TestAsyncUtils - guard body can throw', (WidgetTester tester) async { try { @@ -229,5 +229,24 @@ void main() { } }); + test('TestAsyncUtils - web', () async { + final TestAPI testAPI = TestAPI(); + Future? f1, f2; + f1 = testAPI.testGuard1(); + try { + f2 = testAPI.testGuard2(); + fail('unexpectedly did not throw'); + } on FlutterError catch (e) { + final List lines = e.message.split('\n'); + real_test.expect(lines[0], 'Guarded function conflict.'); + real_test.expect(lines[1], 'You must use "await" with all Future-returning test APIs.'); + real_test.expect(lines[2], ''); + real_test.expect(lines[3], 'When the first function was called, this was the stack:'); + real_test.expect(lines.length, greaterThan(3)); + } + expect(await f1, isNull); + expect(f2, isNull); + }, skip: !kIsWeb); // [intended] depends on platform-specific stack traces. + // see also dev/manual_tests/test_data which contains tests run by the flutter_tools tests for 'flutter test' }