Opened 3 years ago
Last modified 4 days ago
#59644 new task (blessed)
Migrate JavaScript unit tests away from QUnit
| Reported by: | swissspidy | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | Build/Test Tools | Version: | |
| Severity: | normal | Keywords: | needs-patch close |
| Cc: | Focuses: |
Description
The QUnit tests really haven't evolved or expanded in recent years.
Alternatively, Gutenberg has a well developed test library based on Jest, and exports all of the config as a package we could use. In the interest of standardising, I suggest migrating our existing QUnit tests to work in Jest instead.
This will make it easier to contribute to these tests as well, plus it allows us to remove the last remaining usage of Puppeteer, as it turns out the QUnit tests run with that on CI. See https://core.trac.wordpress.org/ticket/59517#comment:13
They don't really need a headless browser though, Jest + jsdom should suffice.
Previously mentioned in #37117
Change History (4)
#1
@
16 months ago
- Summary Migrate QUnit tests to Jest → Migrate JavaScript unit tests away from QUnit
- Type defect (bug) → task (blessed)
#2
@
3 weeks ago
I quite like the QUnit tests. They're fast, simple, and basic. I don't think we do this now, but I've considered several times how interesting it would be to use QUnit tests with a WordPress backend to test behaviors against a browser. This would be especially interesting for things like the HTML API where the goal is to implement a standard and browsers are a good testing oracle.
I'm not attempting to block this work, just providing a perspective.
#3
@
2 weeks ago
Status update, tested against trunk at [64680]:
The main motivation for this ticket, removing the last Puppeteer usage, was resolved in [62411] (#64894). tests/qunit/qunit.js is now a Playwright spec that loads each QUnit HTML harness in headless Chrome and fails if any assertion fails. puppeteer is no longer a direct dependency; puppeteer-core remains only as a transitive dependency of @wordpress/scripts and lighthouse.
I ran the suite locally on Node 24.18 (per .nvmrc):
node_modules/.bin/grunt build node_modules/.bin/grunt copy:qunit CI=1 node_modules/.bin/playwright test --config tests/qunit/playwright.config.js --reporter=list
(CI=1 makes the config use the system Chrome channel instead of a downloaded browser; --reporter=list overrides the github reporter that CI=1 otherwise selects.)
Result: 704/704 assertions pass for both index.html (source) and compiled.html (built output), about 10 seconds in total.
So what's left here is purely a tooling choice. Some points to weigh between keeping QUnit (now on Playwright), moving to Jest + jsdom, or rewriting as Playwright tests:
- jsdom is not a real browser. That matters for tests like
wp-emoji, and for the idea in comment:2 of using the browser as a testing oracle for the HTML API. - The
compiled.htmlrun tests the built, minified scripts. A migration should keep that coverage. tests/qunit/index.htmlis one large harness (~160 script includes plus inline templates and fixtures). A Jest migration would need those fixtures split up per test file, so it's a real rewrite rather than an assertion swap, especially for the customizer tests.
@johnbillion, is the Playwright migration you mentioned in comment:1 still in progress? If there's agreement on a direction, I'm happy to put up a proof-of-concept PR migrating one small, self-contained module (e.g. shortcode or word-count) so we can compare before committing to the full suite.
#4
@
4 days ago
- Keywords close added
I am -1 on this.
The original reason why the directory name of "qunit" was chosen over "javascript" is that it left open the possibility of adding new tools without the requirement of changing all the existing tests. Migrating the tests from one framework to another creates completely unnecessary churn.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
I think we should switch from QUnit to Playwright, that way we're using the same tool for e2e tests, visual regression tests, performance tests, and JavaScript unit tests. I'm seeing good initial results getting Claude Code to migrate the tests over. I'll carry on and see if I can get it into a good state.