Testing utilities
Test custom-domain code without network calls using memoryProvider, createMockDomain, createMockDnsRecord, and createFailingProvider from the testing subpath.
memoryProvider(options?) returns an in-memory provider for tests and local scripts. Each instance keeps its own domains and makes no network calls. Every option is optional:
interface MemoryProviderOptions {
initialStatus?: DomainStatus;
records?: DnsRecord[] | ((hostname: string) => DnsRecord[]);
certificateStatus?: CertificateStatus;
activationDelayMs?: number;
latencyMs?: number;
failures?: Partial<Record<MemoryOperation, DomainSdkError | (() => DomainSdkError)>>;
}
type MemoryOperation = "add" | "get" | "list" | "verify" | "remove";
initialStatussets the status of each added domain. It defaults to"pending_dns". With"active", records startvalid, verificationverified, and the certificateactiveunlesscertificateStatusis set.recordsreplaces the default record, oneCNAMEfrom the hostname to the placeholdertarget.example.net. Pass a function to build records per hostname. Records withpurpose: "ownership"are also copied intoverification.records.certificateStatussets the initialcertificate.status. It defaults to"pending", or"active"wheninitialStatusis"active".activationDelayMsmarks each domain active this many milliseconds afteradd(). Without it, a domain keeps its initial status until you change it.latencyMswaits before every operation. Aborting the request’s signal during the wait rejects withABORTED.failuresmakes an operation throw the givenDomainSdkError, or call the function and throw what it returns.
The returned provider also has:
calls, the live call log: one{ operation, hostname?, at }entry peradd,get,list,verify, orremovecall, in order.activate(),transition(), andreset()add no entries. TypeScript types it as a readonly array, but it is not a snapshot.activate(hostname), which setsstatustoactive,verification.statustoverified,certificate.statustoactive, and every entry indomain.recordstovalid. Entries inverification.recordskeep their original status.domains.verify(hostname)does the same.transition(hostname, status, certificateStatus?), which sets anyDomainStatus. Passing"active"also setsverification.statustoverifiedand every entry indomain.recordstovalid.certificateStatussetscertificate.statuswhen given; otherwise the certificate becomesactivefor"active"and keeps its status for any other value.reset(), which clears domains, calls, and pending activation timers.
createMockDomain, createMockDnsRecord, and createFailingProvider generate focused test values. Import all of them from @opencoredev/domain-sdk/testing; production root imports remain unaffected.
Read next: Test without external API calls.