Skip to Content
SDK & PluginsShared Config

Configuration

Use configure() when several tests in one file need the same runtime setup.

This keeps repeated environment access, headers, and plugin wiring out of each individual test.

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 data = await http.get("users?limit=5").json<{ users: any[] }>(); 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 test suite:

// 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").json(); });

Plugin registration

configure() is also where you register plugins. 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 } }`); });

HTTP options

The http field supports these options:

OptionTypeDescription
prefixUrlstringBase URL ({{KEY}} resolved)
headersRecord<string, string>Default headers ({{KEY}} resolved)
timeoutnumberRequest timeout in ms
retrynumber | objectRetry configuration
throwHttpErrorsbooleanThrow on 4xx/5xx
hooksobjectbeforeRequest / afterResponse hooks

Next

Last updated on