Testing
This section contains checking and testing strategies, processes, and test pages used by website tests and deployed live checks.
This section is under construction.
Test categories
Test scripts in package.json are grouped by naming
conventions that also drive their auto-discovery:
test:baseruns the core checks (equivalent tocheck). In CI these are covered by the dedicated check workflows rather than a single job.- Compound
test:<word>-<word>scripts are auto-discovered and run together bytest:compound-tests(and thereforetest:all). Giving a script a compound name is how you opt it into that group, even when it is otherwise a single check (for exampletest:local-tools). test:publicruns the checks undertests/public/(any*.test.mjsthere). They read the builtpublic/site, so they need a priornpm run buildand skip whenpublic/is absent. Add a check by dropping a*.test.mjsinto that folder; follow the convention of skipping whenpublic/is missing. These are deliberately kept out oftest:compound-tests(which does not build) and instead run in CI in a job that reuses an existing build artifact.test:*:livescripts are optional checks against a deployed, live site.
Test assertions
Goal
When a test fails, the output should make it obvious what was being checked and show a clear diff between actual and expected values, without long hand-written messages.
For example, avoid:
assert.ok(a === b, `expected ${a} to be ${b}`);
Instead favor:
assert.strictEqual(status, expectedStatus, 'HTTP status');
Guidance
The points below use Node’s built-in node:test runner and assert API because
that is what several of our test suites use. The same ideas apply in other test
frameworks: prefer assertions that produce tight diffs, keep failure context
short and specific, and extract shared helpers when the same check repeats.
- Prefer
assert.strictEqualoverassert.equalfor primitive checks where strictness and diff quality matter. - Add a short third argument as context, for example
HTTP status,Content-Type,Location,Request body. - Use
assert.matchwhen a regular expression can capture the intent more clearly thanincludesor chainedoklogic. - Put shared assertion helpers in a module imported by the test suites that use
them, colocated with those tests instead of copy-pasted across files. Other
small, test-only utilities can live in the same module when it stays focused
(for example
assertVaryIncludesAcceptinnetlify/edge-functions/lib/test-helpers.ts).