Skip to main content

Published

How feature flag coverage works

In brief: The fixture records each flag arm a test ran, from the browser, the backend or the test itself. TestChimp joins those records to the story behind each test and to your provider's flag catalog, then marks each arm tested, tested (forced), untested or ignored.

TestChimp records which flag values each test execution ran, attributes those executions to user stories through the tests' scenario links, and compares the result with the list of flags and arms your provider reports.

Concepts​

  • Flag: identified by its key in your provider, such as new-checkout. Flags seen in tests but not in any connected provider are kept as observed-only and shown as Catalog unknown.
  • Arm: one possible value of a flag.
    • Boolean flags have the arms true and false.
    • Multivariate flags use the provider's variation: the LaunchDarkly variation value, the PostHog variant key, or the Statsig experiment group.
    • JSON or number flags with no named variations use the JSON value itself.
  • Catalog: the flags and arms synced from your provider, for the provider environment your tests run against.
  • Evaluation record: "during test execution E, flag F returned arm V, from source S".
  • Source: where the evaluation was seen.
    • Frontend (FE): evaluated in the browser page under test.
    • Backend (BE): evaluated in the backend while it served a request from the test, and echoed back in a response header.
    • Forced: the test set the value itself, by mocking the provider's response or by calling testchimp.flags.force().

From a story to its flag arms​

Feature flag coverage reuses the lineage that requirement coverage uses:

  1. Stories in scope are resolved the way requirement coverage resolves them: the plans folder you pick, then each story's scenarios, then the tests linked to those scenarios.
  2. Executions are the runs of those tests on the selected branch and environment within the time window (the last 30 days by default). With a release selected, TestChimp uses the release's scope and executions instead.
  3. Evaluation records for those executions give the flags and arms each test ran.
  4. Arms per flag are the catalog arms for the provider environment, plus any arm a test ran that the catalog does not list. Those extra arms carry a "not in provider" note, which usually means a stale catalog or a value mismatch.

Which flags count for a story​

A flag is relevant to a story when:

  • Auto: a test linked to the story evaluated it in an in-scope execution; or
  • Pinned: someone pinned the flag to the story, even if no test has evaluated it yet. All its arms then show as untested until a test runs them.

A flag someone excluded from a story is hidden, behind the Show excluded flags toggle. Pin and exclude from the flag menu on the story, or with the set-story-feature-flag-relevance tool. A flag evaluated only by tests linked to another story never appears under this one.

Arm statuses​

StatusMeaning
TestedAt least one in-scope execution of a linked test recorded this arm from the frontend or backend.
Tested (forced)Every record for this arm is forced: the test set the value itself. The arm ran, but not through your provider's real targeting.
UntestedThe arm is in the catalog for a relevant flag, and no in-scope execution recorded it.
IgnoredSomeone ignored this gap. It counts as neither covered nor uncovered in the totals.

Failed executions count: the arm ran. If the latest execution that covered an arm failed, the test chip shows a warning icon. Archived flags are still shown, marked archived.

Totals count each story, flag and arm once per story, so 3 of 4 flag arms tested means the same thing at story, folder and release level.

How capture works​

Frontend​

The @testchimp/playwright fixture adds a small window.__TESTCHIMP_FLAGS__ buffer to every page in the test's browser context, popups included. Your app reports evaluations through @testchimp/flags/web, which calls that buffer. The hooks plug into the OpenFeature web SDK, the LaunchDarkly JS client and PostHog JS.

Backend​

If your backend evaluates flags, @testchimp/flags/server collects every evaluation made while handling a request and returns them in one x-testchimp-flags response header. It runs only when the process has TESTCHIMP_FLAG_ECHO=1. The fixture reads that header on every browser response and every response to Playwright's request fixture, and records the entries as backend evaluations.

No request header is involved. The fixture attributes each response to the test whose context made the request, so tests running in parallel workers against the same backend each get only their own flags. The fixture reads headers through Playwright, so your app needs no CORS change.

Forced values​

When a test mocks a known provider endpoint with route.fulfill, the fixture records every flag in the mocked payload as forced. It recognises the LaunchDarkly client evaluation endpoints, the PostHog /decide and /flags endpoints, and the Statsig /v1/initialize endpoint. Tests that pin a value some other way (a query parameter, a cookie, local storage) can call testchimp.flags.force(flagKey, variant).

Flush​

The fixture aggregates records per test and sends them when the test ends, with the same test identity as API capture. If a test recorded nothing, nothing is sent. A failed upload logs a warning and never fails the test.

Production safety​

  • @testchimp/flags/web does nothing when window.__TESTCHIMP_FLAGS__ is absent, and that global only exists when the TestChimp fixture injected it. In production the hooks cost a property check.
  • @testchimp/flags/server does nothing unless TESTCHIMP_FLAG_ECHO=1 is set. With it unset, no header is added, no network call is made, and nothing is thrown. Set it in test environments only, never in production.
  • Neither package makes network calls to TestChimp. The fixture does the upload from the test runner.

Limits​

  • Backend hooks are Node only in this version. Other languages can implement the header contract directly.
  • Only the backend that answers the request. Flags evaluated in services behind it, queue consumers, cron jobs or background workers are not captured.
  • No combinations. Each flag's arms are counted on their own, not as combinations with other flags.
  • Backend-only flags need echo. A flag evaluated only in the backend, with TESTCHIMP_FLAG_ECHO unset, shows as untested.
  • Statsig: there are no Statsig SDK hooks yet. Statsig values reach TestChimp through forced capture of a mocked initialize call, through OpenFeature if you use Statsig as an OpenFeature provider, or through reportFlag.
  • Forced is not targeting. A forced arm proves the code path ran with that value. It does not prove your provider serves that value to the right users.

FAQ

What is a flag arm?

One possible value of a flag: true or false for a boolean flag, or one variation or variant for a multivariate flag.

What does Tested (forced) mean?

Every record for that arm came from the test setting the value itself, by mocking the provider response or calling testchimp.flags.force(). The code path ran, but not through real targeting.

Do failed test runs count?

Yes. The arm ran. If the latest covering execution failed, the test chip shows a warning icon.

Which backend flags are captured?

Flags evaluated in the Node backend that answers the test request, with TESTCHIMP_FLAG_ECHO=1 set. Services behind it, queues and background jobs are not captured.