Lesson 8 of 9 · 24m
Testing and Observing a Federated Frontend
Contract tests, consumer-driven expectations, end-to-end smoke paths, and correlated telemetry are the only way to trust independent releases.
A micro-frontend can pass all its unit tests and still break the product because integration assumptions live outside its repository. This is the same lesson backend microservices taught a decade ago: local correctness does not imply system correctness. Federated frontends need contract testing, end-to-end smoke coverage, and observability that crosses team boundaries.
Test the slice in honest isolation
Each remote should run standalone with a development harness that provides its required context:
render(<CheckoutApp session={testSession} featureFlags={{ walletPay: true }}
initialCartId="crt_test" onNavigate={vi.fn()} />);If the remote cannot boot outside production, developers will test against production-shaped luck. The harness is part of the public interface; maintain it like code.
Contract-test the seams
Consumer-driven contracts work well for events and initialization props. A consumer records what it needs; producer CI verifies that the emitted contract still satisfies it.
test("checkout.completed v1 payload remains compatible", () => {
const event = buildCheckoutCompleted(sampleOrder);
expect(event.detail).toMatchObject({version: 1, orderId: expect.any(String),
total: {amount: expect.any(Number), currency: expect.stringMatching(/^[A-Z]{3}$/)}});
});Schema validation with zod, JSON Schema, or TypeScript-generated definitions is better than screenshots of a wiki page.
Keep end-to-end tests small and sharp
Do not re-test every feature through the assembled product. Use a handful of golden paths:
- load
/catalog, search, open a product - add to cart, refresh
/cart, continue to checkout - sign in at the shell boundary and preserve destination
- survive one remote failing while checkout still renders
These tests catch composition, routing, auth, and boot-order failures. Feature behavior belongs in slice-level tests.
Correlate telemetry across boundaries
Attach shared context to logs, traces, and analytics:
const telemetryContext = {shellVersion: "12.6.0", remoteName: "checkout",
remoteVersion: "4.18.2", routePrefix: "/checkout", sessionId: session.id};Without remote version tags, an error spike after deployment is just noise. With them, you can answer the only question that matters: which deployed unit caused this, and who can roll it back?
Monitor user experience, not just JavaScript exceptions
Track chunk-load failures, contract violations, hydration errors, Web Vitals by route prefix, and fallback-render counts. A remote that technically renders but takes six seconds to become interactive is still failing the product.
Field notes
- End-to-end suites that duplicate every slice test become slow and politically impossible to maintain.
- Contract tests should fail in the repository that broke compatibility, not three days later in a centralized QA suite.
- Error boundaries must report which remote and version failed; silent fallbacks hide incidents.
- Synthetic deep-link checks are valuable because federated boot order breaks refresh behavior first.
Was this lesson helpful?