write-insomnia-test
Writing an Insomnia E2E Test Case
Core rule: reuse before you invent
This repo is strictly layered: tests/*.spec.ts → flows/*.flow.ts → pages/*.page.ts → models/*.ts. Writing a new test case almost never requires new Page/Flow/Model code — it's just composing existing methods in a spec file.
Before writing any code, scan the live framework (see step 3) and confirm, for the domain involved: the Flow's exact method signatures, the Model's exact fields, and the mock server URL to hit. This skill deliberately ships no static API reference — the source is the only source of truth. Do not call a method or pass a field from memory/guesswork — the single most common accuracy failure in this framework is inventing a Flow method or Model field that doesn't actually exist.
Framework facts the code doesn't make obvious
- Fixtures:
dataPath,skipOnboarding,vaultKey/vaultSaltare overridable viatest.extendto seed state before launch. Git Sync specs importtest(and the git helpers) frommisc/git-fixtures, notmisc/fixtures. - Single worker: the suite is serial (enforced in
playwright.config.ts); module-level state inmisc/git-fixtures.ts(currentGitRepo) and the mock servers' shared state depend on it. - Mock servers: started by
playwright.config.ts'swebServer, all loopback-only. Import base URLs from@package/misc/constants, never hardcode a port. TLS variants needpreferencesFlow.set({ validateSSL: false })unless the CA is added viacertificatesFlow; mTLS also needs a client certificate. Toggles on the cloud API mock (_admin/*helpers inmisc/fixtures.ts) must run before the app launches. - Timing: Page/Flow methods already wait for debounced saves to reach disk, so a spec never needs
page.waitForTimeout(). For anything else useexpect.poll/toPasswithDEFAULT_TIMEOUT/ACTION_TIMEOUT/LONG_TIMEOUTfrommisc/constants.ts. - Timeouts inside a retry loop: the outer budget must be larger than the inner step timeouts. A
toPass({ timeout: DEFAULT_TIMEOUT })whose body does a bareclick()/scrollIntoViewIfNeeded()/toBeHidden()with{ timeout: DEFAULT_TIMEOUT }can burn the whole 10s on one attempt (e.g. a virtualized sidebar tree row unmounting mid-click on a slow CI runner), so the loop times out with zero retries. Fix it by giving the outertoPassa bigger existing constant (LONG_TIMEOUT) than the inner steps (DEFAULT_TIMEOUT), not by inventing a new number. Always take timeouts frommisc/constants.ts(DEFAULT_TIMEOUT/ACTION_TIMEOUT/LONG_TIMEOUT/POLL_INTERVAL); only add a constant there when none of them fits. - Page/Flow layering: a Page exposes plain per-field setters and never takes a whole Model (except returning raw data from
get()); the owning Flow holds the Model and dispatches to the setters. - Model construction: use a plain object literal when the constructor takes a single init object;
new <Model>(...)only for positional-arg Models (e.g.Project,Collection,McpClient,Folder,MockServer). - No Flow ≠ no support: some domains have no dedicated Flow (e.g. Command Palette, Runner, Vault Key and Plugins live on
workspaceFlow/preferencesFlow; Konnect and Login/Scratch Pad use a Page directly). Find them by scanning, not by assuming a<domain>Flowexists. - **Imports use the
@package/*alias** (tsconfig.jsonpaths), never relative../../paths — including from specs nested in a fixture directory, so depth never matters. Import order is lint-sorted (faker, then@package/...alphabetical, then@playwright/test). - Step reporting is explicit, not automatic: Flow methods opt in with the
@step()decorator frommisc/step.ts(Pages don't use it). A new Flow method that should appear as a report step needs@step(); specs never writetest.step(...)themselves. - Coverage (
COVERAGE=true) is CI-only; specs never need to know about it.
Prefer Flow methods over direct Page access
When a step can be done through a xxxFlow method, call that — never reach for the equivalent pageManager.xxxPage method just because it's more direct. A Flow method already sequences the right Page calls (and any related field the action implies — e.g. HttpRequestFlow.create() also applying auth/params/headers, not just the URL) in the order the app actually expects; composing a spec straight out of Page calls risks silently skipping or reordering a step the Flow would have handled correctly. This is also why a genuinely new spec almost always destructures a Flow instance first and a Page instance only if step 3 shows the action has no Flow wrapper — never the other way around.
Flow methods are explicit, not overloaded: each distinct action has its own named method (workspaceFlow.createProject() / .openLocalGitFolder() / .cloneGitProject() / .createCollection(), exportFlow.exportCollection() / .exportProject(), workspaceFlow.renameRequest() …) so a call site shows which flow
