Skip to content

Commit ad4b9ce

Browse files
authored
Fix screenshot overwrite bug (#1523)
1 parent 61464e6 commit ad4b9ce

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 0.23.2
22

33
- Allow `package:analyzer` range to accept `^9.0.0` too.
4+
- Fix issue where screenshots with same filenames but located in different subdirectories were overwriting each other during processing.
45

56
## 0.23.1
67

lib/src/screenshots.dart

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,21 +140,29 @@ Future<ScreenshotResult> _processScreenshot(
140140
p.Screenshot e,
141141
String tempDir,
142142
) async {
143-
final basename = path.basenameWithoutExtension(e.path);
144-
final webpName = '$basename.webp';
143+
final nameWithNoExt = path.withoutExtension(e.path);
144+
final webpName = '$nameWithNoExt.webp';
145+
final pngName = '$nameWithNoExt.png';
146+
145147
final genDir = 'gen';
146148
final thumbnail100Dir = path.join(genDir, '100x100');
147149
final thumbnail190Dir = path.join(genDir, '190x190');
148150
final webpPath = path.join(genDir, webpName);
149151
final webp100ThumbnailPath = path.join(thumbnail100Dir, webpName);
150152
final webp190ThumbnailPath = path.join(thumbnail190Dir, webpName);
151-
final pngName = '$basename.png';
152153
final png100ThumbnailPath = path.join(thumbnail100Dir, pngName);
153154
final png190ThumbnailPath = path.join(thumbnail190Dir, pngName);
154155
final originalPath = path.join(pkgDir, e.path);
155156

156-
Directory(path.join(tempDir, thumbnail100Dir)).createSync(recursive: true);
157-
Directory(path.join(tempDir, thumbnail190Dir)).createSync(recursive: true);
157+
Directory(
158+
path.join(tempDir, path.dirname(webpPath)),
159+
).createSync(recursive: true);
160+
Directory(
161+
path.join(tempDir, path.dirname(webp100ThumbnailPath)),
162+
).createSync(recursive: true);
163+
Directory(
164+
path.join(tempDir, path.dirname(webp190ThumbnailPath)),
165+
).createSync(recursive: true);
158166

159167
final webpScreenshotProblems = await _generateWebpScreenshot(
160168
originalPath,

test/screenshot_test.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,26 @@ void main() {
120120
);
121121
});
122122

123+
test('same name screenshots are not overridden', () async {
124+
if (!hasWebpTools) return;
125+
126+
final pkgDir = _testImagesDir;
127+
final s = Screenshot('description', 'static.webp');
128+
final s2 = Screenshot('description', 's2/static.webp');
129+
130+
final result = await processAllScreenshots([s, s2], pkgDir);
131+
132+
expect(result.length, 2);
133+
expect(result[0].problems, isEmpty);
134+
expect(result[0].processedScreenshot, isNotNull);
135+
expect(result[1].problems, isEmpty);
136+
expect(result[1].processedScreenshot, isNotNull);
137+
expect(
138+
result[0].processedScreenshot!.webpImage,
139+
isNot(equals(result[1].processedScreenshot!.webpImage)),
140+
);
141+
}, skip: !hasWebpTools);
142+
123143
test('success - process WebP, PNG and GIFs', () async {
124144
if (!hasWebpTools) return;
125145
final pkgDir = _testImagesDir;

test/testImages/s2/static.webp

3.27 KB
Loading

0 commit comments

Comments
 (0)