API reference
Everything below is exported from neritest.
createSandbox(options?) → Sandbox
interface SandboxOptions {
logging?: LoggerOptions; // { console?, categories?, level?, bufferSize? }
startTime?: number; // virtual clock start (ms since epoch). default: now
botUsername?: string; // default "TestBot"
acceptAnyToken?: boolean; // unknown tokens auth as the bot. default true
fetchShim?: boolean; // intercept hardcoded CDN/webhook hosts. default true
}
Construction is synchronous; the servers bind asynchronously.
Sandbox
Lifecycle
ready(): Promise<this>- resolves when gateway + API are listening.close(): Promise<void>- stop servers, disconnect bots, remove the fetch shim.wsUrl/apiUrl- the sandbox URLs.bot- the defaultSandboxUser.token.
World building
createUser({ username, ...RawUser }): SandboxUsercreateServer(opts): SandboxServerTypeScriptinterface CreateServerOptions { name: string; owner?: SandboxUser; // default: the sandbox bot (bot gets creator perms) botJoins?: boolean; // default true botPermissions?: number; // bot's role perms when it joins. default ADMIN hexColor?: string; }createDM(user): SandboxChannel- a DM channel between the bot anduser.user(id): SandboxUser | undefined
Bot execution
createClient({ token?, messageCacheLimit? }): Promise<Client>- a real SDK client, logged in.mount(client, { token? }): Promise<Client>- repoint an existing client.loadBot(entryPath): Promise<module>- import an unmodified bot; itsnew Client()connects here.
Time
advanceTime(amount)-"5m","1h30m","24h", or ms. Fires virtual timers.now(): number- current virtual time.clock: ClockforsetTimeout/setInterval.
Fault injection
api- theApiServer(see below).gateway- theGateway(see below).
Record / replay / fixtures / debug
record(file?): Recording-{ stop(): Session, save(file?): Session }.replay(sessionOrFile, { realtime?, speed? }): Promise<void>loadFixture(nameOrFn)-"basic","moderation","large-server", or a builder.debug- theDebugger.logs- theLogger.store- the rawStore(escape hatch).
Facade objects
SandboxServer
name, defaultRoleId, ownerId, defaultChannel, channels, roles, defaultRole, members
createChannel({ name, type?, category?, permissions? }): SandboxChannelcreateCategory(name): SandboxChannelcreateRole({ name?, permissions?, hexColor?, hideRole? }): SandboxRoleaddMember(user, { nickname?, roles? })setMemberRoles(user, roles)/giveRole(user, role)member(user): SandboxMember | undefined/memberPermissions(user): numberisBanned(user): boolean/removeMember(user)addCustomEmoji(name, { gif?, id? })/update({ name?, avatar?, banner?, hexColor? })
SandboxChannel
id, name, type, serverId, messages, lastMessage
send(user, input): SandboxMessage-inputis a string or:TypeScriptinterface SendOptions { content?: string; html?: string; // → message.htmlEmbed (Nerimity HTML support) htmlEmbed?: string; // alias embed?: RawEmbed; buttons?: { id: string; label: string; alert?: boolean }[]; attachments?: { mime?; path?; width?; height?; duration? }[]; silent?: boolean; replyTo?: SandboxMessage | string; mentionReplies?: boolean; type?: MessageType; }sendHtml(user, html): SandboxMessagestartTyping(user)- fireschannel:typingupdate({ name?, permissions?, categoryId? })/delete()
SandboxMessage
id, content, htmlEmbed, authorId, channelId, reactions, buttons, editedAt,
deleted, toRaw()
react(user, emoji)/removeReaction(user, emoji)- emoji is a string or{ name, emojiId?, gif? }clickButton(user, buttonId, { type?, data? })- firesmessageButtonClickedit({ content?, html?, buttons? })- firesmessageUpdatedelete()- firesmessageDelete
SandboxUser
id, username, tag, isBot, toString() (→ [@:id] mention)
setPresence({ status?, custom?, activity? })wasKicked(server?): boolean/wasBanned(server?): boolean
SandboxMember
nickname, roles: SandboxRole[], permissions: number
hasRole(role)/hasPermission(bit)
SandboxRole
id, name, permissions - update({...}) / delete()
ApiServer (sandbox.api)
Fault injection: rateLimit({ requests?, retryAfterMs? }), failNext(status, body),
setLatency(ms), hangNext(ms?).
Direct requests (as the bot): get(path), post(path, body), patch(path, body),
delete(path), request(method, path, body?) → { status, body }.
Gateway (sandbox.gateway)
disconnect({ close? }), setLatency(ms), setPacketLoss(rate), setDuplication(rate),
rejectNextAuth(), connectionCount, emitRaw(event, payload).
expect(value)
toBe, toEqual, toContain, toContainEqual, toHaveLength, toBeTruthy, toBeFalsy,
toBeDefined, toBeUndefined, toBeNull, toBeGreaterThan, toBeLessThan, toMatch,
toThrow, toContainHtml, .not, .resolves, .rejects.
Constants & helpers
RolePermissions, permissions("KICK", "BAN"), hasBit, addBit, removeBit,
MessageType, ChannelType, ServerToClient, ClientToServer, Clock, parseDuration,
Recorder, Logger, Debugger, and all Raw* types.