Skip to content

Testing

Lionel Serrao edited this page Nov 29, 2026 · 1 revision

Testing

Two layers, and both run the same kill switch and restore code the extension uses.

flowchart TB
    subgraph Unit["Unit tests: npm test (52, every CI run)"]
        U1["Fake Flagsmith answers"] --> U2["Hard-to-cause failures:<br/>refused writes, deleted tests,<br/>tests resumed by hand"]
    end
    subgraph Live["Live end-to-end: node e2e.mjs (26)"]
        L1["Your real self-hosted Flagsmith"] --> L2["Throwaway environments,<br/>zz_e2e_ flags and segment"]
        L2 --> L3["Ask Flagsmith what users<br/>are actually served"]
        L3 --> L4["Delete everything it created"]
    end
Loading

Unit tests

cd extension
npm ci
npm test

They use node:test with a scripted fetch, so no Flagsmith is needed. What they cover:

  • request shapes for normal and versioned environments;
  • the kill switch carrying on past refused writes;
  • A/B tests found from their hidden segments;
  • restore cases where someone changed things by hand;
  • Markdown escaping in hovers;
  • the scanner's call shapes, comments and typos;
  • alert-rule YAML, incident summaries and change timing.

Live end-to-end tests

cd extension; npm run compile; cd ../demo-app
$env:FLAGSMITH_API_KEY="<organisation API key>"   # export FLAGSMITH_API_KEY=... on macOS/Linux
node e2e.mjs                 # or: node e2e.mjs "My project"

It creates two throwaway environments (one with v2 versioning) plus zz_e2e_ flags and a segment, runs the cases, then deletes everything it created. Your own flags are never written to. Results print to the terminal and go to e2e-results.json. If a run is interrupted, node e2e.mjs --cleanup removes leftovers.

Cases What they prove
C1–C8, V1–V8 Kill switch and restore on a normal and a versioned environment: everyone is served off, values and multivariate splits survive, restore copes with hand edits and deleted overrides
H1 "Hide disabled flags" environments
X0–X4 A/B tests: paused and traffic taken without a 409, nobody in the test gets the flag, restore copes with a test resumed or completed by hand
A1 Alerts without an environment are stored project-wide
N1, N2 A wrong key and an unreachable address give readable errors

The cases check what Flagsmith serves to users (a transient identity per check), not only what the API answers. That's what caught the problems fixed in 0.7.2.

Adding a test

  • Pure logic or request shapes: add to extension/src/test/*.test.ts. Use the flagsmith((call) => …) helper in incidentOps.test.ts to script answers.
  • Anything that writes to Flagsmith: add a check('ID', 'what it proves', async () => { … }) to demo-app/e2e.mjs. Create what you need with the zz_e2e_ prefix, or inside the throwaway environments, so clean-up finds it.

Clone this wiki locally