How to Test Both Flag States in CI With a Matrix
A matrix over the flag value runs the suite with the flag on and off, so neither path regresses silently.
While a flag exists, both states are live code. A GitHub Actions matrix that sets the flag to on and off runs the whole suite against each, catching breakage in either branch.
Steps
- Read the flag override from an environment variable in tests.
- Add a matrix dimension with the flag values
onandoff. - Set the env var from
matrix.flagso each leg forces one state.
Matrix over the flag
.github/workflows/ci.yml
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
flag: [on, off]
env:
FF_NEW_CHECKOUT: ${{ matrix.flag }}
steps:
- uses: actions/checkout@v4
- run: npm ci && npm testHonor the override in code
Terminal
function newCheckoutEnabled() {
const override = process.env.FF_NEW_CHECKOUT;
if (override) return override === 'on';
return flags.getBooleanValue('new-checkout', false);
}Gotchas
- Only override in test builds; a leaked override in production defeats the real flag.
- Two states double the run count, so keep flags short-lived to bound the matrix.
Related guides
How to Mock Feature Flags in CI TestsReplace the flag backend with an in-memory provider in CI tests so each test forces exact flag values without…
How to Build a Kill Switch With Feature FlagsAdd a feature flag kill switch so an incident is mitigated by toggling one flag off in seconds instead of wai…