-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Improve Test Coverage for Webp-Uploads Plugin #1946
base: trunk
Are you sure you want to change the base?
Improve Test Coverage for Webp-Uploads Plugin #1946
Conversation
I've ignored the cc : @westonruter |
@sarthak-19 good question. I'm not sure how deprecated they are. @adamsilverstein are these on their way out or are they still important? I recall they were recently modified. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## trunk #1946 +/- ##
==========================================
- Coverage 70.99% 64.25% -6.74%
==========================================
Files 85 83 -2
Lines 6958 6933 -25
==========================================
- Hits 4940 4455 -485
- Misses 2018 2478 +460
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
However when I'm generating the coverage report with modified changes in local env. I'm getting 80% coverage.
Any ideas why this might be happening? cc : @westonruter |
I see that too. I guess they can be removed, but they're already ignored from code coverage, so I think we can consider removal in another PR.
Sorry, I don't know. Maybe @ShyamGadde has an idea. |
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.
@sarthak-19 I'm curious about how you were able to generate the coverage reports locally. I tried replicating this on both my local environment and on a private performance repo I set up specifically for testing workflows, but couldn't get it to run.
Taking a closer look at the workflow logs, you can see that the coverage report for the webp-uploads
plugin isn't being generated at all, which explains why the coverage is showing as zero.
*/ | ||
|
||
class Test_WebP_Uploads_Uninstall extends WP_UnitTestCase { | ||
|
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.
The culprit appears to be in the uninstall test for single site - the WP_UNINSTALL_PLUGIN
constant isn't defined, which causes uninstall.php
to exit early:
performance/plugins/webp-uploads/uninstall.php
Lines 9 to 12 in 04f8b04
// If uninstall.php is not called by WordPress, bail. | |
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { | |
exit; | |
} |
This premature exit terminates the entire PHP runtime execution, preventing the coverage report from being generated. Interestingly, the test itself doesn't fail, which can be confusing at first.
A possible fix would be to define the constant in the test class like this:
/** | |
* Runs the routine before setting up all tests. | |
*/ | |
public static function set_up_before_class(): void { | |
parent::set_up_before_class(); | |
// Mock uninstall const. | |
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { | |
define( 'WP_UNINSTALL_PLUGIN', 'Yes' ); | |
} | |
} | |
/** | ||
* Test uninstall on a single site. | ||
*/ | ||
public function test_uninstall_single_site(): void { |
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.
While the above change will solve the issue of the report not generating, there's still a potential problem with multisite tests. Since the single site test will also run and uninstall.php
is included using include_once
, it won't execute again for multisite tests, causing those assertions to fail.
To prevent this issue, you might want to add this check to the single site uninstall test:
public function test_uninstall_single_site(): void { | |
public function test_uninstall_single_site(): void { | |
if ( is_multisite() ) { | |
$this->markTestSkipped( 'This test is for single site only.' ); | |
} | |
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.
Hi @ShyamGadde thank you so much for pointing me in the right direction.
I'm curious about how you were able to generate the coverage reports locally.
I suppose I was just testing for multisite in my local env.
npm run test-php-multisite:auto-sizes -- -- -- --coverage-html=./html-reports
& probably that's why in my local the code coverage was showing up.
Thanks I'll make the necessary changes soon 🙇🏻
Summary
This is part of #1789:
@covers
Annotations