From e6ef82928c7f3b488b7b445c7fb4badbf02fdf5a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 18 Jun 2024 17:28:28 -0300 Subject: [PATCH 1/3] chore(deps): Bump peter-evans/create-pull-request from 6.0.5 to 6.1.0 (#1230) --- .github/workflows/generate_flutter_news_template.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/generate_flutter_news_template.yaml b/.github/workflows/generate_flutter_news_template.yaml index b84117b5c..41858e3ef 100644 --- a/.github/workflows/generate_flutter_news_template.yaml +++ b/.github/workflows/generate_flutter_news_template.yaml @@ -49,7 +49,7 @@ jobs: run: git stash pop - name: Create Pull Request With Required Changes - uses: peter-evans/create-pull-request@v6.0.5 + uses: peter-evans/create-pull-request@v6.1.0 with: branch: chore/generate-flutter-news-template commit-message: "chore: generate flutter_news_template" From 4e59207180b7eef596fb81f3363e4dd910d6b3ce Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 25 Jun 2024 10:52:43 -0300 Subject: [PATCH 2/3] chore(deps-dev): Bump typescript from 5.4.5 to 5.5.2 in /docs (#1233) --- docs/package-lock.json | 14 +++++++------- docs/package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/package-lock.json b/docs/package-lock.json index 9ffe9e031..68e387e81 100644 --- a/docs/package-lock.json +++ b/docs/package-lock.json @@ -23,7 +23,7 @@ "@tsconfig/docusaurus": "^2.0.3", "eslint": "^8.57.0", "prettier": "^3.3.2", - "typescript": "^5.4.5" + "typescript": "^5.5.2" }, "engines": { "node": ">=18.19.1" @@ -13832,9 +13832,9 @@ } }, "node_modules/typescript": { - "version": "5.4.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz", - "integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==", + "version": "5.5.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.2.tgz", + "integrity": "sha512-NcRtPEOsPFFWjobJEtfihkLCZCXZt/os3zf8nTxjVH3RvTSxjrCamJpbExGvYOF+tFHc3pA65qpdwPbzjohhew==", "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -24643,9 +24643,9 @@ } }, "typescript": { - "version": "5.4.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz", - "integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==" + "version": "5.5.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.2.tgz", + "integrity": "sha512-NcRtPEOsPFFWjobJEtfihkLCZCXZt/os3zf8nTxjVH3RvTSxjrCamJpbExGvYOF+tFHc3pA65qpdwPbzjohhew==" }, "unicode-canonical-property-names-ecmascript": { "version": "2.0.0", diff --git a/docs/package.json b/docs/package.json index 5ec5eb18c..ac4c74df9 100644 --- a/docs/package.json +++ b/docs/package.json @@ -33,7 +33,7 @@ "@tsconfig/docusaurus": "^2.0.3", "eslint": "^8.57.0", "prettier": "^3.3.2", - "typescript": "^5.4.5" + "typescript": "^5.5.2" }, "browserslist": { "production": [ From a89a5111142d37368a486f6b2945b0fecd593971 Mon Sep 17 00:00:00 2001 From: Matias Leyba Date: Thu, 27 Jun 2024 20:11:01 -0300 Subject: [PATCH 3/3] fix(ci): golden test comparator implementation (#1232) --- .github/workflows/news_blocks_ui.yaml | 3 - .../test/helpers/tolerant_comparator.dart | 70 +++++++------------ .../test/src/article_introduction_test.dart | 4 +- .../test/src/divider_horizontal_test.dart | 4 +- .../test/src/post_large/post_large_test.dart | 4 +- .../src/post_medium/post_medium_test.dart | 4 +- .../test/src/post_small_test.dart | 2 +- .../test/src/section_header_test.dart | 4 +- .../news_blocks_ui/test/src/spacer_test.dart | 4 +- .../test/src/text_caption_test.dart | 4 +- .../test/src/text_headline_test.dart | 4 +- .../test/src/text_lead_paragraph_test.dart | 4 +- .../test/src/text_paragraph_test.dart | 5 +- .../test/src/trending_story_test.dart | 2 +- .../test/src/video_introduction_test.dart | 4 +- .../src/widgets/banner_ad_content_test.dart | 36 +++++----- .../test/src/widgets/post_footer_test.dart | 4 +- 17 files changed, 82 insertions(+), 80 deletions(-) diff --git a/.github/workflows/news_blocks_ui.yaml b/.github/workflows/news_blocks_ui.yaml index 943d52e70..ec76faea0 100644 --- a/.github/workflows/news_blocks_ui.yaml +++ b/.github/workflows/news_blocks_ui.yaml @@ -19,6 +19,3 @@ jobs: flutter_version: 3.19.6 working_directory: flutter_news_example/packages/news_blocks_ui coverage_excludes: "lib/src/generated/*.dart" - # Due to incompability with custom goldenFileComparator, - # reference: flutter_news_example/packages/news_blocks_ui/test/helpers/tolerant_comparator.dart - test_optimization: false diff --git a/flutter_news_example/packages/news_blocks_ui/test/helpers/tolerant_comparator.dart b/flutter_news_example/packages/news_blocks_ui/test/helpers/tolerant_comparator.dart index a5dc0ae68..890310d73 100644 --- a/flutter_news_example/packages/news_blocks_ui/test/helpers/tolerant_comparator.dart +++ b/flutter_news_example/packages/news_blocks_ui/test/helpers/tolerant_comparator.dart @@ -1,30 +1,17 @@ -// ignore_for_file: avoid_print - import 'package:flutter/foundation.dart'; import 'package:flutter_test/flutter_test.dart'; -/// A comparator for golden tests that allows for a small difference in pixels. -/// -/// This comparator performs a pixel-for-pixel comparison of the decoded PNGs, -/// returning true only if the difference is less than [differenceTolerance]%. -/// In case of failure this comparator will provide output to illustrate the -/// difference. -class TolerantComparator extends LocalFileComparator { - TolerantComparator.from( - super.testFile, { - required LocalFileComparator comparator, - }) : _comparator = comparator; - - /// The difference tolerance that this comparator allows for. - /// - /// If compared files produce less than [differenceTolerance]% difference, - /// then the test is accepted. Otherwise, the test fails. - static const differenceTolerance = .06; - - final LocalFileComparator _comparator; +class _TolerantGoldenFileComparator extends LocalFileComparator { + _TolerantGoldenFileComparator( + super.testFile, + ); - @override - Uri getTestUri(Uri key, int? version) => _comparator.getTestUri(key, version); + /// How much the golden image can differ from the test image. + /// + /// It is expected to be between 0 and 1. + /// Where 0 is no difference (same image) + /// and 1 is the maximum difference (completely different images). + static const double _precisionTolerance = .06; @override Future compare(Uint8List imageBytes, Uri golden) async { @@ -32,29 +19,26 @@ class TolerantComparator extends LocalFileComparator { imageBytes, await getGoldenBytes(golden), ); - if (!result.passed) { - final error = await generateFailureOutput(result, golden, basedir); - if (result.diffPercent >= differenceTolerance) { - throw FlutterError(error); - } else { - print( - 'Warning - golden differed less than $differenceTolerance% ' - '(${result.diffPercent}%). Ignoring failure but logging the error.', - ); - print(error); - } + + final passed = result.passed || result.diffPercent <= _precisionTolerance; + if (passed) { + result.dispose(); + return true; } - return true; + + final error = await generateFailureOutput(result, golden, basedir); + result.dispose(); + throw FlutterError(error); } } -/// Sets [TolerantComparator] as the default golden file comparator in tests. -void setUpTolerantComparator() { - final oldComparator = goldenFileComparator as LocalFileComparator; - final newComparator = TolerantComparator.from( - comparator: oldComparator, - Uri.parse('${oldComparator.basedir}test'), - ); - expect(oldComparator.basedir, newComparator.basedir); +/// Sets [_TolerantGoldenFileComparator] as the default golden file comparator +/// in tests. +void setUpTolerantComparator(String testPath) { + final oldComparator = goldenFileComparator; + final newComparator = _TolerantGoldenFileComparator(Uri.parse(testPath)); + goldenFileComparator = newComparator; + + addTearDown(() => goldenFileComparator = oldComparator); } diff --git a/flutter_news_example/packages/news_blocks_ui/test/src/article_introduction_test.dart b/flutter_news_example/packages/news_blocks_ui/test/src/article_introduction_test.dart index e1c2f42ff..0c7c87de0 100644 --- a/flutter_news_example/packages/news_blocks_ui/test/src/article_introduction_test.dart +++ b/flutter_news_example/packages/news_blocks_ui/test/src/article_introduction_test.dart @@ -20,7 +20,9 @@ void main() { const premiumText = 'Subscriber Exclusive'; group('ArticleIntroduction', () { - setUpAll(setUpTolerantComparator); + setUpAll( + () => setUpTolerantComparator('test/src/article_introduction_test.dart'), + ); final technologyArticleIntroduction = ArticleIntroductionBlock( category: category, diff --git a/flutter_news_example/packages/news_blocks_ui/test/src/divider_horizontal_test.dart b/flutter_news_example/packages/news_blocks_ui/test/src/divider_horizontal_test.dart index 6685e3d6c..e27650698 100644 --- a/flutter_news_example/packages/news_blocks_ui/test/src/divider_horizontal_test.dart +++ b/flutter_news_example/packages/news_blocks_ui/test/src/divider_horizontal_test.dart @@ -9,7 +9,9 @@ import '../helpers/helpers.dart'; void main() { group('DividerHorizontal', () { - setUpAll(setUpTolerantComparator); + setUpAll( + () => setUpTolerantComparator('test/src/divider_horizontal_test.dart'), + ); testWidgets('renders correctly', (tester) async { final widget = Center( diff --git a/flutter_news_example/packages/news_blocks_ui/test/src/post_large/post_large_test.dart b/flutter_news_example/packages/news_blocks_ui/test/src/post_large/post_large_test.dart index fb650252b..1d23c9fc6 100644 --- a/flutter_news_example/packages/news_blocks_ui/test/src/post_large/post_large_test.dart +++ b/flutter_news_example/packages/news_blocks_ui/test/src/post_large/post_large_test.dart @@ -22,7 +22,9 @@ void main() { 'and prices are finally falling'; group('PostLarge', () { - setUpAll(setUpTolerantComparator); + setUpAll( + () => setUpTolerantComparator('test/src/post_large/post_large_test.dart'), + ); group('renders correctly overlaid ', () { testWidgets( diff --git a/flutter_news_example/packages/news_blocks_ui/test/src/post_medium/post_medium_test.dart b/flutter_news_example/packages/news_blocks_ui/test/src/post_medium/post_medium_test.dart index 0475f34b0..f045ce0c1 100644 --- a/flutter_news_example/packages/news_blocks_ui/test/src/post_medium/post_medium_test.dart +++ b/flutter_news_example/packages/news_blocks_ui/test/src/post_medium/post_medium_test.dart @@ -16,7 +16,9 @@ void main() { // Change the default factory databaseFactory = databaseFactoryFfi; - setUpTolerantComparator(); + setUpTolerantComparator( + 'test/src/post_medium/post_medium_test.dart', + ); setUpMockPathProvider(); }); diff --git a/flutter_news_example/packages/news_blocks_ui/test/src/post_small_test.dart b/flutter_news_example/packages/news_blocks_ui/test/src/post_small_test.dart index d7d601dde..b09c2654a 100644 --- a/flutter_news_example/packages/news_blocks_ui/test/src/post_small_test.dart +++ b/flutter_news_example/packages/news_blocks_ui/test/src/post_small_test.dart @@ -17,7 +17,7 @@ void main() { // Change the default factory databaseFactory = databaseFactoryFfi; - setUpTolerantComparator(); + setUpTolerantComparator('test/src/post_small_test.dart'); setUpMockPathProvider(); }); diff --git a/flutter_news_example/packages/news_blocks_ui/test/src/section_header_test.dart b/flutter_news_example/packages/news_blocks_ui/test/src/section_header_test.dart index e6c13f270..15d200603 100644 --- a/flutter_news_example/packages/news_blocks_ui/test/src/section_header_test.dart +++ b/flutter_news_example/packages/news_blocks_ui/test/src/section_header_test.dart @@ -7,7 +7,9 @@ import '../helpers/helpers.dart'; void main() { group('SectionHeader', () { - setUpAll(setUpTolerantComparator); + setUpAll( + () => setUpTolerantComparator('test/src/section_header_test.dart'), + ); testWidgets('renders correctly without action', (tester) async { const widget = Center( diff --git a/flutter_news_example/packages/news_blocks_ui/test/src/spacer_test.dart b/flutter_news_example/packages/news_blocks_ui/test/src/spacer_test.dart index 8f6fa6194..b3f505eb8 100644 --- a/flutter_news_example/packages/news_blocks_ui/test/src/spacer_test.dart +++ b/flutter_news_example/packages/news_blocks_ui/test/src/spacer_test.dart @@ -9,7 +9,9 @@ import '../helpers/helpers.dart'; void main() { group('Spacer', () { - setUpAll(setUpTolerantComparator); + setUpAll( + () => setUpTolerantComparator('test/src/spacer_test.dart'), + ); testWidgets('renders correctly for extraSmall spacing', (tester) async { final widget = ColoredBox( diff --git a/flutter_news_example/packages/news_blocks_ui/test/src/text_caption_test.dart b/flutter_news_example/packages/news_blocks_ui/test/src/text_caption_test.dart index 4b05c5281..aabb906f4 100644 --- a/flutter_news_example/packages/news_blocks_ui/test/src/text_caption_test.dart +++ b/flutter_news_example/packages/news_blocks_ui/test/src/text_caption_test.dart @@ -9,7 +9,9 @@ import '../helpers/helpers.dart'; void main() { group('TextCaption', () { - setUpAll(setUpTolerantComparator); + setUpAll( + () => setUpTolerantComparator('test/src/text_caption_test.dart'), + ); testWidgets( 'renders correctly ' diff --git a/flutter_news_example/packages/news_blocks_ui/test/src/text_headline_test.dart b/flutter_news_example/packages/news_blocks_ui/test/src/text_headline_test.dart index 84e069292..97be6b2e2 100644 --- a/flutter_news_example/packages/news_blocks_ui/test/src/text_headline_test.dart +++ b/flutter_news_example/packages/news_blocks_ui/test/src/text_headline_test.dart @@ -9,7 +9,9 @@ import '../helpers/helpers.dart'; void main() { group('TextHeadline', () { - setUpAll(setUpTolerantComparator); + setUpAll( + () => setUpTolerantComparator('test/src/text_headline_test.dart'), + ); testWidgets('renders correctly', (tester) async { final widget = Center( diff --git a/flutter_news_example/packages/news_blocks_ui/test/src/text_lead_paragraph_test.dart b/flutter_news_example/packages/news_blocks_ui/test/src/text_lead_paragraph_test.dart index 7f9f2c086..6b6507a8f 100644 --- a/flutter_news_example/packages/news_blocks_ui/test/src/text_lead_paragraph_test.dart +++ b/flutter_news_example/packages/news_blocks_ui/test/src/text_lead_paragraph_test.dart @@ -9,7 +9,9 @@ import '../helpers/helpers.dart'; void main() { group('TextLeadParagraph', () { - setUpAll(setUpTolerantComparator); + setUpAll( + () => setUpTolerantComparator('test/src/text_lead_paragraph_test.dart'), + ); testWidgets('renders correctly', (tester) async { final widget = Center( diff --git a/flutter_news_example/packages/news_blocks_ui/test/src/text_paragraph_test.dart b/flutter_news_example/packages/news_blocks_ui/test/src/text_paragraph_test.dart index c8b8aaca4..59aa59169 100644 --- a/flutter_news_example/packages/news_blocks_ui/test/src/text_paragraph_test.dart +++ b/flutter_news_example/packages/news_blocks_ui/test/src/text_paragraph_test.dart @@ -9,8 +9,9 @@ import '../helpers/helpers.dart'; void main() { group('TextParagraph', () { - setUpAll(setUpTolerantComparator); - + setUpAll( + () => setUpTolerantComparator('test/src/text_paragraph_test.dart'), + ); testWidgets('renders correctly', (tester) async { final widget = Center( child: TextParagraph( diff --git a/flutter_news_example/packages/news_blocks_ui/test/src/trending_story_test.dart b/flutter_news_example/packages/news_blocks_ui/test/src/trending_story_test.dart index 48729f39a..166fff79f 100644 --- a/flutter_news_example/packages/news_blocks_ui/test/src/trending_story_test.dart +++ b/flutter_news_example/packages/news_blocks_ui/test/src/trending_story_test.dart @@ -16,7 +16,7 @@ void main() { // Change the default factory databaseFactory = databaseFactoryFfi; - setUpTolerantComparator(); + setUpTolerantComparator('test/src/trending_story_test.dart'); setUpMockPathProvider(); }); diff --git a/flutter_news_example/packages/news_blocks_ui/test/src/video_introduction_test.dart b/flutter_news_example/packages/news_blocks_ui/test/src/video_introduction_test.dart index a159cab95..87439714b 100644 --- a/flutter_news_example/packages/news_blocks_ui/test/src/video_introduction_test.dart +++ b/flutter_news_example/packages/news_blocks_ui/test/src/video_introduction_test.dart @@ -24,7 +24,9 @@ void main() { () { final fakeVideoPlayerPlatform = FakeVideoPlayerPlatform(); VideoPlayerPlatform.instance = fakeVideoPlayerPlatform; - setUpTolerantComparator(); + setUpTolerantComparator( + 'test/src/video_introduction_test.dart', + ); }, ); diff --git a/flutter_news_example/packages/news_blocks_ui/test/src/widgets/banner_ad_content_test.dart b/flutter_news_example/packages/news_blocks_ui/test/src/widgets/banner_ad_content_test.dart index 9cf886120..339cbb751 100644 --- a/flutter_news_example/packages/news_blocks_ui/test/src/widgets/banner_ad_content_test.dart +++ b/flutter_news_example/packages/news_blocks_ui/test/src/widgets/banner_ad_content_test.dart @@ -152,28 +152,26 @@ void main() { }); testWidgets('renders AdWidget when ad is loaded', (tester) async { - await tester.runAsync(() async { - ad = BannerAd( - size: AdSize.banner, - adUnitId: BannerAdContent.androidTestUnitId, - listener: BannerAdListener(), - request: AdRequest(), - ); + ad = BannerAd( + size: AdSize.banner, + adUnitId: BannerAdContent.androidTestUnitId, + listener: BannerAdListener(), + request: AdRequest(), + ); - await tester.pumpApp( - BannerAdContent( - size: BannerAdSize.normal, - adBuilder: adBuilder, - currentPlatform: platform, - ), - ); + await tester.pumpApp( + BannerAdContent( + size: BannerAdSize.normal, + adBuilder: adBuilder, + currentPlatform: platform, + ), + ); - capturedListener.onAdLoaded!(ad); - await tester.pumpAndSettle(); + capturedListener.onAdLoaded!(ad); + await tester.pumpAndSettle(); - expect(find.byType(AdWidget), findsOneWidget); - expect(find.byType(ProgressIndicator), findsNothing); - }); + expect(find.byType(AdWidget), findsOneWidget); + expect(find.byType(ProgressIndicator), findsNothing); }); testWidgets('uses AdSize.banner for BannerAdSize.normal', (tester) async { diff --git a/flutter_news_example/packages/news_blocks_ui/test/src/widgets/post_footer_test.dart b/flutter_news_example/packages/news_blocks_ui/test/src/widgets/post_footer_test.dart index e1a28cb74..55b594297 100644 --- a/flutter_news_example/packages/news_blocks_ui/test/src/widgets/post_footer_test.dart +++ b/flutter_news_example/packages/news_blocks_ui/test/src/widgets/post_footer_test.dart @@ -8,7 +8,9 @@ import '../../helpers/helpers.dart'; void main() { group('PostFooter', () { - setUpAll(setUpTolerantComparator); + setUpAll( + () => setUpTolerantComparator('test/src/widgets/post_footer_test.dart'), + ); testWidgets('renders correctly', (tester) async { await tester.pumpApp(