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. |
swissspidy
left a comment
There was a problem hiding this comment.
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, andexpectedkeys. With this PR, now tests are in separate directories withset-up.php,buffer.html, andexpected.htmlfiles. Whenever thebuffer.htmlandexpected.htmlfiles 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.htmlto update the test. This is also the case when creating a new test, where you just add aset-up.phpandbuffer.htmland the test will then issue an "test incomplete" warning while writing out theactual.htmlfor the developer to then examine and rename toexpected.htmlif 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.htmlfiles. So these do not need to be reviewed. The only exception may be theset_uplogic invideo-with-large-poster-and-desktop-url-metrics-missingandvideo-with-large-poster-and-desktop-url-metrics-collectedwhich 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