From 48c2301f7a2a916cde25116c2f7704c64f3638d3 Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Mon, 9 Dec 2024 12:00:26 -0800 Subject: [PATCH] Add a simple golden-file test to `package:integration_test`. (#159233) Closes https://github.com/flutter/flutter/issues/72045. Let's see if I wired this correctly and if `Flutter Gold` knows to check based on the files changed. --- packages/integration_test/pubspec.yaml | 4 ++++ .../integration_test/test/_goldens_io.dart | 5 ++++ .../integration_test/test/_goldens_web.dart | 8 +++++++ .../test/flutter_test_config.dart | 12 ++++++++++ .../test/golden_screenshot_test.dart | 23 +++++++++++++++++++ 5 files changed, 52 insertions(+) create mode 100644 packages/integration_test/test/_goldens_io.dart create mode 100644 packages/integration_test/test/_goldens_web.dart create mode 100644 packages/integration_test/test/flutter_test_config.dart create mode 100644 packages/integration_test/test/golden_screenshot_test.dart diff --git a/packages/integration_test/pubspec.yaml b/packages/integration_test/pubspec.yaml index 0fed29b84a..19abe2f7f8 100644 --- a/packages/integration_test/pubspec.yaml +++ b/packages/integration_test/pubspec.yaml @@ -38,6 +38,10 @@ dependencies: vector_math: 2.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" webdriver: 3.0.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" +dev_dependencies: + flutter_goldens: + sdk: flutter + flutter: plugin: platforms: diff --git a/packages/integration_test/test/_goldens_io.dart b/packages/integration_test/test/_goldens_io.dart new file mode 100644 index 0000000000..d552235d69 --- /dev/null +++ b/packages/integration_test/test/_goldens_io.dart @@ -0,0 +1,5 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +export 'package:flutter_goldens/flutter_goldens.dart' show testExecutable; diff --git a/packages/integration_test/test/_goldens_web.dart b/packages/integration_test/test/_goldens_web.dart new file mode 100644 index 0000000000..a18d6a13d4 --- /dev/null +++ b/packages/integration_test/test/_goldens_web.dart @@ -0,0 +1,8 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +// package:flutter_goldens is not used as part of the test process for web. +Future testExecutable(FutureOr Function() testMain, {String? namePrefix}) async => testMain(); diff --git a/packages/integration_test/test/flutter_test_config.dart b/packages/integration_test/test/flutter_test_config.dart new file mode 100644 index 0000000000..f985a52917 --- /dev/null +++ b/packages/integration_test/test/flutter_test_config.dart @@ -0,0 +1,12 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +import '_goldens_io.dart' if (dart.library.js_interop) '_goldens_web.dart' as flutter_goldens; + +Future testExecutable(FutureOr Function() testMain) { + // Enable golden file testing using Skia Gold. + return flutter_goldens.testExecutable(testMain, namePrefix: 'integration'); +} diff --git a/packages/integration_test/test/golden_screenshot_test.dart b/packages/integration_test/test/golden_screenshot_test.dart new file mode 100644 index 0000000000..3069159a25 --- /dev/null +++ b/packages/integration_test/test/golden_screenshot_test.dart @@ -0,0 +1,23 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +@Tags(['reduced-test-set']) +library; + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets('a screenshot of a Placeholder', (WidgetTester tester) async { + await tester.pumpWidget(const Placeholder()); + + await expectLater( + find.byType(Placeholder), + matchesGoldenFile('placeholder.png'), + ); + }); +}