Skip to content

Commit 4a171bc

Browse files
authored
Use containerized odiff tool to compare screenshots. (#8628)
1 parent add7595 commit 4a171bc

File tree

3 files changed

+67
-5
lines changed

3 files changed

+67
-5
lines changed

pkg/pub_integration/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Screenshots
2+
3+
## Tools
4+
5+
The screenshots are created during the `puppeteer` tests, if the `PUB_SCREENSHOT_DIR`
6+
environment variable is set.
7+
8+
The comparison is created by the `odiff` tool using `docker`. To build the `odiff`
9+
container, user the following command:
10+
11+
```
12+
cd tool
13+
docker build . -f Dockerfile.odiff -t odiff
14+
```
15+
16+
## Before/after screenshots
17+
18+
To create before/after screenshot comparisons, use the following workflow:
19+
20+
1. Run `pkg/pub_integration` tests with `PUB_SCREENSHOT_DIR=/path/to/before/dir`.
21+
1. Make the changes.
22+
1. Run `pkg/pub_integration` tests with `PUB_SCREENSHOT_DIR=/path/to/after/dir`.
23+
1. Run `dart tool/compare_screenshots.dart <before-dir> <after-dir> <diff-dir>`
24+
25+
The comparison will put the files into the `<diff-dir>` with the before/after/diff
26+
versions, alongside a summary `index.html` file to have a quick overview of them.
27+
28+
## Missing features
29+
30+
- Create a better side-by-side comparison for images, as right now everything is just a list of images.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM debian:trixie-slim
2+
3+
RUN apt -y update
4+
RUN apt -y install npm
5+
6+
WORKDIR /root
7+
RUN npm install [email protected]
8+
9+
RUN mkdir -p /root/before
10+
RUN mkdir -p /root/after
11+
RUN mkdir -p /root/diff
12+
13+
ENTRYPOINT [ "/root/node_modules/odiff-bin/bin/odiff.exe" ]

pkg/pub_integration/tool/compare_screenshots.dart

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,27 @@ Future<void> main(List<String> args) async {
1717

1818
final reportDir = Directory(args[2]);
1919
await reportDir.create(recursive: true);
20-
await _CompareTool(beforeFiles, afterFiles, reportDir)._compare();
20+
await _CompareTool(
21+
args[0],
22+
beforeFiles,
23+
args[1],
24+
afterFiles,
25+
reportDir,
26+
)._compare();
2127
}
2228

2329
class _CompareTool {
30+
final String _beforeDir;
31+
final String _afterDir;
2432
final Directory _reportDir;
2533
final Map<String, File> _beforeFiles;
2634
final Map<String, File> _afterFiles;
2735
final _report = StringBuffer();
2836

2937
_CompareTool(
38+
this._beforeDir,
3039
this._beforeFiles,
40+
this._afterDir,
3141
this._afterFiles,
3242
this._reportDir,
3343
);
@@ -77,10 +87,19 @@ class _CompareTool {
7787
p.join(_reportDir.path, relativeDir, '$basename-diff.png');
7888
await File(diffPath).parent.create(recursive: true);
7989

80-
final pr = await Process.run('compare', [
81-
before.path,
82-
after.path,
83-
diffPath,
90+
final pr = await Process.run('docker', [
91+
'run',
92+
'--rm',
93+
'-v',
94+
'$_beforeDir:/root/before',
95+
'-v',
96+
'$_afterDir:/root/after',
97+
'-v',
98+
'${_reportDir.path}:/root/diff',
99+
'odiff',
100+
p.join('/root/before', relativeDir, '$basename.png'),
101+
p.join('/root/after', relativeDir, '$basename.png'),
102+
p.join('/root/diff', relativeDir, '$basename-diff.png'),
84103
]);
85104
if (pr.exitCode == 0) continue;
86105

0 commit comments

Comments
 (0)