-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve snapshot testing for Optimization Detective #1791
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## trunk #1791 +/- ##
=======================================
Coverage 57.43% 57.43%
=======================================
Files 84 84
Lines 6508 6508
=======================================
Hits 3738 3738
Misses 2770 2770
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice evolution on how tests for Optimization Detective are written! This will definitely speed up development going forward.
Writing snapshot tests for Optimization Detective has been tedious since the buffer HTML and expected HTML have been embedded in PHP files. This has made adding new tests tedious by needing to ensure the HTML is properly escaped. The HTML in the PHP files was also indented additional tabs for readability, and when attempting to paste updates to the expected output into the PHP, this would often cause problems with auto-formatting.
Previously test cases were contained in single PHP files which returned an array with
set_up
,buffer
, andexpected
keys. With this PR, now tests are in separate directories withset-up.php
,buffer.html
, andexpected.html
files. Whenever thebuffer.html
andexpected.html
files do not match during tests, then the test will emit anactual.html
(which is ignored from git) which the developer can then simply rename toexpected.html
to update the test. This is also the case when creating a new test, where you just add aset-up.php
andbuffer.html
and the test will then issue an "test incomplete" warning while writing out theactual.html
for the developer to then examine and rename toexpected.html
if it is all as expected.This PR also removes duplicated test set up logic between Optimization Detective, Image Prioritizer, and Embed Optimizer.
This PR is massive, but the changes in
plugins/**/test-cases/*
are just splitting up the PHP files into theset-up.php
,buffer.html
, andexpected.html
files. So these do not need to be reviewed. The only exception may be theset_up
logic invideo-with-large-poster-and-desktop-url-metrics-missing
andvideo-with-large-poster-and-desktop-url-metrics-collected
which change/improve how the image URLs are inserted into the buffer using placeholder replacements.Note that phpunit-snapshot-assertions cannot be used because it requires PHP 8.1.
Fixes #1418