- addons
Create a Modern Test Data Function
A test data function is a pure generator. It receives a parameter map and returns a single string. It has no UI adapters and cannot modify runtime variables, and that purity is what lets the platform call it anywhere a value is needed.
Prerequisites
- A Modern addon exists and its scaffold is downloaded.
Declare the Function
import { defineTestDataFunction } from "@testsigma/addon-sdk";
import { z } from "zod";
export const randomEmail = defineTestDataFunction({
name: "random.email",
description: "Generate a unique email address",
parameters: z.object({
domain: z.string().default("example.com").describe("Mail domain to use"),
}),
async generate({ domain }, ctx) {
const local = `user-${Math.random().toString(36).slice(2, 10)}`;
ctx.logger.info("generated email", { domain });
return `${local}@${domain}`;
},
});Declaration Fields
| Field | Meaning |
|---|---|
| name | Globally unique name. Use the dotted convention. |
| description | Shown in the data generator picker. |
| parameters | Optional Zod schema for arguments the test author fills in. |
| permissions | Optional allowlists. Only fs, net, and env apply. |
| generate(args, ctx) | Returns a Promise |
A function that calls an external API declares the host it contacts, for example permissions: { net: ["erp.example.com"] }.
What the Context Provides
ctx gives you tmpDir, signal, logger, and execution. There is no UI adapter and no runtime variable store.
ai and ocr permissions are honored for action addons only. A test data function context never exposes ctx.ai or ctx.ocr.
Where Test Authors Use It
- Step test data, in any field that accepts a data generator
- For-loop conditions, as the left or right bound
- Step group parameter overrides
Write for Idempotence
The platform may cache a result within a run when the function is invoked with identical parameters. A loop bound, for example, is computed once per loop rather than once per iteration.
Do not rely on the function being re-invoked for every reference with the same arguments. If each call must produce a fresh value, vary a parameter.
