diff --git a/CHANGELOG.md b/CHANGELOG.md index 3abf91f34..6b3870c1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 0.23.2 - Allow `package:analyzer` range to accept `^9.0.0` too. +- Fix issue where screenshots with same filenames but located in different subdirectories were overwriting each other during processing. ## 0.23.1 diff --git a/lib/src/screenshots.dart b/lib/src/screenshots.dart index c66adf3f7..f5794e0e8 100644 --- a/lib/src/screenshots.dart +++ b/lib/src/screenshots.dart @@ -140,21 +140,29 @@ Future _processScreenshot( p.Screenshot e, String tempDir, ) async { - final basename = path.basenameWithoutExtension(e.path); - final webpName = '$basename.webp'; + final nameWithNoExt = path.withoutExtension(e.path); + final webpName = '$nameWithNoExt.webp'; + final pngName = '$nameWithNoExt.png'; + final genDir = 'gen'; final thumbnail100Dir = path.join(genDir, '100x100'); final thumbnail190Dir = path.join(genDir, '190x190'); final webpPath = path.join(genDir, webpName); final webp100ThumbnailPath = path.join(thumbnail100Dir, webpName); final webp190ThumbnailPath = path.join(thumbnail190Dir, webpName); - final pngName = '$basename.png'; final png100ThumbnailPath = path.join(thumbnail100Dir, pngName); final png190ThumbnailPath = path.join(thumbnail190Dir, pngName); final originalPath = path.join(pkgDir, e.path); - Directory(path.join(tempDir, thumbnail100Dir)).createSync(recursive: true); - Directory(path.join(tempDir, thumbnail190Dir)).createSync(recursive: true); + Directory( + path.join(tempDir, path.dirname(webpPath)), + ).createSync(recursive: true); + Directory( + path.join(tempDir, path.dirname(webp100ThumbnailPath)), + ).createSync(recursive: true); + Directory( + path.join(tempDir, path.dirname(webp190ThumbnailPath)), + ).createSync(recursive: true); final webpScreenshotProblems = await _generateWebpScreenshot( originalPath, diff --git a/test/screenshot_test.dart b/test/screenshot_test.dart index f999dc7c3..dbb583895 100644 --- a/test/screenshot_test.dart +++ b/test/screenshot_test.dart @@ -120,6 +120,26 @@ void main() { ); }); + test('same name screenshots are not overridden', () async { + if (!hasWebpTools) return; + + final pkgDir = _testImagesDir; + final s = Screenshot('description', 'static.webp'); + final s2 = Screenshot('description', 's2/static.webp'); + + final result = await processAllScreenshots([s, s2], pkgDir); + + expect(result.length, 2); + expect(result[0].problems, isEmpty); + expect(result[0].processedScreenshot, isNotNull); + expect(result[1].problems, isEmpty); + expect(result[1].processedScreenshot, isNotNull); + expect( + result[0].processedScreenshot!.webpImage, + isNot(equals(result[1].processedScreenshot!.webpImage)), + ); + }, skip: !hasWebpTools); + test('success - process WebP, PNG and GIFs', () async { if (!hasWebpTools) return; final pkgDir = _testImagesDir; diff --git a/test/testImages/s2/static.webp b/test/testImages/s2/static.webp new file mode 100644 index 000000000..7e0aaf5d1 Binary files /dev/null and b/test/testImages/s2/static.webp differ