@kubb/plugin-cypress
Version:
Cypress test generator plugin for Kubb, creating end-to-end tests from OpenAPI specifications for automated API testing.
71 lines (69 loc) • 2.17 kB
JavaScript
import { t as Request } from "./components-ByyhXRwB.js";
import { pluginTsName } from "@kubb/plugin-ts";
import { usePluginManager } from "@kubb/core/hooks";
import { createReactGenerator } from "@kubb/plugin-oas/generators";
import { useOas, useOperationManager } from "@kubb/plugin-oas/hooks";
import { getBanner, getFooter } from "@kubb/plugin-oas/utils";
import { File } from "@kubb/react-fabric";
import { jsx, jsxs } from "@kubb/react-fabric/jsx-runtime";
//#region src/generators/cypressGenerator.tsx
const cypressGenerator = createReactGenerator({
name: "cypress",
Operation({ operation, generator, plugin }) {
const { options: { output, baseURL, dataReturnType, paramsCasing, paramsType, pathParamsType } } = plugin;
const pluginManager = usePluginManager();
const oas = useOas();
const { getSchemas, getName, getFile } = useOperationManager(generator);
const request = {
name: getName(operation, { type: "function" }),
file: getFile(operation)
};
const type = {
file: getFile(operation, { pluginKey: [pluginTsName] }),
schemas: getSchemas(operation, {
pluginKey: [pluginTsName],
type: "type"
})
};
return /* @__PURE__ */ jsxs(File, {
baseName: request.file.baseName,
path: request.file.path,
meta: request.file.meta,
banner: getBanner({
oas,
output,
config: pluginManager.config
}),
footer: getFooter({
oas,
output
}),
children: [/* @__PURE__ */ jsx(File.Import, {
name: [
type.schemas.request?.name,
type.schemas.response.name,
type.schemas.pathParams?.name,
type.schemas.queryParams?.name,
type.schemas.headerParams?.name,
...type.schemas.statusCodes?.map((item) => item.name) || []
].filter(Boolean),
root: request.file.path,
path: type.file.path,
isTypeOnly: true
}), /* @__PURE__ */ jsx(Request, {
name: request.name,
dataReturnType,
paramsCasing,
paramsType,
pathParamsType,
typeSchemas: type.schemas,
method: operation.method,
baseURL,
url: operation.path
})]
});
}
});
//#endregion
export { cypressGenerator as t };
//# sourceMappingURL=generators-3ldN506W.js.map