Skip to content

Commit 55bcb78

Browse files
Do not parse stack traces in _findResponsibleMethod on Web platforms that use a different format (#115500)
See flutter/flutter#107099
1 parent 05c6df6 commit 55bcb78

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

packages/flutter_test/lib/src/test_async_utils.dart

+9
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,11 @@ class TestAsyncUtils {
267267
'\nWhen the first $originalName was called, this was the stack',
268268
scope.creationStack,
269269
));
270+
} else {
271+
information.add(DiagnosticsStackTrace(
272+
'\nWhen the first function was called, this was the stack',
273+
scope.creationStack,
274+
));
270275
}
271276
throw FlutterError.fromParts(information);
272277
}
@@ -302,6 +307,10 @@ class TestAsyncUtils {
302307

303308
static _StackEntry? _findResponsibleMethod(StackTrace rawStack, String method, List<DiagnosticsNode> information) {
304309
assert(method == 'guard' || method == 'guardSync');
310+
// Web/JavaScript stack traces use a different format.
311+
if (kIsWeb) {
312+
return null;
313+
}
305314
final List<String> stack = rawStack.toString().split('\n').where(_stripAsynchronousSuspensions).toList();
306315
assert(stack.last == '');
307316
stack.removeLast();

packages/flutter_test/test/test_async_utils_test.dart

+26-7
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void main() {
6060
}
6161
expect(await f1, isNull);
6262
expect(f2, isNull);
63-
});
63+
}, skip: kIsWeb); // [intended] depends on platform-specific stack traces.
6464

6565
test('TestAsyncUtils - two classes, all callers in superclass', () async {
6666
final TestAPI testAPI = TestAPISubclass();
@@ -82,7 +82,7 @@ void main() {
8282
}
8383
expect(await f1, isNull);
8484
expect(f2, isNull);
85-
});
85+
}, skip: kIsWeb); // [intended] depends on platform-specific stack traces.
8686

8787
test('TestAsyncUtils - two classes, mixed callers', () async {
8888
final TestAPISubclass testAPI = TestAPISubclass();
@@ -104,7 +104,7 @@ void main() {
104104
}
105105
expect(await f1, isNull);
106106
expect(f2, isNull);
107-
});
107+
}, skip: kIsWeb); // [intended] depends on platform-specific stack traces.
108108

109109
test('TestAsyncUtils - expect() catches pending async work', () async {
110110
final TestAPI testAPI = TestAPISubclass();
@@ -126,7 +126,7 @@ void main() {
126126
real_test.expect(lines.length, greaterThan(7));
127127
}
128128
expect(await f1, isNull);
129-
});
129+
}, skip: kIsWeb); // [intended] depends on platform-specific stack traces.
130130

131131
testWidgets('TestAsyncUtils - expect() catches pending async work', (WidgetTester tester) async {
132132
Future<Object?>? f1, f2;
@@ -168,7 +168,7 @@ void main() {
168168
}
169169
await f1;
170170
await f2;
171-
});
171+
}, skip: kIsWeb); // [intended] depends on platform-specific stack traces.
172172

173173
testWidgets('TestAsyncUtils - expect() catches pending async work', (WidgetTester tester) async {
174174
Future<Object?>? f1;
@@ -193,7 +193,7 @@ void main() {
193193
real_test.expect(information[3].level, DiagnosticLevel.info);
194194
}
195195
await f1;
196-
});
196+
}, skip: kIsWeb); // [intended] depends on platform-specific stack traces.
197197

198198
testWidgets('TestAsyncUtils - expect() catches pending async work', (WidgetTester tester) async {
199199
Future<Object?>? f1;
@@ -218,7 +218,7 @@ void main() {
218218
real_test.expect(information[3].level, DiagnosticLevel.info);
219219
}
220220
await f1;
221-
});
221+
}, skip: kIsWeb); // [intended] depends on platform-specific stack traces.
222222

223223
testWidgets('TestAsyncUtils - guard body can throw', (WidgetTester tester) async {
224224
try {
@@ -229,5 +229,24 @@ void main() {
229229
}
230230
});
231231

232+
test('TestAsyncUtils - web', () async {
233+
final TestAPI testAPI = TestAPI();
234+
Future<Object?>? f1, f2;
235+
f1 = testAPI.testGuard1();
236+
try {
237+
f2 = testAPI.testGuard2();
238+
fail('unexpectedly did not throw');
239+
} on FlutterError catch (e) {
240+
final List<String> lines = e.message.split('\n');
241+
real_test.expect(lines[0], 'Guarded function conflict.');
242+
real_test.expect(lines[1], 'You must use "await" with all Future-returning test APIs.');
243+
real_test.expect(lines[2], '');
244+
real_test.expect(lines[3], 'When the first function was called, this was the stack:');
245+
real_test.expect(lines.length, greaterThan(3));
246+
}
247+
expect(await f1, isNull);
248+
expect(f2, isNull);
249+
}, skip: !kIsWeb); // [intended] depends on platform-specific stack traces.
250+
232251
// see also dev/manual_tests/test_data which contains tests run by the flutter_tools tests for 'flutter test'
233252
}

0 commit comments

Comments
 (0)