FSD Frontend System Design

Chapter 4 · Testing

Interview drill

8 questions from this chapter. Answer each one out loud first, then open it to compare.

  1. 4.1"What's your testing strategy for a large frontend?"
    • Name the shape and the ratio, then justify it by CI time and debugging cost, not by dogma.
    • Cover money paths with E2E, everything else lower; add visual and a11y checks as separate gates.
    • State the flake policy — quarantine within a day — because that's what keeps a suite trusted.

    Review 4.1 Testing Overview →

  2. 4.2"Where's the line between a unit and an integration test?"
    • It's the mocking boundary, not the file count — one component with a mocked child is a unit test.
    • I default to mocking only the network (MSW), so the real render, state, and event path stay under test.
    • That makes tests survive refactors, which is the property that decides whether a suite lasts.

    Review 4.2 Unit & Integration Testing →

  3. 4.3"Your E2E suite is flaky. How do you fix it?"
    • Measure first: track per-test failure rate and quarantine anything under 99% within a day.
    • Attack the structural causes — shared data, real third parties, sleep-based waits, animation timing.
    • Then shrink the suite; most flaky E2E suites are covering things that belong two layers down.

    Review 4.3 E2E and Automation Testing →

  4. 4.4"How do you A/B test without hurting performance?"
    • Decide at the edge so the variant ships in the HTML — no flicker, no extra round trip, no layout shift.
    • Keep the payload as one small config object, not two bundles; lazy-load only genuinely divergent code.
    • Add latency and error rate as guardrail metrics, so a winning variant that slows the page still loses.

    Review 4.4 A/B Testing →

  5. 4.5"How do you stop performance regressing over time?"
    • Make it a gate, not a goal: budgets fail CI so no regression merges silently.
    • Cheap deterministic checks (bundle size) on every PR, full Lighthouse on main, RUM alerting in production.
    • Track p75 on real devices — averages hide exactly the users who churn.

    Review 4.5 Performance Testing →

  6. 4.6"Do you practise TDD?"
    • For logic-heavy code and for every bug fix, yes — a bug without a failing test first has no proof it's fixed.
    • For visual and exploratory UI work I build first and test the settled behaviour, because the interface is still moving.
    • The durable benefit isn't coverage, it's that untestable code is usually badly designed code, and TDD surfaces that immediately.

    Review 4.6 Test-Driven Development →

  7. 4.7"How do you test security in a frontend pipeline?"
    • Layer it: secrets at commit, dependencies and SAST on PR, DAST on staging, header assertions as ordinary tests.
    • Gate only on reachable high severity, or the team learns to bypass the gate entirely.
    • Automation finds known patterns; business-logic flaws — like an IDOR on an order id — still need a human.

    Review 4.7 Security Testing →

  8. 4.8"How do you test a component that fetches data?"
    • MSW intercepts at the network layer, so the real fetch, real serialization, and real error branches all run.
    • findBy* for the resolved state, queryBy* to assert the loading state is gone — never sleep.
    • Cover all four states — loading, empty, error, success — since the last three are where production bugs actually live.

    Review 4.8 [BONUS] Testing React Components →