New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
setUrlStrategy
fails in integration test environment
#116936
Comments
I'm looking into this. For background, we don't allow flutter web apps to set the url strategy more than once to prevent them from shooting themselves in the foot. Changing the url strategy is not something a normal app does. The expectation is that the app sets up the url strategy once on start up (or does nothing, in which case we default to the Do integration tests run one after the other in the same instance? If that's the case then that explains the error you are seeing. Solution: What we can do is expose a |
Discussed this with the team, here's a brief summary: The url strategy issue you're seeing is just a symptom of the fact that integration tests are NOT running in isolation. This leads to all kinds of weird behavior since the underlying state is preserved across tests. Ideally, you want each integration test to run in isolation (that's how real apps run, you don't run multiple apps consecutively in the same page). |
How do these tests run? Is there anything that can be reused from the engine test runner that can help here? |
@ditman those tests work because on I'm not sure if they have access to this API from outside the engine. Maybe something like this would work?: import 'dart:ui' as ui;
// On test tearDown:
(ui.window as dynamic).resetHistory(); |
Ahhh, cool trick! I think that should be doable, I hope that helps unblock this a little bit :S |
The issue might be that |
@kenzieschmoll have you found a fix/workaround for this? |
Adding this was an acceptable workaround 👍 Thanks!
|
Actually, it appears this workaround is flaky... it sometimes passes sometimes fails. |
Ah sorry, this is my bad. I forgot that Try this: tearDown(() async {
await (ui.window as dynamic).resetHistory();
}); |
Ah adding the await seems to have fixed it. This is an acceptable workaround for now, thanks! |
The proposed workaround was working for a while, but now I seem to be hitting an assertion error when calling resetHistory();
|
Taking a step back here. Do you really want your tests to mess with the real browser history and url? I'm assuming the answer is no. But if you don't do anything about it, and your tests perform any kind of flutter navigation, you'll be touching the real browser history. You have 2 options here:
|
FWIW, you can wrap this line a a simple Main app code: import 'package:flutter/material.dart';
import 'package:url_strategy/url_strategy.dart';
bool isTesting = false;
/// The main entry point of the application.
void main() {
// Set the path URL strategy for Flutter web applications. This removes the
// "#" symbol from the URL and makes it more user-friendly and easier to share.
if (!isTesting) {
setPathUrlStrategy();
}
runApp(const MyApp());
} Test app code: import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:<your-app>/main.dart' as app;
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
app.isTesting = true;
testWidgets('test loading the app', (tester) async {
// Build our app and trigger a frame.
await app.main();
await tester.pumpAndSettle();
});
} |
This is called in the app's main method. In the integration test, this exception is thrown upon calling
app.main()
:The text was updated successfully, but these errors were encountered: