For the complete documentation index, see llms.txt. This page is also available as Markdown.

Micro-frontends

Applies to: pages composed of several separately built and deployed front ends: webpack or Rspack Module Federation, single-spa, import maps, iframes, or independently deployed script bundles.

The rule

Each separately built front end is its own SeaLights build: its own config (its own application name), its own scan --instrumentForBrowsers, its own instrumented output. On the page, the Browser Agent runs one instance per build session and reports each build's coverage separately. Give all front ends that are tested together the same lab ID.

 shell (host)     config --appName shell      scan --instrumentForBrowsers --labId qa-env ─┐
 orders (remote)  config --appName orders     scan --instrumentForBrowsers --labId qa-env  ├─► one page, three agents, lab "qa-env"
 billing (remote) config --appName billing    scan --instrumentForBrowsers --labId qa-env ─┘

Example: Module Federation host and remote

Run in each repository (or each package of a monorepo), after its own build:

# in the remote's pipeline
printf '%s' "$SEALIGHTS_AGENT_TOKEN" > sltoken.txt
npx slnodejs config --tokenFile sltoken.txt --appName orders-mfe \
  --branchName "$BRANCH_NAME" --buildName "$BUILD_NUMBER"
npx slnodejs scan --tokenFile sltoken.txt --buildSessionIdFile buildSessionId \
  --scanDir dist --scmType git \
  --instrumentForBrowsers --outputPath sl_dist --labId qa-env
# deploy sl_dist as the remote's files in the test environment

# in the host's pipeline: the same commands with --appName shell

Add --es6Modules for front ends whose output is ES modules.

Notes

Topic
What to do

Shared dependencies (React, Angular, Vue singletons)

They are skipped by default inside every bundle; no extra setup.

One front end is instrumented, another is not

Coverage is reported only for the instrumented one. That is fine during a gradual rollout.

Same build loaded twice

A second configuration with a build session ID that is already running on the page is ignored.

Context propagation to back ends

If any front end on the page is instrumented with --enableOpenTelemetry, propagation applies to every request from the page. With several --allowCORS values, the last build that sets one wins, so give every front end the same list. See Context Propagation.

Several environments

Instrument each front end once per environment with that environment's --labId, or set window["__sl.labId__"] in the host page, which applies to every build on the page. See Configuration → Lab ID.

One release made of all front ends

To report them as one release, create an integration build with the front ends as components.

Front ends in iframes

Each iframe is its own page with its own agent instances; the same rules apply.

Check it

On a page that loads several front ends, the console shows one has been loaded line per build, and window.$SealightsAgent.dumpSlMappings() returns one mapping per build. See Check that it works.

Last updated

Was this helpful?