Skip to content

Fix unit tests in WP 7.0-alpha after Script Loader updated to use HTML API to generate SCRIPT tags#2353

Merged
westonruter merged 4 commits into
trunkfrom
fix/od-wp-trunk-snapshot-tests
Jan 15, 2026
Merged

Fix unit tests in WP 7.0-alpha after Script Loader updated to use HTML API to generate SCRIPT tags#2353
westonruter merged 4 commits into
trunkfrom
fix/od-wp-trunk-snapshot-tests

Conversation

@westonruter

Copy link
Copy Markdown
Member

@westonruter westonruter added no milestone PRs that do not have a defined milestone for release [Plugin] Optimization Detective Issues for the Optimization Detective plugin [Plugin] Embed Optimizer Issues for the Embed Optimizer plugin (formerly Auto Sizes) skip changelog PRs that should not be mentioned in changelogs labels Jan 15, 2026
@github-actions

github-actions Bot commented Jan 15, 2026

Copy link
Copy Markdown

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.

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

Co-authored-by: westonruter <westonruter@git.wordpress.org>
Co-authored-by: sirreal <jonsurrell@git.wordpress.org>

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

@codecov

codecov Bot commented Jan 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.17%. Comparing base (7becbba) to head (938a5b6).
⚠️ Report is 5 commits behind head on trunk.

Additional details and impacted files
@@           Coverage Diff           @@
##            trunk    #2353   +/-   ##
=======================================
  Coverage   69.17%   69.17%           
=======================================
  Files          90       90           
  Lines        7708     7708           
=======================================
  Hits         5332     5332           
  Misses       2376     2376           
Flag Coverage Δ
multisite 69.17% <ø> (ø)
single 35.39% <ø> (ø)

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@westonruter westonruter added [Type] Enhancement A suggestion for improvement of an existing feature [Type] Bug An existing feature is broken and removed [Type] Enhancement A suggestion for improvement of an existing feature labels Jan 15, 2026
@sirreal

sirreal commented Jan 15, 2026

Copy link
Copy Markdown
Member

Sorry 😁

Things are working as expected, right? It's a shame assertEqualHTML() wasn't available earlier 😞

@westonruter

Copy link
Copy Markdown
Member Author

It's all good. This is to be expected. I'm hoping to start leveraging assertEqualHTML soon after #2354

@sirreal

sirreal commented Jan 15, 2026

Copy link
Copy Markdown
Member

An alternative is to copy this function and this method for the interim.

If you put it in a trait, you can use it only in the classes that require it and cleanup should be simple.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes unit test failures caused by WordPress 7.0-alpha's Script Loader update that now uses the HTML API to generate SCRIPT tags. The HTML API produces script tags with attributes in a different order than the previous implementation, requiring test expectations to be updated.

Changes:

  • Updated expected HTML strings in web-worker-offloading tests to match new attribute ordering
  • Added attribute normalization logic in test assertions to handle ordering differences
  • Updated optimization-detective regex pattern to accommodate both attribute orderings
  • Refactored embed-optimizer tests to use WP_HTML_Tag_Processor for more robust assertions

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
plugins/web-worker-offloading/tests/test-web-worker-offloading.php Updated expected script tag strings and added normalization functions to sort attributes before comparison
plugins/optimization-detective/tests/class-optimization-detective-test-helpers.php Modified regex pattern to match both possible attribute orderings for script tags
plugins/embed-optimizer/tests/test-hooks.php Replaced string-based assertions with WP_HTML_Tag_Processor for parsing script attributes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread plugins/web-worker-offloading/tests/test-web-worker-offloading.php
Comment thread plugins/web-worker-offloading/tests/test-web-worker-offloading.php
Comment thread plugins/web-worker-offloading/tests/test-web-worker-offloading.php
@westonruter westonruter merged commit 33a9c2d into trunk Jan 15, 2026
34 checks passed
@westonruter westonruter deleted the fix/od-wp-trunk-snapshot-tests branch January 15, 2026 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no milestone PRs that do not have a defined milestone for release [Plugin] Embed Optimizer Issues for the Embed Optimizer plugin (formerly Auto Sizes) [Plugin] Optimization Detective Issues for the Optimization Detective plugin skip changelog PRs that should not be mentioned in changelogs [Type] Bug An existing feature is broken

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants