-
Notifications
You must be signed in to change notification settings - Fork 109
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 Test Coverage for Web Worker Offloading Plugin #1871
Open
sarthak-19
wants to merge
7
commits into
WordPress:trunk
Choose a base branch
from
sarthak-19:add/code_coverage_web_worker
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+325
−135
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1c60b11
Add missing test case and @cover annotations for improved code covera…
137992e
Added CodeCoverage Ignore for the relevent lines
caad68e
Refactor code, move functions from hooks.php to helper.php for web-wo…
cb059f3
Refactor code, move functions from hooks.php to helper.php for web-wo…
83ca300
Fix printing of output during test
westonruter 326b970
Revert auto-sizes changes
westonruter 51a3dc8
Eliminte defining constant
westonruter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
plugins/web-worker-offloading/tests/third-party/test-google-site-kit.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
/** | ||
* Test cases for google-site-kit.php in Web Worker Offloading. | ||
* | ||
* @package web-worker-offloading | ||
*/ | ||
class Test_Google_Site_Kit extends WP_UnitTestCase { | ||
/** | ||
* Runs the routine before each test is executed. | ||
*/ | ||
public function set_up(): void { | ||
parent::set_up(); | ||
require_once __DIR__ . '/../../third-party/google-site-kit.php'; | ||
} | ||
|
||
/** | ||
* Test the function that configures WWO for Google Site Kit. | ||
* | ||
* @covers ::plwwo_google_site_kit_configure | ||
*/ | ||
public function test_plwwo_google_site_kit_configure(): void { | ||
$configuration = array(); | ||
$expected_configuration = array( | ||
'globalFns' => array( 'gtag', 'wp_has_consent' ), | ||
'forward' => array( 'dataLayer.push', 'gtag' ), | ||
'mainWindowAccessors' => array( | ||
'_googlesitekitConsentCategoryMap', | ||
'_googlesitekitConsents', | ||
'wp_consent_type', | ||
'wp_fallback_consent_type', | ||
'wp_has_consent', | ||
'waitfor_consent_hook', | ||
), | ||
); | ||
|
||
$result = plwwo_google_site_kit_configure( $configuration ); | ||
|
||
$this->assertEquals( $expected_configuration, $result ); | ||
} | ||
|
||
/** | ||
* Test the function that filters inline script attributes. | ||
* | ||
* @covers ::plwwo_google_site_kit_filter_inline_script_attributes | ||
*/ | ||
public function test_plwwo_google_site_kit_filter_inline_script_attributes(): void { | ||
$attributes = array( 'id' => 'google_gtagjs-js-consent-mode-data-layer' ); | ||
$expected_attributes = array( | ||
'id' => 'google_gtagjs-js-consent-mode-data-layer', | ||
'type' => 'text/partytown', | ||
); | ||
|
||
$result = plwwo_google_site_kit_filter_inline_script_attributes( $attributes ); | ||
|
||
$this->assertEquals( $expected_attributes, $result ); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Since a constant is not removed after a test completes, it's important to run in a separate process.
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.
When trying to run is a separate process, I'm getting error as
Serialization of 'Closure' is not allowed
, and I'm not sure how to resolve this.Attaching error log below :
cc : @westonruter
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 typically see that when
@runInSeparateProcess
is added for a test that has a closure among the data in the data provider. But this test has no data provider, so I'm confused why it is occuring for this test.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.
Ohhkk, so should I keep it as is?
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 tried to various things to get it to work to run in a separate process but it was too messy. There are closures defined in some global variable in WordPress core, so I tried to remove them during the tests, but I still had trouble. We'll just not test that now I guess.
Patch