Testing & VerificationBaseline · Widely

Test Fidelity Spectrum: Unit, Component, Browser & E2E

Mental Model

Every test layer trades execution speed for engine fidelity. Pure Node.js unit tests validate state machines in microseconds with fake timers, browser component tests verify CSS layout and ARIA semantics in ~50ms, and narrow E2E suites guard full-stack routing and persistence.

Interactive Simulator

Test Fidelity Spectrum Across Engine Layers

Trace how each test tier trades execution latency for real browser and backend subsystems.

V8 Isolate (1ms)
Blink Layout
Backend HTTP
Step 1 / 3: 1. Unit Tier (V8 Isolate, ~1ms)

Executes pure JS/TS functions and fake timers with zero DOM or browser process overhead.

expect(calculateTax(100, 'FR')).toBe(20);
Internal State / Memory
latencyMs
1
domEngine
none
network
none

Under the Hood

Test runners allocate different OS processes and browser subsystems at each tier, which dictates both runtime cost and which production failures each tier can detect.

  1. Unit Layer (V8 Isolate, 0.1ms-2ms/test): Executes pure reducers, parsers, and state machines with zero DOM overhead; blind to CSS, events, and network serialization.
  2. Simulated Component Layer (JSDOM, 5ms-30ms/test): Mounts framework trees in Node.js; verifies state transitions and ARIA attributes, yet misses box layout and hit-testing.
  3. Browser Component Layer (Headless Frame, 30ms-150ms/test): Renders isolated components inside real Chromium/WebKit without backend servers, catching z-index occlusion, focus traps, and media queries.
  4. End-to-End Layer (Full Stack, 1s-10s/test): Boots real HTTP servers, cookies, and storage across multi-page navigations to verify auth redirects and database writes.
TS
// Route each invariant to the lowest layer that executes the real mechanism
const testMatrix = {
  priceCalculation: 'unit-v8',          // Pure JS math, 0.2ms
  debouncedFilter: 'unit-fake-timers',  // Virtual clock + microtasks, 2ms
  modalFocusTrap: 'browser-component',  // Real Blink layout & inert, 60ms
  stripeCheckout: 'e2e-full-stack',     // Real redirects & cookies, 3500ms
};

Problem Genealogy

  • 2015 (Ice-Cream Cone Anti-Pattern): Teams wrote 70% Selenium E2E suites that took 45+ minutes per PR and flaked on 10% of runs due to network and selector races.
  • 2018 (Testing Trophy & JSDOM Dominance): Shifted suites to JSDOM integration tests, dropping CI time to 2 minutes but letting CSS stacking, scroll, and CORS bugs slip into production.
  • 2024 (Hybrid Browser Component + Thin E2E): Kept pure logic in V8 unit tests, moved UI/layout components to headless browser runners, and capped E2E to critical revenue paths.

Production Pitfalls

Production Pitfall
  • Duplicating Unit Combinatorics in E2E: Testing 40 form-validation edge cases through full-stack browser logins burns 15 minutes of CI compute to exercise a pure regex function.
  • Mocking Everything in E2E: Stubbing auth, routing, and API serialization inside E2E tests collapses E2E fidelity down to a slow component test while keeping the 3-second boot penalty.
When Not to Use
  • When not to use Full-Stack E2E: Never use full-stack E2E tests to verify component styling permutations, pure business math, or exhaustive validation matrices; push those down to unit or browser-component suites where failure feedback takes milliseconds.

Connections & Logical Next Steps

Testing & VerificationTest Fidelity Spectrum: Unit, Component, Browser & E2E
What This Unlocks
Leaf concept