Skip to content
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
wants to merge 4 commits into
base: trunk
Choose a base branch
from

Conversation

sarthak-19
Copy link
Contributor

@sarthak-19 sarthak-19 commented Feb 14, 2025

Summary

This is part of #1789:

  • Ignore Coverage for Non-Critical Code Blocks
  • Add Missing @covers Annotations
  • Add Missing Tests
Before : 28.00% ⚠️ After: 99.00% ✅
image  image

cc : @westonruter

Copy link

codecov bot commented Feb 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.11%. Comparing base (d94977f) to head (cb059f3).
Report is 135 commits behind head on trunk.

Additional details and impacted files
@@            Coverage Diff             @@
##            trunk    #1871      +/-   ##
==========================================
+ Coverage   65.89%   68.11%   +2.22%     
==========================================
  Files          88       86       -2     
  Lines        6878     6976      +98     
==========================================
+ Hits         4532     4752     +220     
+ Misses       2346     2224     -122     
Flag Coverage Δ
multisite 68.11% <100.00%> (+2.22%) ⬆️
single 37.84% <2.32%> (-0.75%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

/**
* Test the function that loads third party plugin integrations.
*
* @covers ::plwwo_load_third_party_integrations
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @covers ::plwwo_load_third_party_integrations
* @covers ::plwwo_load_third_party_integrations
* @runInSeparateProcess

Since a constant is not removed after a test completes, it's important to run in a separate process.

Copy link
Contributor Author

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 :

Runtime:       PHP 8.2.27 with Xdebug 3.4.1
Configuration: /var/www/html/wp-content/plugins/performance/phpunit.xml.dist

..................<script id="web-worker-offloading-js-before">
window.partytown = {...(window.partytown || {}), ...{"lib":"\/wp-content\/plugins\/performance\/plugins\/web-worker-offloading\/build\/"}};
</script>
<script id="web-worker-offloading-js-after">
const t={preserveBehavior:!1},e=e=>{if("string"==typeof e)return[e,t];const[n,r=t]=e;return[n,{...t,...r}]},n=Object.freeze((t=>{const e=new Set;let n=[];do{Object.getOwnPropertyNames(n).forEach((t=>{"function"==typeof n[t]&&e.add(t)}))}while((n=Object.getPrototypeOf(n))!==Object.prototype);return Array.from(e)})());!function(t,r,o,i,a,s,c,d,l,p,u=t,f){function h(){f||(f=1,"/"==(c=(s.lib||"/~partytown/")+(s.debug?"debug/":""))[0]&&(l=r.querySelectorAll('script[type="text/partytown"]'),i!=t?i.dispatchEvent(new CustomEvent("pt1",{detail:t})):(d=setTimeout(v,1e4),r.addEventListener("pt0",w),a?y(1):o.serviceWorker?o.serviceWorker.register(c+(s.swPath||"partytown-sw.js"),{scope:c}).then((function(t){t.active?y():t.installing&&t.installing.addEventListener("statechange",(function(t){"activated"==t.target.state&&y()}))}),console.error):v())))}function y(e){p=r.createElement(e?"script":"iframe"),t._pttab=Date.now(),e||(p.style.display="block",p.style.width="0",p.style.height="0",p.style.border="0",p.style.visibility="hidden",p.setAttribute("aria-hidden",!0)),p.src=c+"partytown-"+(e?"atomics.js?v=0.10.2":"sandbox-sw.html?"+t._pttab),r.querySelector(s.sandboxParent||"body").appendChild(p)}function v(n,o){for(w(),i==t&&(s.forward||[]).map((function(n){const[r]=e(n);delete t[r.split(".")[0]]})),n=0;n<l.length;n++)(o=r.createElement("script")).innerHTML=l[n].innerHTML,o.nonce=s.nonce,r.head.appendChild(o);p&&p.parentNode.removeChild(p)}function w(){clearTimeout(d)}s=t.partytown||{},i==t&&(s.forward||[]).map((function(r){const[o,{preserveBehavior:i}]=e(r);u=t,o.split(".").map((function(e,r,o){var a;u=u[o[r]]=r+1<o.length?u[o[r]]||(a=o[r+1],n.includes(a)?[]:{}):(()=>{let e=null;if(i){const{methodOrProperty:n,thisObject:r}=((t,e)=>{let n=t;for(let t=0;t<e.length-1;t+=1)n=n[e[t]];return{thisObject:n,methodOrProperty:e.length>0?n[e[e.length-1]]:void 0}})(t,o);"function"==typeof n&&(e=(...t)=>n.apply(r,...t))}return function(){let n;return e&&(n=e(arguments)),(t._ptf=t._ptf||[]).push(o,arguments),n}})()}))})),"complete"==r.readyState?h():(t.addEventListener("DOMContentLoaded",h),t.addEventListener("load",h))}(window,document,navigator,top,window.crossOriginIsolated);
</script>
<script type="text/partytown" src="https://example.com/test-script.js?ver=1.0.0" id="test-script-js"></script>
Serialization of 'Closure' is not allowed
Script WP_MULTISITE=1 phpunit --exclude-group=ms-excluded handling the test-multisite event returned with error code 2
Script @test-multisite --verbose --testsuite web-worker-offloading was called via test-multisite:web-worker-offloading
✖ Command failed with exit code 2
Command failed with exit code 2

cc : @westonruter

Copy link
Member

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.

Copy link
Contributor Author

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?

@sarthak-19 sarthak-19 marked this pull request as ready for review February 18, 2025 15:11
Copy link

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 props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @sarthak.jaiswal@rtCamp.com.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: sarthak.jaiswal@rtCamp.com.

Co-authored-by: westonruter <westonruter@git.wordpress.org>
Co-authored-by: sarthak-19 <sarthak8858@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants