UNPKG

@kubb/plugin-cypress

Version:

Cypress test generator plugin for Kubb, creating end-to-end tests from OpenAPI specifications for automated API testing.

82 lines (80 loc) 3.41 kB
const require_components = require('./components-CI2gDAda.cjs'); const require_generators = require('./generators-Dfxz9bL7.cjs'); let node_path = require("node:path"); node_path = require_components.__toESM(node_path); let _kubb_core = require("@kubb/core"); let _kubb_core_transformers = require("@kubb/core/transformers"); let _kubb_plugin_oas = require("@kubb/plugin-oas"); let _kubb_plugin_ts = require("@kubb/plugin-ts"); //#region src/plugin.ts const pluginCypressName = "plugin-cypress"; const pluginCypress = (0, _kubb_core.definePlugin)((options) => { const { output = { path: "cypress", barrelType: "named" }, group, dataReturnType = "data", exclude = [], include, override = [], transformers = {}, generators = [require_generators.cypressGenerator].filter(Boolean), contentType, baseURL, paramsCasing = "camelcase", paramsType = "inline", pathParamsType = paramsType === "object" ? "object" : options.pathParamsType || "inline" } = options; return { name: pluginCypressName, options: { output, dataReturnType, group, baseURL, paramsCasing, paramsType, pathParamsType }, pre: [_kubb_plugin_oas.pluginOasName, _kubb_plugin_ts.pluginTsName].filter(Boolean), resolvePath(baseName, pathMode, options$1) { const root = node_path.default.resolve(this.config.root, this.config.output.path); if ((pathMode ?? (0, _kubb_core.getMode)(node_path.default.resolve(root, output.path))) === "single") /** * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend * Other plugins then need to call addOrAppend instead of just add from the fileManager class */ return node_path.default.resolve(root, output.path); if (group && (options$1?.group?.path || options$1?.group?.tag)) { const groupName = group?.name ? group.name : (ctx) => { if (group?.type === "path") return `${ctx.group.split("/")[1]}`; return `${(0, _kubb_core_transformers.camelCase)(ctx.group)}Requests`; }; return node_path.default.resolve(root, output.path, groupName({ group: group.type === "path" ? options$1.group.path : options$1.group.tag }), baseName); } return node_path.default.resolve(root, output.path, baseName); }, resolveName(name, type) { const resolvedName = (0, _kubb_core_transformers.camelCase)(name, { isFile: type === "file" }); if (type) return transformers?.name?.(resolvedName, type) || resolvedName; return resolvedName; }, async install() { const root = node_path.default.resolve(this.config.root, this.config.output.path); const mode = (0, _kubb_core.getMode)(node_path.default.resolve(root, output.path)); const oas = await this.getOas(); const files = await new _kubb_plugin_oas.OperationGenerator(this.plugin.options, { fabric: this.fabric, oas, pluginManager: this.pluginManager, events: this.events, plugin: this.plugin, contentType, exclude, include, override, mode }).build(...generators); await this.upsertFile(...files); const barrelFiles = await (0, _kubb_core.getBarrelFiles)(this.fabric.files, { type: output.barrelType ?? "named", root, output, meta: { pluginKey: this.plugin.key } }); await this.upsertFile(...barrelFiles); } }; }); //#endregion exports.pluginCypress = pluginCypress; exports.pluginCypressName = pluginCypressName; //# sourceMappingURL=index.cjs.map