Testing
Swap configure() for configureForTesting() and seed the values your code should see — unit-test flag-gated code without touching the network.
Code that reads flags shouldn't need a live connection to test. Swap the live configure() for configureForTesting() — a drop-in sibling with no network, ever and no SDK key required. It seeds the values your code should see, and you read them back through the ordinary new Client(user). In this mode the rules never fetch, track() is a no-op, assign() logs no exposure, and telemetry is off.
Unlike configure() (first-config-wins), configureForTesting() and
configureForOffline() replace the active configuration — a suite can
reconfigure freely between cases. Your code under test keeps calling new Client(user)
exactly as it does in production.
Seed the values
import { configureForTesting, Client, clearOverrides } from "@shipeasy/sdk/server"; // or /client
configureForTesting({
flags: { new_checkout: true },
configs: { upload_limits: { max_uploads: 50 } },
});
const flags = new Client({ user_id: "u_1" });
flags.getFlag("new_checkout"); // true
flags.getConfig("upload_limits"); // { max_uploads: 50 }
clearOverrides(); // reset every seeded override back to the empty-blob defaultconfigureForTesting({ flags?, configs?, attributes? }):
| Field | Shape | Effect |
|---|---|---|
flags | { [name]: boolean } | forced getFlag results |
configs | { [name]: value } | forced getConfig results |
attributes | (yourUser) => User | same transform as configure() (default identity) |
Package-level overrides
Layer a quick override on top of whatever configureForTesting() / configureForOffline() — or even a live configure() — set up. These are package-level; there's no object to hold:
import { overrideFlag, overrideConfig, clearOverrides } from "@shipeasy/sdk/server"; // or /client
overrideFlag("new_checkout", true);
overrideConfig("upload_limits", { max_uploads: 50 });
// …read through `new Client(user)` …
clearOverrides(); // drop every on-the-spot overrideOverrides on a real client
A programmatic override always wins, including against a live configuration. In the browser the precedence is:
programmatic override > URL / devtools override (?se_gate_… ) > the server's evaluationUse configureForTesting() + override* to seed individual values; use
configureForOffline() with a snapshot when you
want the real rule set evaluated offline. They compose — overrides apply on top of a
snapshot too.