@kubb/plugin-cypress
Version:
Cypress test generator plugin for Kubb, creating end-to-end tests from OpenAPI specifications for automated API testing.
98 lines (96 loc) • 3.13 kB
JavaScript
import { cypressGenerator } from './chunk-PIJKOKJD.js';
import './chunk-NEMUYKDD.js';
import path from 'path';
import { createPlugin, PluginManager, FileManager } from '@kubb/core';
import { camelCase } from '@kubb/core/transformers';
import { pluginOasName, OperationGenerator } from '@kubb/plugin-oas';
import { pluginTsName } from '@kubb/plugin-ts';
var pluginCypressName = "plugin-cypress";
var pluginCypress = createPlugin((options) => {
const {
output = { path: "cypress", barrelType: "named" },
group,
dataReturnType = "data",
exclude = [],
include,
override = [],
transformers = {},
generators = [cypressGenerator].filter(Boolean),
contentType,
baseURL
} = options;
return {
name: pluginCypressName,
options: {
output,
dataReturnType,
group,
baseURL
},
pre: [pluginOasName, pluginTsName].filter(Boolean),
resolvePath(baseName, pathMode, options2) {
const root = path.resolve(this.config.root, this.config.output.path);
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
if (mode === "single") {
return path.resolve(root, output.path);
}
if (group && (options2?.group?.path || options2?.group?.tag)) {
const groupName = group?.name ? group.name : (ctx) => {
if (group?.type === "path") {
return `${ctx.group.split("/")[1]}`;
}
return `${camelCase(ctx.group)}Requests`;
};
return path.resolve(
root,
output.path,
groupName({
group: group.type === "path" ? options2.group.path : options2.group.tag
}),
baseName
);
}
return path.resolve(root, output.path, baseName);
},
resolveName(name, type) {
const resolvedName = camelCase(name, {
isFile: type === "file"
});
if (type) {
return transformers?.name?.(resolvedName, type) || resolvedName;
}
return resolvedName;
},
async buildStart() {
const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
const oas = await swaggerPlugin.context.getOas();
const root = path.resolve(this.config.root, this.config.output.path);
const mode = FileManager.getMode(path.resolve(root, output.path));
const operationGenerator = new OperationGenerator(this.plugin.options, {
oas,
pluginManager: this.pluginManager,
plugin: this.plugin,
contentType,
exclude,
include,
override,
mode
});
const files = await operationGenerator.build(...generators);
await this.addFile(...files);
const barrelFiles = await this.fileManager.getBarrelFiles({
type: output.barrelType ?? "named",
root,
output,
meta: {
pluginKey: this.plugin.key
},
logger: this.logger
});
await this.addFile(...barrelFiles);
}
};
});
export { pluginCypress, pluginCypressName };
//# sourceMappingURL=index.js.map
//# sourceMappingURL=index.js.map