diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml
index ad81dc2..ca3cd67 100644
--- a/.github/workflows/run-tests.yml
+++ b/.github/workflows/run-tests.yml
@@ -35,6 +35,10 @@ jobs:
coverage: pcov
ini-values: pcov.directory=src
+ - name: Fix Imagick Policy for PDFs
+ run: |
+ sudo sed -i 's///g' /etc/ImageMagick-6/policy.xml
+
- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
@@ -60,7 +64,7 @@ jobs:
SIDECAR_EXECUTION_ROLE: ${{secrets.SIDECAR_EXECUTION_ROLE}}
- name: Execute tests
- run: vendor/bin/pest --coverage
+ run: vendor/bin/pest --coverage --exclude-group=pdf-comparison
env:
SIDECAR_ACCESS_KEY_ID: ${{secrets.SIDECAR_ACCESS_KEY_ID}}
SIDECAR_SECRET_ACCESS_KEY: ${{secrets.SIDECAR_SECRET_ACCESS_KEY}}
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 264fb69..f629f87 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,7 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
-## [Unreleased](https://github.com/stefanzweifel/sidecar-browsershot/compare/v2.0.0...HEAD)
+## [Unreleased](https://github.com/stefanzweifel/sidecar-browsershot/compare/v2.1.0...HEAD)
+
+## [v2.1.0](https://github.com/stefanzweifel/sidecar-browsershot/compare/v2.0.0...v2.1.0) - 2024-02-17
+
+### Changed
+
+- Update used AWS Lambda Layers to use puppeteer-core v22 and Chromium v121.0.0 ([#113](https://github.com/stefanzweifel/sidecar-browsershot/pull/113))
## [v2.0.0](https://github.com/stefanzweifel/sidecar-browsershot/compare/v1.13.1...v2.0.0) - 2023-12-30
diff --git a/composer.json b/composer.json
index 333b9a8..4dbdf39 100644
--- a/composer.json
+++ b/composer.json
@@ -26,6 +26,7 @@
"spatie/laravel-package-tools": "^1.9.2"
},
"require-dev": {
+ "ext-imagick": "*",
"larastan/larastan": "^1.0|^2.0",
"laravel/pint": "^1.13",
"league/flysystem-aws-s3-v3": "^1.0|^2.0|^3.0",
diff --git a/config/sidecar-browsershot.php b/config/sidecar-browsershot.php
index 50217b8..217f3ef 100644
--- a/config/sidecar-browsershot.php
+++ b/config/sidecar-browsershot.php
@@ -43,8 +43,8 @@
* @see https://github.com/stefanzweifel/sidecar-browsershot-layer
*/
'layers' => [
- // "arn:aws:lambda:us-east-1:821527532446:layer:sidecar-browsershot-layer:1",
- // "arn:aws:lambda:us-east-1:764866452798:layer:chrome-aws-lambda:37",
+ // "arn:aws:lambda:us-east-1:821527532446:layer:sidecar-browsershot-layer:2",
+ // "arn:aws:lambda:us-east-1:764866452798:layer:chrome-aws-lambda:42",
],
/**
diff --git a/src/Functions/BrowsershotFunction.php b/src/Functions/BrowsershotFunction.php
index 6653b8d..da62920 100644
--- a/src/Functions/BrowsershotFunction.php
+++ b/src/Functions/BrowsershotFunction.php
@@ -134,16 +134,16 @@ public function layers()
$region = config('sidecar.aws_region');
if ($region === 'ap-northeast-2') {
- $chromeAwsLambdaVersion = 36;
+ $chromeAwsLambdaVersion = 41;
} else {
- $chromeAwsLambdaVersion = 37;
+ $chromeAwsLambdaVersion = 42;
}
// Add Layers that each contain `puppeteer-core` and `@sparticuz/chromium`
// https://github.com/stefanzweifel/sidecar-browsershot-layer
// https://github.com/shelfio/chrome-aws-lambda-layer
return [
- "arn:aws:lambda:{$region}:821527532446:layer:sidecar-browsershot-layer:1",
+ "arn:aws:lambda:{$region}:821527532446:layer:sidecar-browsershot-layer:2",
"arn:aws:lambda:{$region}:764866452798:layer:chrome-aws-lambda:{$chromeAwsLambdaVersion}",
];
}
diff --git a/tests/BrowsershotLambdaReferenceTest.php b/tests/BrowsershotLambdaReferenceTest.php
index a3c5519..c509c95 100644
--- a/tests/BrowsershotLambdaReferenceTest.php
+++ b/tests/BrowsershotLambdaReferenceTest.php
@@ -36,7 +36,8 @@
it('generates reference hello-world-with-smileys.pdf', function () {
$pdf = BrowsershotLambda::html('
Hello world!! 👋🦫ðŸ«
')->pdf();
$pdfWithCorrectDates = $this->updateCreationDateAndModDateOfPdf($pdf);
+
$reference = file_get_contents(__DIR__.'/references/hello-world-with-smileys.pdf');
- $this->assertEquals($reference, $pdfWithCorrectDates);
-});
+ $this->assertPdfsAreSimilar($reference, $pdfWithCorrectDates, threshold: 200);
+})->group('pdf-comparison');
diff --git a/tests/TestCase.php b/tests/TestCase.php
index ee9606c..17cfe61 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -4,7 +4,9 @@
use Hammerstone\Sidecar\Providers\SidecarServiceProvider;
use Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables;
+use Imagick;
use Orchestra\Testbench\TestCase as Orchestra;
+use PHPUnit\Framework\Assert;
use Wnx\SidecarBrowsershot\Functions\BrowsershotFunction;
use Wnx\SidecarBrowsershot\SidecarBrowsershotServiceProvider;
@@ -51,4 +53,26 @@ protected function updateCreationDateAndModDateOfPdf(string $pdf): string
"/ModDate (D:20230101000000+00'00')>>\n",
], $pdf, limit: 1);
}
+
+ public function assertPdfsAreSimilar(string $expected, string $actual, float $threshold = 0): void
+ {
+ $expectedPdf = new Imagick();
+ $expectedPdf->readImageBlob($expected);
+ $expectedPdf->resetIterator();
+ $expectedPdf = $expectedPdf->appendImages(true);
+
+ $actualPdf = new Imagick();
+ $actualPdf->readImageBlob($actual);
+ $actualPdf->resetIterator();
+ $actualPdf = $actualPdf->appendImages(true);
+
+ $diff = $expectedPdf->compareImages($actualPdf, imagick::METRIC_ABSOLUTEERRORMETRIC);
+
+ $diffValue = $diff[1];
+
+ // Assert that the difference is less than or equal to the threshold
+ Assert::assertLessThanOrEqual($threshold, $diffValue, sprintf(
+ 'The PDFs are not similar (Difference: %d)', $diffValue
+ ));
+ }
}
diff --git a/tests/references/hello-world-with-smileys.pdf b/tests/references/hello-world-with-smileys.pdf
index cc6f125..7cf313f 100644
Binary files a/tests/references/hello-world-with-smileys.pdf and b/tests/references/hello-world-with-smileys.pdf differ
diff --git a/tests/references/hello-world-with-smileys.png b/tests/references/hello-world-with-smileys.png
index c7eba5f..c3360c0 100644
Binary files a/tests/references/hello-world-with-smileys.png and b/tests/references/hello-world-with-smileys.png differ