Published
LaunchDarkly
In brief: Give TestChimp a read-only LaunchDarkly API access token and your project key, then pick the environment your tests run against. Sync reads flags, variations and the default rule rollout for that environment.
The LaunchDarkly integration reads the flags of one LaunchDarkly project, so feature flag coverage can list every variation and show the ones no test ran.
What you need
- A LaunchDarkly API access token with read-only access. Create it under Organization settings → Authorization → Access tokens. Use a service token so it is not tied to a person, and give it the built-in Reader role, or a custom role that can only read the project.
- The project key of the LaunchDarkly project your app uses. It is shown in the project's settings.
TestChimp never writes to LaunchDarkly, so the token needs no write permissions.
Configure TestChimp
An org admin opens Project settings → Integrations → Feature flags:
- Pick LaunchDarkly.
- Enter the API access token (it starts with
api-). - Enter the Project key.
- Choose Test connection.
- Pick the environment your tests run against, for example
testorstaging. TestChimp lists the project's environments. - Save. The first sync runs right away.
TestChimp uses https://app.launchdarkly.com by default. A custom base URL must use HTTPS on a launchdarkly.com host; instances on other domains are not supported yet.
How the environment is mapped
LaunchDarkly flags have per-environment targeting. TestChimp reads the flags for the environment you picked:
- Arms are the flag's variations. Boolean flags have
trueandfalse. Multivariate flags use each variation's value, shown with the variation's name. - Rollout is the default rule (fallthrough) split for that environment. A fixed default variation shows as 100%. Targeting rules and individual targets are not read, so the rollout is the split for users no rule matches.
If your tests run against more than one LaunchDarkly environment, pick the one most of them use.
What sync reads
- Flags in the project, with key, name, description, tags, kind and archived state.
- Each flag's variations.
- The default rule of the selected environment.
- The project's environment list, for the environment picker.
Sync runs when you save the connection, once a day, and when you choose Sync now. Flags removed from LaunchDarkly are marked archived, not deleted.
Capture in your app
The connection supplies the catalog. To record which variations your tests run, add @testchimp/flags to your app:
- Browser:
instrumentLaunchDarkly(options)around the options you pass toLDClient.initialize. - Node backend:
instrumentLaunchDarklyNode(ldClient)with@launchdarkly/node-server-sdkv9.3 or later, plus the collection middleware andTESTCHIMP_FLAG_ECHO=1in test environments.
Tests that mock LaunchDarkly's client evaluation endpoints with route.fulfill are recorded as forced. See Setup.
Troubleshooting
- 401 or 403: check the token is active and can read the project. The token goes in as-is, without a
Bearerprefix. - 404 on test: check the project key. It is the key, not the project's display name.
- No rollout shown: the flag has no default rule data for the selected environment, or the environment is wrong.
- An arm shows "not in provider": the app reports a value no variation has. Choose Sync now, then compare the reported value with the variation values.
Rotation
Create a new token, edit the connection, paste it in, test and save. Leaving the token field blank keeps the stored one. Then revoke the old token in LaunchDarkly.
FAQ
Which LaunchDarkly token should I use?
A service API access token with the Reader role, or a custom role that can only read the project.
Which rollout does TestChimp show?
The default rule (fallthrough) split for the environment your tests run against. Targeting rules are not read.