How Adresskoll is tested
Adresskoll is an address register with statistics on residents, move-ins, cars and companies for housing co-ops and villa areas. It handles sensitive information, so the test strategy starts from what must never go wrong, not from what is easy to test. This page is the method. The code and the data stay private.
Risk map
Risks are ranked by the harm if they happen, and each one has a named place in the suite where it is checked.
- Sensitive details shown to the wrong visitor. Surnames, registration numbers, villa house numbers and photos must be masked on the server for anyone who is not logged in. Checked by unit and API tests on the masking rules and by E2E tests that log in and out as a visitor.
- Wrong person matches. The same person can appear in several sources with name variants. A bad merge silently mixes two people. Checked by unit tests for every matching level, including a mother and daughter with the same name.
- Importers that stop reading correctly. The sources change their markup without notice. Checked by running the real import functions against saved HTML fixtures, never against live sites.
- Tests touching production data. Every test runs against an in-memory database, a temporary photo directory and a mocked LinkedIn. Any other outgoing request fails the test.
- Layout that breaks on a phone. Grids, charts and dialogs are covered by screenshot baselines on mobile and desktop, and one spec opens every view at 390 px and fails on horizontal scroll.
The test pyramid
Most checks sit low, where they are fast and exact. A browser is used only for what a browser is needed for. Each layer links to the risks from the map above that it guards against.
-
Visual baselines 118 screenshots
Mobile at 390 px and desktop at 1280 px for layouts that DOM assertions do not catch. Fonts are forced to the same files on every machine, and dates are frozen, so the images do not drift.
Guards against
-
End-to-end tests 34 files in Chromium
One file per view, because each file starts its own server and database. Logic that already has a unit test is only exercised in the browser as a flow that proves the wiring.
Guards against
-
Unit and API tests 140 files, about 1,400 test cases
Plain
node:testwith an in-memory SQLite database. Logic such as masking, matching and statistics is kept free of I/O so it can be tested without a server. Routes are tested against the real app on a free port. Coverage thresholds fail the build if they drop.Guards against
CI on every pull request: types, lint, formatting and coverage in one job, the full E2E suite in another
Bugs that became tests
The rule is that every bug fix ships with a test that fails without it. Three from the history:
- Names written as “Surname, First name” were masked after the comma instead of before it. Fixed, and pinned with a unit test.
- Board members were visible to logged-out visitors. Masked, with a test per access level.
- Several views overflowed sideways on a phone and had tap targets that were too small. The all-views overflow spec was added.
Flakiness and run time
Flakiness is treated as a bug in the test. It is prevented by rule where possible and fixed when it still shows up.
-
The linter rejects
it.only,.skip,setTimeout,Math.random()and direct assignment of the database path in tests. Waiting is done with awaitFor(condition)helper, and time windows use a mocked clock. - Every E2E test fails on a console error, a page error, a CSP violation or a blocked external request. No spec has to remember to check.
- Flaky tests that did appear were fixed at the cause: the dogs tab test that did not wait for its loading placeholder, the landing search and address-delete tests, and a house-number test. None was quarantined or retried away.
- CI runs type checking, lint, formatting and coverage in one job and the full E2E suite in another, on every pull request. Recent runs finish in under two minutes.
A test-code excerpt
The hook that makes the “zero console errors” rule automatic. It runs after every E2E test, so a new test inherits it for free. Names are translated and simplified.
// Runs after every E2E test in the file.
afterEach(() => {
if (!activeHarness) return;
const { blockedRequests, problems } = activeHarness;
// Empty the lists so an error only fails the test that caused it.
const blocked = blockedRequests.splice(0);
const errors = problems.splice(0);
assert.deepEqual(blocked, [], 'External requests were blocked');
assert.deepEqual(errors, [], 'Console or page errors during the test');
});