Testing
Tests run your template in the real application (the preview runtime) and a headless Chrome/Edge/Chromium, once per dataset.
node sdk test [dir]
--dataset normal,empty # datasets (default: normal, single-store, empty, edge-cases, no-stores, stores-paused)
--quick # normal dataset only
--no-browser # files and rendering suites only
--filter checkout # only matching checks
--json
Results are saved in .template-sdk/test-results/report.json with screenshots (desktop and phone per dataset).
Built-in checks
Files
- template.json is valid JSON
- Template loads in the application's template engine
- Validation has no errors
Rendering
- The preview starts with this template
- Referenced images are served by the application
- Stylesheet and script are served
- [dataset] Page renders
Browser
- [dataset] Page runs without JavaScript errors
- [dataset] script.js runs
- [dataset] Storefront engine starts
- [dataset] Several stores: store chooser shown, no products yet
- [dataset] Choosing a store loads its catalogue
- [dataset] Stores closed: no products, paused message
- [dataset] Empty catalogue: product blocks stay empty/hidden
- [dataset] Catalogue shown without choosing a store
- [dataset] Route "…" shows #section-…
- [dataset] Products page lists products
- [dataset] Product page opens
- [dataset] Add to cart updates the cart
- [dataset] Checkout opens at the first step
- [dataset] Phone width (390 px): no sideways scrolling
Your tests
Files tests/*.test.js export a function that registers tests:
module.exports = function (t) {
t.test('name', async ({ page, http, url, dataset, expect, contract, project }) => {
// ...
}, { dataset: 'single-store', viewport: { width: 390, height: 844, mobile: true }, browser: true });
};
| Argument | Description |
|---|---|
page | a browser page (null with browser: false): setViewport(width, height, mobile) goto(u, opts) reload(opts) idle(quiet) evaluate(expr, arg) exists(sel) visible(sel) count(sel) text(sel) click(sel) fill(sel, value) waitFor(selOrFn, timeout) screenshot(file, opts) close() |
http(path, init) | fetch against the preview server |
url | the preview server URL |
dataset | the dataset: id, name, summary (storeName, stores, products, coupons, customers, storeMode…) |
expect(value) | toBe toEqual toBeTruthy toBeFalsy toContain toMatch toBeGreaterThan toBeGreaterThanOrEqual toBeLessThan toHaveLength and .not |
contract | the discovered contract |
project | the project (read files) |
Example
module.exports = function (t) {
// <title> carries the store name (with a single active store, that store's own name)
t.test('the server puts the store name in the title', async ({ http, dataset, expect }) => {
const res = await http('/');
expect(res.status).toBe(200);
const html = await res.text();
const title = (/<title>([^<]*)<\\/title>/.exec(html) || [])[1] || '';
expect(title).toContain(dataset.summary.storeName.replace(/&/g, '&'));
}, { dataset: 'single-store', browser: false });
t.test('the page title still names the store in the browser', async ({ page, dataset, expect }) => {
await page.goto('/');
expect(await page.evaluate('document.title')).toContain(dataset.summary.storeName);
}, { dataset: 'single-store' });
};