Testing and quality gates
Scripts
Section titled “Scripts”| Command | Does |
|---|---|
npm run dev | Build the engine once, then start the theme dev server (Turbopack). |
npm run dev:engine | Rebuild the engine on change. Run it beside npm run dev when editing packages/engine: the theme reads the engine’s build output, not its source. |
npm run build | Production build of the theme. |
npm run build -w @magenxcommerce/engine | Build the engine. Needed before a theme build, npm test, or a publish. |
npm run start | Run the production build. |
npm run lint | ESLint over engine and theme. |
npm run type-check | Strict TypeScript over both workspaces, app and test projects. |
npm test | Vitest unit suites. |
npm run test:coverage | The same with V8 coverage and per-file thresholds. |
npm run eval:assistant | Live evals for the shopper assistant against a fake store. Needs ANTHROPIC_API_KEY; not part of npm test. See the assistant guide. |
npm run bundle-budget | First-load JavaScript per route against the committed budget. |
npm run check:engine-pack | Every engine import the theme uses resolves to a file in the engine’s npm package. |
npm run check:engine-esm | Every exported engine module loads under plain Node ESM. |
npm run check:overrides | src/custom/ overrides still match the upstream files they copied. |
npm run sync:stores | Refresh the store-view snapshot from Magento. |
npm run format | Prettier over the monorepo. |
Unit tests
Section titled “Unit tests”Vitest runs two projects (vitest.config.ts):
- node: pure logic. The
/api/graphqlallowlist and Turnstile, checkout helpers (addresses, payment redirect checks, Stripe amounts), the UCP and ACP surfaces, engine money math and HTML sanitising, and the schema drift test that checks every engine query against the companion modules’ schemas. - dom: React under jsdom with Testing Library: the cart, wishlist and auth contexts, the checkout step components (fields, payment and review steps, the Stripe and Mollie card forms), the order confirmation and Mollie return pages, and storefront components such as the product card, header navigation and the assistant panel.
Build the engine before npm test: the tests import its build output.
Coverage has no global threshold on purpose: one number over the whole codebase is either arbitrary or invites filler tests. vitest.config.ts sets per-file thresholds on the code every order passes through (the three contexts, checkout helpers, the order confirmation page, the proxy allowlist and Turnstile). Raise them when a suite covers more; never lower one to pass a PR.
Bundle budget
Section titled “Bundle budget”npm run bundle-budget measures the gzipped first-load JavaScript of every prerendered route against scripts/bundle-budget.json, with 3% tolerance. It keeps the performance structure (deferred cart start-up, lazily loaded payment forms) from eroding unnoticed. Record an intended increase with node scripts/bundle-budget.mjs --update, so it shows up as a reviewable diff.
The PR gate
Section titled “The PR gate”Every pull request runs, in order:
The override drift check runs early on purpose: it is a few file hashes, and a stale override makes every slower step after it wasted. Changes that only touch docs/ skip this gate and run the docs build instead.
Load tests
Section titled “Load tests”tests/load/browse-browser.js is a k6 script, run by hand. A real headless Chromium walks home, category, product and search pages. It measures JavaScript, sub-resources, the browser cache on repeat views, and Core Web Vitals. See tests/load/README.md for how to run it.
Not covered yet
Section titled “Not covered yet”- End-to-end browser tests. They need a staging backend.
- The checkout page itself. The step components have tests, but
checkout/page.tsx, which wires the steps together, does not. Nor do the shipping step, address fields, pickup selector and order summary. - PHPUnit for most companion modules. A few modules, such as Cron Manager, have PHPUnit suites in their own repositories and run them in their own CI. Most have none, and the storefront’s PR gate runs none of them.
- Pre-commit hooks. Lint, type-check and tests run only in the PR gate.