@gatling.io/http
Version:
Gatling JS is a JavaScript/TypeScript interface for the [Gatling load testing tool](https://gatling.io/).
132 lines (131 loc) • 7.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ws = exports.isWsInboundMessageText = exports.isWsInboundMessageBinary = void 0;
const core_1 = require("@gatling.io/core");
const jvm_types_1 = require("@gatling.io/jvm-types");
const request_1 = require("./request");
const jvmWsPrefix = jvm_types_1.Ws$Prefix.INSTANCE;
const wsPrefix = {
checkBinaryMessage: (name) => wrapWsFrameCheckBinary(typeof name === "function"
? jvmWsPrefix.checkBinaryMessage((0, core_1.underlyingSessionTo)(name))
: jvmWsPrefix.checkBinaryMessage(name)),
checkTextMessage: (name) => wrapWsFrameCheckText(typeof name === "function"
? jvmWsPrefix.checkTextMessage((0, core_1.underlyingSessionTo)(name))
: jvmWsPrefix.checkTextMessage(name)),
processUnmatchedMessages: (arg0, arg1) => {
if (arg1 !== undefined) {
// arg1 is the WsProcessUnmatchedMessagesCallback if it is defined
// arg0 is the sseName
const f = arg1;
if (typeof arg0 === "string") {
const sseName = arg0;
return (0, core_1.wrapActionBuilder)(jvmWsPrefix.processUnmatchedMessages(sseName, (0, core_1.underlyingXWithSessionToSession)(f)));
}
else if (typeof arg0 === "function") {
const sseName = arg0;
return (0, core_1.wrapActionBuilder)(jvmWsPrefix.processUnmatchedMessages((0, core_1.underlyingSessionTo)(sseName), (0, core_1.underlyingXWithSessionToSession)(f)));
}
}
else if (typeof arg0 === "function") {
// arg0 is the SseProcessUnmatchedMessagesCallback if arg1 is undefined
const f = arg0;
return (0, core_1.wrapActionBuilder)(jvmWsPrefix.processUnmatchedMessages((0, core_1.underlyingXWithSessionToSession)(f)));
}
throw Error(`processUnmatchedMessages() called with invalid arguments ${arg0}, ${arg1}`);
}
};
const wsAwaitActionBuilderImpl = (jvmBuilder, wrap) => ({
await: (timeout) => wrapWsAwaitActionBuilderOn((0, core_1.isDuration)(timeout)
? jvmBuilder.await((0, core_1.toJvmDuration)(timeout))
: typeof timeout === "function"
? jvmBuilder.await((0, core_1.underlyingSessionToDuration)(timeout))
: jvmBuilder.await(timeout), wrap)
});
const wrapWsAwaitActionBuilderOn = (jvmOn, wrap) => ({
on: (...checks) => wrap(jvmOn.on(checks.map((c) => c._underlying)))
});
const wrapWsConnectActionBuilder = (_underlying) => ({
_underlying,
subprotocol: (sub) => wrapWsConnectActionBuilder(typeof sub === "function" ? _underlying.subprotocol((0, core_1.underlyingSessionTo)(sub)) : _underlying.subprotocol(sub)),
onConnected: (chain) => wrapWsConnectActionBuilder(_underlying.onConnected(chain._underlying)),
...(0, request_1.requestActionBuilderImpl)(_underlying, wrapWsConnectActionBuilder),
...wsAwaitActionBuilderImpl(_underlying, wrapWsConnectActionBuilder)
});
const wrapWsSendTextActionBuilder = (_underlying) => ({
_underlying,
...wsAwaitActionBuilderImpl(_underlying, wrapWsSendTextActionBuilder)
});
const wrapWsSendBinaryActionBuilder = (_underlying) => ({
_underlying,
...wsAwaitActionBuilderImpl(_underlying, wrapWsSendBinaryActionBuilder)
});
const wrapWsFrameCheckBinary = (_underlying) => ({
_underlying,
matching: (...newMatchConditions) => wrapWsFrameCheckBinary(_underlying.check(newMatchConditions.map((cb) => cb._underlying))),
check: (...checks) => wrapWsFrameCheckBinary(_underlying.check(checks.map((cb) => cb._underlying))),
checkIf: (condition) => {
if (typeof condition === "function") {
if (condition.length === 1) {
return wrapWsFrameCheckBinaryUntypedCondition(_underlying.checkIf((0, core_1.underlyingSessionTo)(condition)));
}
else {
return wrapWsFrameCheckBinaryTypedCondition(_underlying.checkIf((0, core_1.underlyingXWithSessionTo)(condition)));
}
}
else {
return wrapWsFrameCheckBinaryUntypedCondition(_underlying.checkIf(condition));
}
},
silent: () => wrapWsFrameCheckBinary(_underlying.silent())
});
const wrapWsFrameCheckBinaryUntypedCondition = (_underlying) => ({
then: (...thenChecks) => wrapWsFrameCheckBinary(_underlying.then(thenChecks.map((cb) => cb._underlying)))
});
const wrapWsFrameCheckBinaryTypedCondition = (_underlying) => ({
then: (...thenChecks) => wrapWsFrameCheckBinary(_underlying.then(thenChecks.map((cb) => cb._underlying)))
});
const wrapWsFrameCheckText = (_underlying) => ({
_underlying,
matching: (...newMatchConditions) => wrapWsFrameCheckText(_underlying.check(newMatchConditions.map((cb) => cb._underlying))),
check: (...checks) => wrapWsFrameCheckText(_underlying.check(checks.map((cb) => cb._underlying))),
checkIf: (condition) => {
if (typeof condition === "function") {
if (condition.length === 1) {
return wrapWsFrameCheckTextUntypedCondition(_underlying.checkIf((0, core_1.underlyingSessionTo)(condition)));
}
else {
return wrapWsFrameCheckTextTypedCondition(_underlying.checkIf((0, core_1.underlyingXWithSessionTo)(condition)));
}
}
else {
return wrapWsFrameCheckTextUntypedCondition(_underlying.checkIf(condition));
}
},
silent: () => wrapWsFrameCheckText(_underlying.silent())
});
const wrapWsFrameCheckTextUntypedCondition = (_underlying) => ({
then: (...thenChecks) => wrapWsFrameCheckText(_underlying.then(thenChecks.map((cb) => cb._underlying)))
});
const wrapWsFrameCheckTextTypedCondition = (_underlying) => ({
then: (...thenChecks) => wrapWsFrameCheckText(_underlying.then(thenChecks.map((cb) => cb._underlying)))
});
const isWsInboundMessageBinary = (message) => typeof message.message() !== "string";
exports.isWsInboundMessageBinary = isWsInboundMessageBinary;
const isWsInboundMessageText = (message) => typeof message.message() === "string";
exports.isWsInboundMessageText = isWsInboundMessageText;
const wrapWs = (jvmWs) => ({
wsName: (wsName) => wrapWs(typeof wsName === "function" ? jvmWs.wsName((0, core_1.underlyingSessionTo)(wsName)) : jvmWs.wsName(wsName)),
connect: (url) => wrapWsConnectActionBuilder(typeof url === "function" ? jvmWs.connect((0, core_1.underlyingSessionTo)(url)) : jvmWs.connect(url)),
sendText: (text) => wrapWsSendTextActionBuilder(typeof text === "function" ? jvmWs.sendText((0, core_1.underlyingSessionTo)(text)) : jvmWs.sendText(text)),
sendBytes: (bytes) => wrapWsSendBinaryActionBuilder(typeof bytes === "function"
? jvmWs.sendBytes((0, core_1.underlyingSessionTo)(bytes))
: typeof bytes === "string"
? jvmWs.sendBytes(bytes)
: jvmWs.sendBytes(bytes)),
close: () => (0, core_1.wrapActionBuilder)(jvmWs.close())
});
const wsApply = (name, wsName) => {
const jvmWs = wsName === undefined ? jvm_types_1.HttpDsl.ws(name) : jvm_types_1.HttpDsl.ws(name, wsName);
return wrapWs(jvmWs);
};
exports.ws = Object.assign(wsApply, wsPrefix);