Tests
| Suite | Command | Needs |
|---|---|---|
| Unit and block validity (Jest) | npm test |
Nothing |
| End-to-end (Playwright) | npm run test:e2e |
npm run build, npm run env -- start |
| PHP integration (PHPUnit) | npm run test:php |
npm run build, composer install, npm run env:test -- start |
Run one file with npm test -- src/blocks/slider/test/loop.test.js (add -t "name"
for one case), or one spec with npm run test:e2e -- test/e2e/layout.spec.js -g "peek".
Block validity
save.js output is the contract every published post was parsed against. If it
changes, existing sliders show as invalid in the editor and their authors face a choice
between losing settings and editing HTML.
src/blocks/test/ registers the real blocks (real block.json, deprecations and
transforms) and runs every configuration in support/fixtures.js through the real
serialize() and parse(). Each must round-trip valid, re-serialize byte for byte,
and match a committed snapshot.
A snapshot failure means published content will stop validating. Never update
snapshots on autopilot. A markup change that is genuinely wanted needs a deprecation in
the block's index.js and a case in compatibility.test.js.
support/fixtures.js is shared: it also builds the kitchen-sink page the end-to-end
tests drive and the bundled patterns. Add a configuration there and it reaches all
three. Run npm run patterns after any change to saved markup; patterns.test.js
fails when the committed patterns drift.
End-to-end
The specs drive Chromium against the kitchen-sink page and find sliders by their accessible names. They cover what unit tests can't: layout, peeking edges, keyboard, autoplay, the editor.
- Locally they run on one worker; CI uses two, then runs
rtl.spec.jsalone, since it switches the site's language. - Editor specs reuse one saved admin session (
test/e2e/support/global-setup.js); don't log in inside a spec. author-save.spec.jscreates its own author account to check that kses leaves a saved slider intact.- Screenshot baselines exist for Linux only and are recorded by CI: dispatch the CI
workflow with
update_snapshots, download the PNGs it uploads and commit them. On other platforms the screenshot tests skip.
PHP
test/php/ runs against a real WordPress in the PHP test site, not mocks: nearly
everything the PHP does is a conversation with WordPress. PHPUnit is pinned to 9.x and
run from vendor/, because WordPress's test case still needs an API PHPUnit 10 removed.
Size budgets
npm run size gzips each compiled asset and compares it with its budget in
package.json (sizeBudget). view.js loads for every visitor to a page with a
slider, so its budget matters most. When an asset legitimately grows, raise its budget
in the same change, to about 10% above the new size.