Configuration
Use configure() when several Glubean assets in one file need the same runtime
setup.
This keeps repeated environment access, headers, and client wiring out of each
individual contract, workflow, or raw test() check.
File-level setup
Use configure() to set up shared HTTP defaults, variables, and secrets once
per file. All values use {{KEY}} template syntax and resolve lazily at
runtime.
import { configure, test } from "@glubean/sdk";
export const { http, vars, secrets } = configure({
vars: {
baseUrl: "{{BASE_URL}}",
},
secrets: {
apiKey: "{{API_KEY}}",
},
http: {
prefixUrl: "{{BASE_URL}}",
headers: { Authorization: "Bearer {{API_KEY}}" },
},
});
export const listUsers = test("list-users", async (ctx) => {
const res = await http.get("users", { searchParams: { limit: "5" } });
ctx.expect(res).toHaveStatus(200);
const data = await res.json<{ users: unknown[] }>();
ctx.expect(data.users.length).toBe(5);
ctx.log(`Tested against ${vars.baseUrl}`);
});The {{KEY}} placeholders resolve from both ctx.vars and ctx.secrets at runtime. Secrets take precedence over vars if both have the same key.
Shared across files
Extract configure() into a shared file to reuse across your Glubean project:
// tests/configure.ts
import { configure } from "@glubean/sdk";
export const { vars, secrets, http } = configure({
vars: { baseUrl: "{{BASE_URL}}" },
secrets: { apiKey: "{{API_KEY}}" },
http: {
prefixUrl: "{{BASE_URL}}",
headers: { Authorization: "Bearer {{API_KEY}}" },
},
});
// tests/users.test.ts
import { test } from "@glubean/sdk";
import { http } from "./configure.js";
export const listUsers = test("list-users", async (ctx) => {
const res = await http.get("users");
ctx.expect(res).toHaveStatus(200);
});Client factories in configure()
configure({ plugins }) registers client factories for the current file:
GraphQL clients, domain API wrappers, or any lazy runtime helper you want to
share across contracts, workflows, and raw tests.
This is separate from plugin manifests. A package that adds global matchers
or a new contract protocol still needs installPlugin(...) from a project
glubean.setup.ts; a plain client factory does not.
Reserved keys (vars, secrets, http) cannot be used as plugin names.
import { configure, test } from "@glubean/sdk";
import { graphql } from "@glubean/graphql";
const { gql } = configure({
plugins: {
gql: graphql({
endpoint: "{{GRAPHQL_URL}}",
headers: { Authorization: "Bearer {{API_KEY}}" },
throwOnGraphQLErrors: true,
}),
},
});
export const checkGraphql = test("graphql", async (ctx) => {
const { data } = await gql.query<{ me: { id: string } }>(`{ me { id } }`);
ctx.expect(data?.me?.id).toBeDefined();
});HTTP options
The http field supports these options:
| Option | Type | Description |
|---|---|---|
prefixUrl | string | Base URL ({{KEY}} resolved) |
headers | Record<string, string> | Default headers ({{KEY}} resolved) |
timeout | number | Request timeout in ms |
retry | number | object | Retry configuration |
throwHttpErrors | boolean | Throw on 4xx/5xx |
hooks | object | beforeRequest / afterResponse hooks |