What a change must prove applies here as everywhere: dev-docs/TESTING.md. This page covers the UI's own suites.
| Suite | Where | Runs with | Command |
|---|---|---|---|
| Unit | packages/core/tests/ |
vitest, happy-dom | npm run test:ui |
| End-to-end | e2e/tests/ |
Playwright, Chromium | npm run test:e2e |
Both commands run from the repository root.
tests/ mirrors src/: a test for src/formulaEditor/keyboardController.ts lives at tests/formulaEditor/keyboard-controller.test.ts. Only formula-builder.test.ts, for the root src/formulaBuilder.ts, sits at the top of tests/. A file covers either one module or one behaviour (tab-commit.test.ts, rich-input-ime.test.ts), is named in kebab-case, and sits in the directory that mirrors the code it exercises. A module can be covered by several behaviour files instead of a file of its own.
tests/helpers/ is a barrel; import it as "../helpers" or "../../helpers", depending on depth. Extend it rather than defining fakes per file.
createEditorHarness(options?)returns{ host, popupCtx, adapter, editor, destroy }: aFormulaEditorwith a defaultTestGridAdapter. Always calldestroy().TestGridAdapteris a fullIGridAdapterfake. It records.highlightsand fires picks through.pickCell()and.pickRange().makeBarAdapter(overrides?)fakes the formula-bar lifecycle, withfire*handles.- DOM helpers:
typeInto,press,keyUp,blurEditor,focusEditor,requireTextarea,nextFrame,sel.
- One
describeper public surface, oneitper behaviour. - Test names read as sentences:
it("converts simple '// note' to '+ N(\"note\")'"). - No
!non-null assertions; guard and throw instead. - Tests are typechecked: the core's
typecheckscript also runstsc -p tsconfig.test.jsonoversrc/andtests/. - happy-dom geometry is all zeros. Stub
getBoundingClientRectandgetClientRectswhere positioning matters, aspopup-controller.test.tsandscroll-anchor.test.tsdo.
npm run test:ui -- <file or name pattern>- Write the failing test, naming the input and the expected output.
- Run it and confirm it fails for the right reason.
- Implement the minimal code.
- Run it and confirm it passes.
When adding tests for existing code, break the code under test on purpose, confirm the new test fails, then restore it.
A basic integration smoke tier: it proves the editor works in a real page. Behaviour (keyboard matrices, popup state, tokenization, highlight geometry) is owned by the unit suite; do not assert it here. What runs, and how to add a demo route, is in e2e/COVERAGE.md; update it in the same commit as any spec change.
The Playwright config starts the demo server itself. The demo resolves hyperformula from this workspace, so build the engine first:
npm run bundle-all
npm run test:e2ePlaywright needs Chromium installed once: npm exec --workspace=e2e -- playwright install chromium.
Conventions:
- Tests touch only the shared
.hfe-*DOM and the demo's#result. Nowindow.*hooks. - Prefer role-based selectors, then
data-testid, then classes. Avoid CSS chains. await expect(...)for every assertion.