Skip to content

Commit 5e657a5

Browse files
Initial commit - includes GoldenCamera and a prototype golden test.
0 parents  commit 5e657a5

File tree

11 files changed

+338
-0
lines changed

11 files changed

+338
-0
lines changed

.gitignore

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
migrate_working_dir/
12+
13+
# IntelliJ related
14+
*.iml
15+
*.ipr
16+
*.iws
17+
.idea/
18+
19+
# The .vscode folder contains launch configuration and tasks you configure in
20+
# VS Code which you may wish to be included in version control, so this line
21+
# is commented out by default.
22+
#.vscode/
23+
24+
# Flutter/Dart/Pub related
25+
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
26+
/pubspec.lock
27+
**/doc/api/
28+
.dart_tool/
29+
.flutter-plugins
30+
.flutter-plugins-dependencies
31+
build/

.metadata

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: "17025dd88227cd9532c33fa78f5250d548d87e9a"
8+
channel: "stable"
9+
10+
project_type: package

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 0.0.1 - Feb 24, 2025 - Initial release
2+
3+
* `GoldenCamera`: Takes and stores photos.

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright (c) 2022 Declarative, Inc.
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!--
2+
This README describes the package. If you publish this package to pub.dev,
3+
this README's contents appear on the landing page for your package.
4+
5+
For information about how to write a good package README, see the guide for
6+
[writing package pages](https://dart.dev/tools/pub/writing-package-pages).
7+
8+
For general information about developing packages, see the Dart guide for
9+
[creating packages](https://dart.dev/guides/libraries/create-packages)
10+
and the Flutter guide for
11+
[developing packages and plugins](https://flutter.dev/to/develop-packages).
12+
-->
13+
14+
TODO: Put a short description of the package here that helps potential users
15+
know whether this package might be useful for them.
16+
17+
## Features
18+
19+
TODO: List what your package can do. Maybe include images, gifs, or videos.
20+
21+
## Getting started
22+
23+
TODO: List prerequisites and provide or point to information on how to
24+
start using the package.
25+
26+
## Usage
27+
28+
TODO: Include short and useful examples for package users. Add longer examples
29+
to `/example` folder.
30+
31+
```dart
32+
const like = 'sample';
33+
```
34+
35+
## Additional information
36+
37+
TODO: Tell users more about the package: where to find more information, how to
38+
contribute to the package, how to file issues, what response they can expect
39+
from the package authors, and more.

analysis_options.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include: package:flutter_lints/flutter.yaml
2+
3+
# Additional information about this file can be found at
4+
# https://dart.dev/guides/language/analysis-options

lib/flutter_test_goldens.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export 'src/golden_camera.dart';

lib/src/golden_camera.dart

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import 'dart:ui';
2+
3+
import 'package:flutter/rendering.dart';
4+
import 'package:flutter_test/flutter_test.dart';
5+
6+
/// A camera for taking golden screenshots and storing them for later reference.
7+
class GoldenCamera {
8+
List<GoldenPhoto> get photos => List.from(_photos);
9+
final _photos = <GoldenPhoto>[];
10+
11+
/// Takes a screenshot of the given [finder] and stores it in [photos]
12+
/// along with its [description].
13+
Future<void> takePhoto(Finder finder, String description) async {
14+
expect(finder, findsOne);
15+
16+
final repaintBoundary = finder.evaluate().first.renderObject! as RenderRepaintBoundary;
17+
final pixels = await repaintBoundary.toImage(pixelRatio: 1.0);
18+
19+
_photos.add(
20+
GoldenPhoto(description, pixels),
21+
);
22+
}
23+
}
24+
25+
/// A golden screenshot along with a description.
26+
class GoldenPhoto {
27+
const GoldenPhoto(this.description, this.pixels);
28+
29+
final String description;
30+
final Image pixels;
31+
}

pubspec.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: flutter_test_goldens
2+
description: "A toolkit for writing golden tests"
3+
version: 0.0.1
4+
homepage:
5+
6+
environment:
7+
sdk: ^3.6.0
8+
flutter: ">=1.17.0"
9+
10+
dependencies:
11+
flutter:
12+
sdk: flutter
13+
flutter_test:
14+
sdk: flutter
15+
16+
dev_dependencies:
17+
flutter_lints: ^5.0.0
18+
19+
lucid:
20+
git:
21+
url: [email protected]:Flutter-Bounty-Hunters/lucid.git
22+
23+
# For information on the generic Dart part of this file, see the
24+
# following page: https://dart.dev/tools/pub/pubspec
25+
26+
# The following section is specific to Flutter packages.
27+
flutter:
28+
29+
# To add assets to your package, add an assets section, like this:
30+
# assets:
31+
# - images/a_dot_burr.jpeg
32+
# - images/a_dot_ham.jpeg
33+
#
34+
# For details regarding assets in packages, see
35+
# https://flutter.dev/to/asset-from-package
36+
#
37+
# An image asset can refer to one or more resolution-specific "variants", see
38+
# https://flutter.dev/to/resolution-aware-images
39+
40+
# To add custom fonts to your package, add a fonts section here,
41+
# in this "flutter" section. Each entry in this list should have a
42+
# "family" key with the font family name, and a "fonts" key with a
43+
# list giving the asset and other descriptors for the font. For
44+
# example:
45+
# fonts:
46+
# - family: Schyler
47+
# fonts:
48+
# - asset: fonts/Schyler-Regular.ttf
49+
# - asset: fonts/Schyler-Italic.ttf
50+
# style: italic
51+
# - family: Trajan Pro
52+
# fonts:
53+
# - asset: fonts/TrajanPro.ttf
54+
# - asset: fonts/TrajanPro_Bold.ttf
55+
# weight: 700
56+
#
57+
# For details regarding fonts in packages, see
58+
# https://flutter.dev/to/font-from-package

test_goldens/button.png

1.58 KB
Loading

0 commit comments

Comments
 (0)