Skip to content

Commit ec35471

Browse files
Add precacheTestImage to flutter_test and unskip web image tests (flutter#191435)
Adds `precacheTestImage` to `package:flutter_test` to safely resolve and cache `ImageProvider`s outside the `FakeAsync` zone during widget testing. Without this, Image tests can hang forever on Flutter web. Fixes flutter#87933 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --------- Co-authored-by: Mouad Debbar <[email protected]>
1 parent 56cbb21 commit ec35471

6 files changed

Lines changed: 1299 additions & 1262 deletions

File tree

‎packages/flutter/test/painting/_network_image_test_web.dart‎

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -123,30 +123,14 @@ void runTests() {
123123
};
124124

125125
final networkImage = NetworkImage(_uniqueUrl(tester.testDescription));
126-
ImageInfo? imageInfo;
127126
Object? recordedError;
128-
Completer<void>? imageCompleter;
129-
await tester.runAsync(() async {
130-
imageCompleter = Completer<void>();
131-
final ImageStream stream = networkImage.resolve(ImageConfiguration.empty);
132-
stream.addListener(
133-
ImageStreamListener(
134-
(ImageInfo info, bool isSync) {
135-
imageInfo = info;
136-
imageCompleter!.complete();
137-
},
138-
onError: (Object error, StackTrace? stackTrace) {
139-
recordedError = error;
140-
imageCompleter!.complete();
141-
},
142-
),
143-
);
144-
});
145-
await tester.runAsync(() async {
146-
await imageCompleter!.future;
147-
});
127+
await precacheTestImage(
128+
networkImage,
129+
onError: (Object error, StackTrace? stackTrace) {
130+
recordedError = error;
131+
},
132+
);
148133
expect(recordedError, isNotNull);
149-
expect(imageInfo, isNull);
150134
});
151135

152136
testWidgets('When strategy is .fallback, emits a WebImageInfo if the image is cross-origin', (

0 commit comments

Comments
 (0)