Module Federation, How do we create unit tests for distributed code?!

Zack Jackson
4 min readApr 23, 2021

The curious case of Module Federation and how do we write tests for federated applications.

If you haven't heard by now — Module Federation is a way to simply import() other modules/files between independently compiled and deployed bundles at runtime.

Possibilities are endless, especially after working with it for over a year. Before there was even an npm release, it was in production, installing directly from a branch on GitHub. It’s immensely more powerful then most think

With this new at-runtime orchestration and code sharing, a big question loomed.

How on earth will I test this?

Over a year later, I think I've found a potential solution…

Federated Unit Tests

If i can federate my features, why not federate them into unit tests as well?

Let us take an example:

I have a file with a form on it. It imports a federated button.

import React,{Suspense} from "react";
import lazy from 'react-lazy-ssr';
const Button = lazy(
()=>import('federated/Button'),{chunkId:"federated/Button"}
)
// this will

--

--

Zack Jackson
Zack Jackson

Written by Zack Jackson

Infra Architect @ ByteDance. Creator of Module Federation. Specializing in Bundler and Javascript Orchestration at scale.

Responses (1)