@kubb/plugin-cypress
Version:
Cypress test generator plugin for Kubb, creating end-to-end tests from OpenAPI specifications for automated API testing.
73 lines (71 loc) • 2.36 kB
JavaScript
import { Request } from './chunk-NEMUYKDD.js';
import { URLPath } from '@kubb/core/utils';
import { createReactGenerator } from '@kubb/plugin-oas';
import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks';
import { getFooter, getBanner } from '@kubb/plugin-oas/utils';
import { pluginTsName } from '@kubb/plugin-ts';
import { useApp, File } from '@kubb/react';
import { jsxs, jsx } from '@kubb/react/jsx-runtime';
var cypressGenerator = createReactGenerator({
name: "cypress",
Operation({ operation }) {
const {
pluginManager,
plugin: {
options: { output, baseURL, dataReturnType }
}
} = useApp();
const oas = useOas();
const { getSchemas, getName, getFile } = useOperationManager();
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,
typeSchemas: type.schemas,
method: operation.method,
baseURL,
url: new URLPath(operation.path).toURLPath()
}
)
]
}
);
}
});
export { cypressGenerator };
//# sourceMappingURL=chunk-PIJKOKJD.js.map
//# sourceMappingURL=chunk-PIJKOKJD.js.map