-
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
Ensure optimization is performed in the wp-env local environment and log debug messages to console when disabled #1822
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. |
'reason' => __( 'Page is not optimized because od_can_optimize_response() returned false. This can be overridden with the od_can_optimize_response filter.', 'optimization-detective' ), | ||
), | ||
array( | ||
'test' => ! ( od_is_rest_api_unavailable() && ( wp_get_environment_type() !== 'local' || class_exists( 'Test_OD_Optimization' ) ) ), |
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.
I wish the class_exists( 'Test_OD_Optimization' )
check weren't needed, but there's apparently no way to override the return value of wp_get_environment_type()
in tests.
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.
Not a blocker, but is there a more generic way to check if tests are being run? Maybe a constant that the WP core unit test suite always sets?
} | ||
} | ||
if ( count( $reasons ) > 0 ) { | ||
if ( WP_DEBUG ) { |
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.
Test coverage for this condition can't be added due to #1271.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## trunk #1822 +/- ##
==========================================
+ Coverage 65.47% 65.96% +0.49%
==========================================
Files 85 88 +3
Lines 6748 6876 +128
==========================================
+ Hits 4418 4536 +118
- Misses 2330 2340 +10
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
0cb53df
to
e9c0618
Compare
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.
@westonruter LGTM, just two minor notes.
'reason' => __( 'Page is not optimized because od_can_optimize_response() returned false. This can be overridden with the od_can_optimize_response filter.', 'optimization-detective' ), | ||
), | ||
array( | ||
'test' => ! ( od_is_rest_api_unavailable() && ( wp_get_environment_type() !== 'local' || class_exists( 'Test_OD_Optimization' ) ) ), |
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.
Not a blocker, but is there a more generic way to check if tests are being run? Maybe a constant that the WP core unit test suite always sets?
Co-authored-by: Felix Arntz <[email protected]>
…est_OD_Optimization' )
I was testing Optimization Detective and I was confused why it wasn't working. Pages which normally had been optimized were being served as if Optimization Detective wasn't even active. It turns out that this is a side effect of #1762 where we prevent any page processing when the REST API for storing URL Metrics is unavailable. Since loopback requests don't work in wp-env (WordPress/gutenberg#20569), neither does the Site Health test for checking whether the REST API is available.
Without the patch in this PR, a plugin can force optimization to apply even when the REST API isn't available via code like the following:
This could be added to the
od-dev-mode
plugin. But this plugin shouldn't have to be installed in order to test Optimization Detective in wp-env.So this PR adds a condition (a7cedce) so that
od_is_rest_api_unavailable()
is checked alongside( wp_get_environment_type() !== 'local' || class_exists( 'Test_OD_Optimization' ) )
. Only if both are true will it short-circuit.Additionally, to assist with helping users understand why Optimization Detective isn't doing anything, this PR includes the reasons for optimization being disabled in the console when
WP_DEBUG
is enabled.