Unverified Commit 55bcb784 authored by Jason Simmons's avatar Jason Simmons Committed by GitHub

Do not parse stack traces in _findResponsibleMethod on Web platforms that use...

Do not parse stack traces in _findResponsibleMethod on Web platforms that use a different format (#115500)

See https://github.com/flutter/flutter/issues/107099
parent 05c6df6d
...@@ -267,6 +267,11 @@ class TestAsyncUtils { ...@@ -267,6 +267,11 @@ class TestAsyncUtils {
'\nWhen the first $originalName was called, this was the stack', '\nWhen the first $originalName was called, this was the stack',
scope.creationStack, scope.creationStack,
)); ));
} else {
information.add(DiagnosticsStackTrace(
'\nWhen the first function was called, this was the stack',
scope.creationStack,
));
} }
throw FlutterError.fromParts(information); throw FlutterError.fromParts(information);
} }
...@@ -302,6 +307,10 @@ class TestAsyncUtils { ...@@ -302,6 +307,10 @@ class TestAsyncUtils {
static _StackEntry? _findResponsibleMethod(StackTrace rawStack, String method, List<DiagnosticsNode> information) { static _StackEntry? _findResponsibleMethod(StackTrace rawStack, String method, List<DiagnosticsNode> information) {
assert(method == 'guard' || method == 'guardSync'); assert(method == 'guard' || method == 'guardSync');
// Web/JavaScript stack traces use a different format.
if (kIsWeb) {
return null;
}
final List<String> stack = rawStack.toString().split('\n').where(_stripAsynchronousSuspensions).toList(); final List<String> stack = rawStack.toString().split('\n').where(_stripAsynchronousSuspensions).toList();
assert(stack.last == ''); assert(stack.last == '');
stack.removeLast(); stack.removeLast();
......
...@@ -60,7 +60,7 @@ void main() { ...@@ -60,7 +60,7 @@ void main() {
} }
expect(await f1, isNull); expect(await f1, isNull);
expect(f2, isNull); expect(f2, isNull);
}); }, skip: kIsWeb); // [intended] depends on platform-specific stack traces.
test('TestAsyncUtils - two classes, all callers in superclass', () async { test('TestAsyncUtils - two classes, all callers in superclass', () async {
final TestAPI testAPI = TestAPISubclass(); final TestAPI testAPI = TestAPISubclass();
...@@ -82,7 +82,7 @@ void main() { ...@@ -82,7 +82,7 @@ void main() {
} }
expect(await f1, isNull); expect(await f1, isNull);
expect(f2, isNull); expect(f2, isNull);
}); }, skip: kIsWeb); // [intended] depends on platform-specific stack traces.
test('TestAsyncUtils - two classes, mixed callers', () async { test('TestAsyncUtils - two classes, mixed callers', () async {
final TestAPISubclass testAPI = TestAPISubclass(); final TestAPISubclass testAPI = TestAPISubclass();
...@@ -104,7 +104,7 @@ void main() { ...@@ -104,7 +104,7 @@ void main() {
} }
expect(await f1, isNull); expect(await f1, isNull);
expect(f2, isNull); expect(f2, isNull);
}); }, skip: kIsWeb); // [intended] depends on platform-specific stack traces.
test('TestAsyncUtils - expect() catches pending async work', () async { test('TestAsyncUtils - expect() catches pending async work', () async {
final TestAPI testAPI = TestAPISubclass(); final TestAPI testAPI = TestAPISubclass();
...@@ -126,7 +126,7 @@ void main() { ...@@ -126,7 +126,7 @@ void main() {
real_test.expect(lines.length, greaterThan(7)); real_test.expect(lines.length, greaterThan(7));
} }
expect(await f1, isNull); expect(await f1, isNull);
}); }, skip: kIsWeb); // [intended] depends on platform-specific stack traces.
testWidgets('TestAsyncUtils - expect() catches pending async work', (WidgetTester tester) async { testWidgets('TestAsyncUtils - expect() catches pending async work', (WidgetTester tester) async {
Future<Object?>? f1, f2; Future<Object?>? f1, f2;
...@@ -168,7 +168,7 @@ void main() { ...@@ -168,7 +168,7 @@ void main() {
} }
await f1; await f1;
await f2; await f2;
}); }, skip: kIsWeb); // [intended] depends on platform-specific stack traces.
testWidgets('TestAsyncUtils - expect() catches pending async work', (WidgetTester tester) async { testWidgets('TestAsyncUtils - expect() catches pending async work', (WidgetTester tester) async {
Future<Object?>? f1; Future<Object?>? f1;
...@@ -193,7 +193,7 @@ void main() { ...@@ -193,7 +193,7 @@ void main() {
real_test.expect(information[3].level, DiagnosticLevel.info); real_test.expect(information[3].level, DiagnosticLevel.info);
} }
await f1; await f1;
}); }, skip: kIsWeb); // [intended] depends on platform-specific stack traces.
testWidgets('TestAsyncUtils - expect() catches pending async work', (WidgetTester tester) async { testWidgets('TestAsyncUtils - expect() catches pending async work', (WidgetTester tester) async {
Future<Object?>? f1; Future<Object?>? f1;
...@@ -218,7 +218,7 @@ void main() { ...@@ -218,7 +218,7 @@ void main() {
real_test.expect(information[3].level, DiagnosticLevel.info); real_test.expect(information[3].level, DiagnosticLevel.info);
} }
await f1; await f1;
}); }, skip: kIsWeb); // [intended] depends on platform-specific stack traces.
testWidgets('TestAsyncUtils - guard body can throw', (WidgetTester tester) async { testWidgets('TestAsyncUtils - guard body can throw', (WidgetTester tester) async {
try { try {
...@@ -229,5 +229,24 @@ void main() { ...@@ -229,5 +229,24 @@ void main() {
} }
}); });
test('TestAsyncUtils - web', () async {
final TestAPI testAPI = TestAPI();
Future<Object?>? f1, f2;
f1 = testAPI.testGuard1();
try {
f2 = testAPI.testGuard2();
fail('unexpectedly did not throw');
} on FlutterError catch (e) {
final List<String> 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' // see also dev/manual_tests/test_data which contains tests run by the flutter_tools tests for 'flutter test'
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment