Skip to content
Latchkey

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 on and off.
  • Set the env var from matrix.flag so 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 test

Honor 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

Run this faster and cheaper on Latchkey managed runners. Start free →