npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@testchimp/flags

v0.1.1

Published

Feature flag evaluation hooks for apps under test. Reports which flag arms a TestChimp test ran, from the browser and from the backend.

Readme

@testchimp/flags

Feature flag hooks for apps under test. They tell TestChimp which flag arms your tests actually ran, so the coverage view can show untested arms.

  • Web (@testchimp/flags/web): reports flags the browser evaluates, through OpenFeature, the LaunchDarkly JS SDK or PostHog JS.
  • Server (@testchimp/flags/server): echoes the flags a backend evaluated for a request back to the test, in a response header. It works with Express, Connect, Fastify, Next.js route handlers, and any (req, res) handler, and includes hooks for OpenFeature, LaunchDarkly Node and PostHog Node.

No runtime dependencies. OpenFeature, LaunchDarkly and PostHog are not imported, so the hooks work with any version that has the callbacks described below.

npm install @testchimp/flags

Safety: nothing happens outside a test

This is the most important property, and it is tested.

  • Web: every function checks for globalThis.__TESTCHIMP_FLAGS__. The TestChimp Playwright fixture defines that global, and only in tests. In production there is no global, so the hooks install no wrappers, make no network calls, and throw nothing.
  • Server: nothing happens unless TESTCHIMP_FLAG_ECHO=1 (or true) is set. Set it only in test environments. When it is unset, no header is added and no per-request state is kept.

Web

Report evaluations through the SDK you already use:

import { createOpenFeatureHook, instrumentLaunchDarkly, instrumentPostHog, reportFlag } from '@testchimp/flags/web';

// OpenFeature web SDK
OpenFeature.addHooks(createOpenFeatureHook());

// LaunchDarkly JS SDK: inspectors can only be set at initialize time
const client = LDClient.initialize(clientSideId, context, instrumentLaunchDarkly({ bootstrap }));

// PostHog JS: call once after init
posthog.init(projectKey, options);
instrumentPostHog(posthog);

// Anything else: report the arm yourself
reportFlag('checkout-layout', 'compact', 'my-provider');

Each provider's evaluations reach the fixture with the right provider id: openfeature, launchdarkly or posthog.

| Provider | Hook | How it captures | |---|---|---| | OpenFeature (web) | createOpenFeatureHook() | The hook's after stage. Reports the variant, or the value when there is no variant. | | LaunchDarkly JS | instrumentLaunchDarkly(options) | A flag-used inspector, which the SDK calls on each variation call. allFlags() is not counted. | | PostHog JS | instrumentPostHog(posthog) | Wraps posthog.capture and reads the $feature_flag_called event that getFeatureFlag emits. Lookups made with send_event: false emit no event, so they are not captured. |

instrumentLaunchDarkly returns a new options object, so pass its result into initialize. It returns the options unchanged outside a test.

Server

Set TESTCHIMP_FLAG_ECHO=1 in the test environment that runs the backend. Then add the middleware (or wrapper) that matches your framework.

// Express or Connect
import { flagCollectionMiddleware } from '@testchimp/flags/server';
app.use(flagCollectionMiddleware());

// Fastify
import { fastifyFlagCollection } from '@testchimp/flags/server';
await app.register(fastifyFlagCollection);

// Next.js App Router route handler, or any (req, res) handler
import { withFlagCollection } from '@testchimp/flags/server';
export const GET = withFlagCollection(async (request: Request) => Response.json(await loadOrders()));

Then wire the provider hook once, at startup:

import { createOpenFeatureServerHook, instrumentLaunchDarklyNode, instrumentPostHogNode } from '@testchimp/flags/server';

OpenFeature.addHooks(createOpenFeatureServerHook());    // OpenFeature server SDK
instrumentLaunchDarklyNode(ldClient);                  // @launchdarkly/node-server-sdk v9.3+, after init
instrumentPostHogNode(posthogClient);                  // posthog-node: getFeatureFlag, isFeatureEnabled, evaluateFlags

reportFlag(flagKey, variant, providerId) is also exported, for providers without a hook.

isFeatureEnabled on a multivariate PostHog flag answers true without naming the variant, so TestChimp can't tell which arm ran and doesn't count it. Use getFeatureFlag, or evaluateFlags (its isEnabled reports the served variant).

Each request gets its own collector, through AsyncLocalStorage. Concurrent requests never see each other's flags.

Backend-only flags need the echo

A flag evaluated only in the backend shows as untested unless TESTCHIMP_FLAG_ECHO=1 is set on the backend. Flags evaluated in the browser need no backend setup, because the fixture captures them directly.

Only the service that answers the browser's request echoes its flags. Deeper services, queue consumers, cron jobs and background workers are out of scope for v1.

Header contract

The header is the interface between your backend and TestChimp. Any language can implement it.

x-testchimp-flags: v1.<base64url(JSON array of {k, v, p})>
x-testchimp-flags-truncated: 1        (only when entries were dropped)
  • k is the flag key, v is the arm as a string, p is the provider id (openfeature, launchdarkly, posthog, statsig, or unknown).
  • Entries are deduplicated by (k, v).
  • base64url has no padding.
  • The encoded value must stay within 4096 bytes. Keep the first entries that fit, and set x-testchimp-flags-truncated: 1 if any were dropped.
  • Set the header only when at least one entry was recorded. Set it only when the echo is enabled.

A Python implementation, about 25 lines:

import base64, json

MAX_BYTES = 4096

def encode(entries):
    return "v1." + base64.urlsafe_b64encode(json.dumps(entries, separators=(",", ":")).encode()).rstrip(b"=").decode()

def flag_headers(arms):
    """arms: (flag_key, variant, provider_id) tuples observed while handling one request."""
    seen, kept, truncated = set(), [], False
    for k, v, p in arms:
        if (k, v) in seen:
            continue
        seen.add((k, v))
        if len(encode(kept + [{"k": k, "v": v, "p": p}]).encode()) > MAX_BYTES:
            truncated = True
            break
        kept.append({"k": k, "v": v, "p": p})
    if not kept:
        return {}
    headers = {"x-testchimp-flags": encode(kept)}
    if truncated:
        headers["x-testchimp-flags-truncated"] = "1"
    return headers

Call flag_headers from your framework's response hook, and only when the echo is enabled. The Playwright fixture reads the header from every response, so no CORS change is needed in the app under test.

Verified against

  • @launchdarkly/node-server-sdk 9.17.1: the afterEvaluation hook fires from a real variation call.
  • @openfeature/server-sdk 1.23.0: the after hook fires from a real getBooleanValue and getStringValue call.
  • The header decodes with the @testchimp/playwright fixture decoder.
  • The web entry is checked to contain no Node-only module, and makes no network calls (unit tests).
  • The LaunchDarkly JS inspector, PostHog $feature_flag_called and posthog-node method shapes are taken from the providers' current documentation. They are covered by unit tests, but not yet by a live browser run.

Not in v1

  • Statsig adapters. Statsig gates reach TestChimp through the fixture's bootstrap capture only.
  • Java, Python and Go server hooks. Use the header contract above.
  • Flags evaluated outside the service that answers the browser's request.

License

MIT