UNPKG

@gatling.io/http

Version:

Gatling JS is a JavaScript/TypeScript interface for the [Gatling load testing tool](https://gatling.io/).

378 lines (377 loc) 14 kB
import { ActionBuilder, ChainBuilder, CheckBuilder, Duration, Session, Wrapper } from "@gatling.io/core"; import { RequestActionBuilder } from "./request"; import JvmWsFrameCheckBinary = io.gatling.javaapi.http.WsFrameCheck$Binary; import JvmWsFrameCheckText = io.gatling.javaapi.http.WsFrameCheck$Text; /** * DSL for building WebSocket configurations * * <p>Immutable, so all methods return a new occurrence and leave the original unmodified. */ export interface Ws { /** * Define a custom WebSocket name so multiple WebSockets for the same virtual users don't conflict * * @param wsName - the name, expressed as a Gatling Expression Language String * @returns a new Ws instance */ wsName(wsName: string): Ws; /** * Define a custom WebSocket name so multiple WebSockets for the same virtual users don't conflict * * @param wsName - the name, expressed as a function * @returns a new Ws instance */ wsName(wsName: (session: Session) => string): Ws; /** * Boostrap an action to connect the WebSocket * * @param url - the url to connect to, expressed as a Gatling Expression Language String * @returns the next DSL step */ connect(url: string): WsConnectActionBuilder; /** * Boostrap an action to connect the WebSocket * * @param url - the url to connect to, expressed as a function * @returns the next DSL step */ connect(url: (session: Session) => string): WsConnectActionBuilder; /** * Boostrap an action to send a TEXT frame * * @param text - the text to send, expressed as a Gatling Expression Language String * @returns the next DSL step */ sendText(text: string): WsSendTextActionBuilder; /** * Boostrap an action to send a TEXT frame * * @param text - the text to send, expressed as a function * @returns the next DSL step */ sendText(text: (session: Session) => string): WsSendTextActionBuilder; /** * Boostrap an action to send a BINARY frame * * @param bytes - the static bytes to send * @returns the next DSL step */ sendBytes(bytes: number[]): WsSendBinaryActionBuilder; /** * Boostrap an action to send a BINARY frame * * @param bytes - the bytes to send, expressed as a Gatling Expression Language String * @returns the next DSL step */ sendBytes(bytes: string): WsSendBinaryActionBuilder; /** * Boostrap an action to send a BINARY frame * * @param bytes - the bytes to send, expressed as a function * @returns the next DSL step */ sendBytes(bytes: (session: Session) => number[]): WsSendBinaryActionBuilder; /** * Boostrap an action to send a CLOSE frame with the default 1000 status code * * @returns the next DSL step */ close(): ActionBuilder; /** * Boostrap an action to send a CLOSE frame with specified status and reason * * @param statusCode - the close frame status code * @param reason - the close frame reason * @returns the next DSL step */ close(statusCode: number, reason: string): ActionBuilder; } type WsProcessUnmatchedMessagesCallback = (messages: WsInboundMessage[], session: Session) => Session; export interface WsPrefix { /** * Bootstrap a check on inbound TEXT frames * * @param name - the name of the check, expressed as a Gatling Expression Language String * @returns the next DSL step */ checkTextMessage(name: string): WsFrameCheckText; /** * Bootstrap a check on inbound TEXT frames * * @param name - the name of the check, expressed as a function * @returns the next DSL step */ checkTextMessage(name: (session: Session) => string): WsFrameCheckText; /** * Bootstrap a check on inbound BINARY frames * * @param name - the name of the check, expressed as a Gatling Expression Language String * @returns the next DSL step */ checkBinaryMessage(name: string): WsFrameCheckBinary; /** * Bootstrap a check on inbound BINARY frames * * @param name - the name of the check, expressed as a function * @returns the next DSL step */ checkBinaryMessage(name: (session: Session) => string): WsFrameCheckBinary; /** * Process the currently buffered inbound WebSocket messages and empty the buffer * * @param f - the function to process the buffered messages * @returns an ActionBuilder */ processUnmatchedMessages(f: WsProcessUnmatchedMessagesCallback): ActionBuilder; /** * Process the currently buffered inbound WebSocket messages and empty the buffer * * @param wsName - the name of the WebSocket, expressed as a Gatling Expression Language String * @param f - the function to process the buffered messages * @returns an ActionBuilder */ processUnmatchedMessages(wsName: string, f: WsProcessUnmatchedMessagesCallback): ActionBuilder; /** * Process the currently buffered inbound WebSocket messages and empty the buffer * * @param wsName - the name of the WebSocket, expressed as a function * @param f - the function to process the buffered messages * @returns an ActionBuilder */ processUnmatchedMessages(wsName: (session: Session) => string, f: WsProcessUnmatchedMessagesCallback): ActionBuilder; } export interface WsAwaitActionBuilder<T> { /** * Boostrap a check that waits for a given duration * * @param timeout - the static wait duration * @returns the next DSL step */ await(timeout: Duration): WsAwaitActionBuilderOn<T>; /** * Boostrap a check that waits for a given duration * * @param timeout - the wait duration, expressed as a Gatling Expression Language String * @returns the next DSL step */ await(timeout: string): WsAwaitActionBuilderOn<T>; /** * Boostrap a check that waits for a given duration * * @param timeout - the wait duration, expressed as a function * @returns the next DSL step */ await(timeout: (session: Session) => Duration): WsAwaitActionBuilderOn<T>; } export interface WsAwaitActionBuilderOn<T> { /** * Define the checks to wait on * * @param checks - the checks * @returns a usable ActionBuilder */ on(...checks: WsFrameCheck[]): T; } /** * DSL for building WebSocket connect actions * * <p>Immutable, so all methods return a new occurrence and leave the original unmodified. */ export interface WsConnectActionBuilder extends RequestActionBuilder<WsConnectActionBuilder>, WsAwaitActionBuilder<WsConnectActionBuilder>, ActionBuilder { /** * Define a WebSocket subprotocol * * @param sub - the subprotocol, expressed as a Gatling Expression Language String * @returns a new WsConnectActionBuilder instance */ subprotocol(sub: string): WsConnectActionBuilder; /** * Define a WebSocket subprotocol * * @param sub - the subprotocol, expressed as a function * @returns a new WsConnectActionBuilder instance */ subprotocol(sub: (session: Session) => string): WsConnectActionBuilder; /** * Define a chain to execute when the WebSocket gets connected or re-connected * * @param chain - the chain * @returns a new WsConnectActionBuilder instance */ onConnected(chain: ChainBuilder): WsConnectActionBuilder; } /** * DSL for building actions to send TEXT frames * * <p>Immutable, so all methods return a new occurrence and leave the original unmodified. */ export interface WsSendTextActionBuilder extends WsAwaitActionBuilder<WsSendTextActionBuilder>, ActionBuilder { } /** * DSL for building actions to send BINARY frames * * <p>Immutable, so all methods return a new occurrence and leave the original unmodified. */ export interface WsSendBinaryActionBuilder extends WsAwaitActionBuilder<WsSendBinaryActionBuilder>, ActionBuilder { } export type WsFrameCheck = WsFrameCheckBinary | WsFrameCheckText; /** * DSL for building WebSocket BINARY frames checks * * <p>Immutable, so all methods return a new occurrence and leave the original unmodified. */ export interface WsFrameCheckBinary extends Wrapper<JvmWsFrameCheckBinary> { /** * Define conditions that have to hold true to match inbound messages and apply the checks on * them * * @param newMatchConditions - the conditions to match * @returns a new Binary instance */ matching(...newMatchConditions: CheckBuilder[]): WsFrameCheckBinary; /** * Define the checks to apply on inbound messages * * @param checks - the checks * @returns a new Binary instance */ check(...checks: CheckBuilder[]): WsFrameCheckBinary; /** * Define the checks to apply on inbound messages when a condition holds true. * * @param condition - a condition, expressed as a function * @returns the next DSL step */ checkIf(condition: (session: Session) => boolean): WsFrameCheckBinaryUntypedCondition; /** * Define the checks to apply on inbound messages when a condition holds true. * * @param condition - a condition, expressed as a Gatling Expression Language String * @returns the next DSL step */ checkIf(condition: string): WsFrameCheckBinaryUntypedCondition; /** * Define the checks to apply on inbound messages when a condition holds true. * * @param condition - a condition, expressed as a function that's aware of the HTTP response and * the Session * @returns the next DSL step */ checkIf(condition: (response: number[], session: Session) => boolean): WsFrameCheckBinaryTypedCondition; /** * Make the check silent, not logged by the reporting engine * * @returns a new Binary instance */ silent(): WsFrameCheckBinary; } export interface WsFrameCheckBinaryUntypedCondition { /** * Define the checks to apply on inbound messages when a condition holds true. * * @param thenChecks - the checks * @returns a new Binary instance */ then(...thenChecks: CheckBuilder[]): WsFrameCheckBinary; } export interface WsFrameCheckBinaryTypedCondition { /** * Define the checks to apply when the condition holds true. * * @param thenChecks - the checks * @returns a new Binary instance */ then(...thenChecks: CheckBuilder[]): WsFrameCheckBinary; } /** * DSL for building WebSocket TEXT frames checks * * <p>Immutable, so all methods return a new occurrence and leave the original unmodified. */ export interface WsFrameCheckText extends Wrapper<JvmWsFrameCheckText> { /** * Define conditions that have to hold true to match inbound messages and apply the checks on * them * * @param newMatchConditions - the conditions to match * @returns a new Text instance */ matching(...newMatchConditions: CheckBuilder[]): WsFrameCheckText; /** * Define the checks to apply on inbound messages * * @param checks - the checks * @returns a new Text instance */ check(...checks: CheckBuilder[]): WsFrameCheckText; /** * Define the checks to apply on inbound messages when a condition holds true. * * @param condition - a condition, expressed as a function * @returns the next DSL step */ checkIf(condition: (session: Session) => boolean): WsFrameCheckTextUntypedCondition; /** * Define the checks to apply on inbound messages when a condition holds true. * * @param condition - a condition, expressed as a Gatling Expression Language String * @returns the next DSL step */ checkIf(condition: string): WsFrameCheckTextUntypedCondition; /** * Define the checks to apply on inbound messages when a condition holds true. * * @param condition - a condition, expressed as a function that's aware of the HTTP response and * the Session * @returns the next DSL step */ checkIf(condition: (response: string, session: Session) => boolean): WsFrameCheckTextTypedCondition; /** * Make the check silent, not logged by the reporting engine * * @returns a new Text instance */ silent(): WsFrameCheckText; } export interface WsFrameCheckTextUntypedCondition { /** * Define the checks to apply on inbound messages when a condition holds true. * * @param thenChecks - the checks * @returns a new Text instance */ then(...thenChecks: CheckBuilder[]): WsFrameCheckText; } export interface WsFrameCheckTextTypedCondition { /** * Define the checks to apply when the condition holds true. * * @param thenChecks - the checks * @returns a new Text instance */ then(...thenChecks: CheckBuilder[]): WsFrameCheckText; } export type WsInboundMessage = WsInboundMessageBinary | WsInboundMessageText; export interface WsInboundMessageBinary { timestamp(): number; message(): number[]; } export declare const isWsInboundMessageBinary: (message: WsInboundMessage) => message is WsInboundMessageBinary; export interface WsInboundMessageText { timestamp(): number; message(): string; } export declare const isWsInboundMessageText: (message: WsInboundMessage) => message is WsInboundMessageText; export interface WsApply { /** * Bootstrap a WebSocket request configuration * * @param name - the WebSocket request name, expressed as a Gatling Expression Language String * @param wsName - the name of the WebSocket so multiple WebSockets for the same virtual users don't * conflict, expressed as a Gatling Expression Language String * @returns the next DSL step */ (name: string, wsName?: string): Ws; } export declare const ws: WsApply & WsPrefix; export {};