@kubb/plugin-cypress
Version:
Cypress test generator plugin for Kubb, creating end-to-end tests from OpenAPI specifications for automated API testing.
150 lines (147 loc) • 5.27 kB
JavaScript
//#region rolldown:runtime
var __create = Object.create;
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
value,
configurable: true
});
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
key = keys[i];
if (!__hasOwnProp.call(to, key) && key !== except) {
__defProp(to, key, {
get: ((k) => from[k]).bind(null, key),
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
}
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
value: mod,
enumerable: true
}) : target, mod));
//#endregion
let _kubb_plugin_oas_utils = require("@kubb/plugin-oas/utils");
let _kubb_react_fabric = require("@kubb/react-fabric");
let _kubb_core_utils = require("@kubb/core/utils");
let _kubb_oas = require("@kubb/oas");
let _kubb_react_fabric_jsx_runtime = require("@kubb/react-fabric/jsx-runtime");
//#region src/components/Request.tsx
function getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }) {
if (paramsType === "object") {
const pathParams = (0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
typed: true,
casing: paramsCasing
});
return _kubb_react_fabric.FunctionParams.factory({
data: {
mode: "object",
children: {
...pathParams,
data: typeSchemas.request?.name ? {
type: typeSchemas.request?.name,
optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
} : void 0,
params: typeSchemas.queryParams?.name ? {
type: typeSchemas.queryParams?.name,
optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
} : void 0,
headers: typeSchemas.headerParams?.name ? {
type: typeSchemas.headerParams?.name,
optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
} : void 0
}
},
options: {
type: "Partial<Cypress.RequestOptions>",
default: "{}"
}
});
}
return _kubb_react_fabric.FunctionParams.factory({
pathParams: typeSchemas.pathParams?.name ? {
mode: pathParamsType === "object" ? "object" : "inlineSpread",
children: (0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
typed: true,
casing: paramsCasing
}),
default: (0, _kubb_oas.isAllOptional)(typeSchemas.pathParams?.schema) ? "{}" : void 0
} : void 0,
data: typeSchemas.request?.name ? {
type: typeSchemas.request?.name,
optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
} : void 0,
params: typeSchemas.queryParams?.name ? {
type: typeSchemas.queryParams?.name,
optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
} : void 0,
headers: typeSchemas.headerParams?.name ? {
type: typeSchemas.headerParams?.name,
optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
} : void 0,
options: {
type: "Partial<Cypress.RequestOptions>",
default: "{}"
}
});
}
function Request({ baseURL = "", name, dataReturnType, typeSchemas, url, method, paramsType, paramsCasing, pathParamsType }) {
const path = new _kubb_core_utils.URLPath(url, { casing: paramsCasing });
const params = getParams({
paramsType,
paramsCasing,
pathParamsType,
typeSchemas
});
const returnType = dataReturnType === "data" ? `Cypress.Chainable<${typeSchemas.response.name}>` : `Cypress.Chainable<Cypress.Response<${typeSchemas.response.name}>>`;
const urlTemplate = path.toTemplateString({ prefix: baseURL });
const requestOptions = [`method: '${method}'`, `url: ${urlTemplate}`];
if (typeSchemas.queryParams?.name) requestOptions.push("qs: params");
if (typeSchemas.headerParams?.name) requestOptions.push("headers");
if (typeSchemas.request?.name) requestOptions.push("body: data");
requestOptions.push("...options");
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
name,
isIndexable: true,
isExportable: true,
children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function, {
name,
export: true,
params: params.toConstructor(),
returnType,
children: dataReturnType === "data" ? `return cy.request<${typeSchemas.response.name}>({
${requestOptions.join(",\n ")}
}).then((res) => res.body)` : `return cy.request<${typeSchemas.response.name}>({
${requestOptions.join(",\n ")}
})`
})
});
}
Request.getParams = getParams;
//#endregion
Object.defineProperty(exports, 'Request', {
enumerable: true,
get: function () {
return Request;
}
});
Object.defineProperty(exports, '__name', {
enumerable: true,
get: function () {
return __name;
}
});
Object.defineProperty(exports, '__toESM', {
enumerable: true,
get: function () {
return __toESM;
}
});
//# sourceMappingURL=components-CI2gDAda.cjs.map