@kubb/plugin-cypress 5.0.0-alpha.9 → 5.0.0-beta.100
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +17 -10
- package/README.md +38 -23
- package/dist/index.cjs +401 -63
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +130 -6
- package/dist/index.js +394 -63
- package/dist/index.js.map +1 -1
- package/package.json +38 -77
- package/dist/components-BK_6GU4v.js +0 -257
- package/dist/components-BK_6GU4v.js.map +0 -1
- package/dist/components-Drg_gLu2.cjs +0 -305
- package/dist/components-Drg_gLu2.cjs.map +0 -1
- package/dist/components.cjs +0 -3
- package/dist/components.d.ts +0 -50
- package/dist/components.js +0 -2
- package/dist/generators-B3FWG2Ck.js +0 -71
- package/dist/generators-B3FWG2Ck.js.map +0 -1
- package/dist/generators-C73nd-xB.cjs +0 -75
- package/dist/generators-C73nd-xB.cjs.map +0 -1
- package/dist/generators.cjs +0 -3
- package/dist/generators.d.ts +0 -505
- package/dist/generators.js +0 -2
- package/dist/types-DGvL0jsn.d.ts +0 -85
- package/src/components/Request.tsx +0 -147
- package/src/components/index.ts +0 -1
- package/src/generators/cypressGenerator.tsx +0 -66
- package/src/generators/index.ts +0 -1
- package/src/index.ts +0 -2
- package/src/plugin.ts +0 -119
- package/src/types.ts +0 -83
- /package/dist/{chunk--u3MIqq1.js → rolldown-runtime-C0LytTxp.js} +0 -0
package/LICENSE
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
MIT License
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Copyright (c) 2026 Kubb Labs
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
7
11
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
— see licenses/LICENSE-AGPL-3.0 for the full license text:
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<h1>Plugin Cypress</h1>
|
|
3
2
|
<a href="https://kubb.dev" target="_blank" rel="noopener noreferrer">
|
|
4
|
-
<img
|
|
3
|
+
<img src="https://kubb.dev/og.png" alt="Kubb banner">
|
|
5
4
|
</a>
|
|
6
5
|
|
|
7
|
-
|
|
8
6
|
[![npm version][npm-version-src]][npm-version-href]
|
|
9
7
|
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
10
|
-
[![
|
|
8
|
+
[![Stars][stars-src]][stars-href]
|
|
11
9
|
[![License][license-src]][license-href]
|
|
12
|
-
[![
|
|
10
|
+
[![Node][node-src]][node-href]
|
|
11
|
+
|
|
13
12
|
<h4>
|
|
14
|
-
<a href="https://
|
|
15
|
-
<span> · </span>
|
|
16
|
-
<a href="https://kubb.dev/" target="_blank">Documentation</a>
|
|
13
|
+
<a href="https://kubb.dev/plugins/cypress" target="_blank">Documentation</a>
|
|
17
14
|
<span> · </span>
|
|
18
15
|
<a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Report Bug</a>
|
|
19
16
|
<span> · </span>
|
|
@@ -21,12 +18,31 @@
|
|
|
21
18
|
</h4>
|
|
22
19
|
</div>
|
|
23
20
|
|
|
24
|
-
|
|
21
|
+
<br />
|
|
22
|
+
|
|
23
|
+
# @kubb/plugin-cypress
|
|
24
|
+
|
|
25
|
+
### Generate Cypress commands with Kubb
|
|
25
26
|
|
|
27
|
+
`@kubb/plugin-cypress` generates Cypress request commands with Kubb. Each operation becomes a typed Cypress command, ready to use in your test files.
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
bun add @kubb/plugin-cypress
|
|
33
|
+
# or
|
|
34
|
+
pnpm add @kubb/plugin-cypress
|
|
35
|
+
# or
|
|
36
|
+
npm install @kubb/plugin-cypress
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Documentation
|
|
40
|
+
|
|
41
|
+
See the [full documentation](https://kubb.dev/plugins/cypress) for configuration options and examples.
|
|
26
42
|
|
|
27
43
|
## Supporting Kubb
|
|
28
44
|
|
|
29
|
-
Kubb
|
|
45
|
+
Kubb is an open source project, and its development is funded entirely by sponsors. If you would like to become a sponsor, please consider:
|
|
30
46
|
|
|
31
47
|
- [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
|
|
32
48
|
|
|
@@ -36,20 +52,19 @@ Kubb uses an MIT-licensed open source project with its ongoing development made
|
|
|
36
52
|
</a>
|
|
37
53
|
</p>
|
|
38
54
|
|
|
55
|
+
## License
|
|
56
|
+
|
|
57
|
+
[MIT](https://github.com/kubb-labs/plugins/blob/main/LICENSE)
|
|
39
58
|
|
|
40
59
|
<!-- Badges -->
|
|
41
60
|
|
|
42
|
-
[npm-version-src]: https://
|
|
43
|
-
[npm-version-href]: https://
|
|
44
|
-
[npm-downloads-src]: https://
|
|
45
|
-
[npm-downloads-href]: https://
|
|
46
|
-
[
|
|
61
|
+
[npm-version-src]: https://shieldcn.dev/npm/v/@kubb/plugin-cypress.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
62
|
+
[npm-version-href]: https://npmx.dev/package/@kubb/plugin-cypress
|
|
63
|
+
[npm-downloads-src]: https://shieldcn.dev/npm/dm/@kubb/plugin-cypress.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
64
|
+
[npm-downloads-href]: https://npmx.dev/package/@kubb/plugin-cypress
|
|
65
|
+
[stars-src]: https://shieldcn.dev/github/stars/kubb-labs/kubb.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
66
|
+
[stars-href]: https://github.com/kubb-labs/kubb
|
|
67
|
+
[license-src]: https://shieldcn.dev/npm/license/@kubb/plugin-cypress.svg?variant=secondary&size=xs&theme=zinc
|
|
47
68
|
[license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE
|
|
48
|
-
[
|
|
49
|
-
[
|
|
50
|
-
[minified-src]: https://img.shields.io/bundlephobia/min/@kubb/plugin-cypress?style=flat&colorA=18181B&colorB=f58517
|
|
51
|
-
[minified-href]: https://www.npmjs.com/package/@kubb/plugin-cypress
|
|
52
|
-
[coverage-src]: https://img.shields.io/codecov/c/github/kubb-labs/kubb?style=flat&colorA=18181B&colorB=f58517
|
|
53
|
-
[coverage-href]: https://www.npmjs.com/package/@kubb/plugin-cypress
|
|
54
|
-
[sponsors-src]: https://img.shields.io/github/sponsors/stijnvanhulle?style=flat&colorA=18181B&colorB=f58517
|
|
55
|
-
[sponsors-href]: https://github.com/sponsors/stijnvanhulle/
|
|
69
|
+
[node-src]: https://shieldcn.dev/npm/node/@kubb/plugin-cypress.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
70
|
+
[node-href]: https://npmx.dev/package/@kubb/plugin-cypress
|
package/dist/index.cjs
CHANGED
|
@@ -1,81 +1,419 @@
|
|
|
1
|
-
Object.
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
let
|
|
7
|
-
let
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
5
|
+
//#endregion
|
|
6
|
+
let kubb_kit = require("kubb/kit");
|
|
7
|
+
let kubb_jsx = require("kubb/jsx");
|
|
8
|
+
let kubb_jsx_jsx_runtime = require("kubb/jsx/jsx-runtime");
|
|
8
9
|
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
10
|
+
//#region ../../internals/shared/src/params.ts
|
|
11
|
+
/**
|
|
12
|
+
* Drops parameters that share the same name, keeping the first.
|
|
13
|
+
*
|
|
14
|
+
* A malformed spec can declare the same parameter name twice within one `in` location. Both would
|
|
15
|
+
* resolve to the same output property, so emitting both would yield an object type with a duplicate
|
|
16
|
+
* member, which TypeScript rejects. This is a defensive guard against that case, not a casing guard:
|
|
17
|
+
* parameter names flow through unchanged, so no two distinct names ever collide here anymore.
|
|
18
|
+
*/
|
|
19
|
+
function dedupeParams(params) {
|
|
20
|
+
const seen = /* @__PURE__ */ new Set();
|
|
21
|
+
return params.filter((param) => {
|
|
22
|
+
if (seen.has(param.name)) return false;
|
|
23
|
+
seen.add(param.name);
|
|
24
|
+
return true;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region ../../internals/shared/src/operation.ts
|
|
29
|
+
/**
|
|
30
|
+
* Derives the shared `ContentTypeInfo` shape from a list of content types, tracking whether several
|
|
31
|
+
* are present and the union, default, and form-data flags the client uses to pick one.
|
|
32
|
+
*/
|
|
33
|
+
function buildContentTypeInfo(contentTypes) {
|
|
34
|
+
const isMultipleContentTypes = contentTypes.length > 1;
|
|
35
|
+
return {
|
|
36
|
+
contentTypes,
|
|
37
|
+
isMultipleContentTypes,
|
|
38
|
+
contentTypeUnion: isMultipleContentTypes ? contentTypes.map((ct) => JSON.stringify(ct)).join(" | ") : "",
|
|
39
|
+
defaultContentType: contentTypes[0] ?? "application/json",
|
|
40
|
+
hasFormData: contentTypes.some((ct) => ct === "multipart/form-data")
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function getContentTypeInfo(node) {
|
|
44
|
+
return buildContentTypeInfo(node.requestBody?.content?.map((e) => e.contentType) ?? []);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The request-body counterpart for the primary success response: the content types it documents and
|
|
48
|
+
* whether several are present, so the client can let a caller pick which one to accept.
|
|
49
|
+
*/
|
|
50
|
+
function getResponseContentTypeInfo(node) {
|
|
51
|
+
return buildContentTypeInfo(getPrimarySuccessResponse(node)?.content?.map((e) => e.contentType) ?? []);
|
|
52
|
+
}
|
|
53
|
+
function buildRequestConfigType(node) {
|
|
54
|
+
const request = getContentTypeInfo(node);
|
|
55
|
+
const response = getResponseContentTypeInfo(node);
|
|
56
|
+
const configType = `Partial<Omit<RequestConfig, 'path' | 'query' | 'body' | 'headers' | 'url'>>`;
|
|
57
|
+
const members = [request.isMultipleContentTypes ? `request?: ${request.contentTypeUnion}` : null, response.isMultipleContentTypes ? `response?: ${response.contentTypeUnion}` : null].filter(Boolean);
|
|
58
|
+
return members.length ? `${configType} & { contentType?: { ${members.join("; ")} } }` : configType;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Which of the grouped request options an operation carries.
|
|
62
|
+
*/
|
|
63
|
+
function getRequestGroups(node) {
|
|
64
|
+
const { path, query, header } = getOperationParameters(node);
|
|
65
|
+
return {
|
|
66
|
+
path: path.length > 0,
|
|
67
|
+
query: query.length > 0,
|
|
68
|
+
body: Boolean(node.requestBody?.content?.[0]?.schema),
|
|
69
|
+
headers: header.length > 0
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Resolves which grouped request options an operation carries together with whether each group
|
|
74
|
+
* holds a required member. The grouped parameter stays optional only when nothing inside it is
|
|
75
|
+
* required, matching the generated `RequestConfig` type.
|
|
76
|
+
*/
|
|
77
|
+
function getRequestGroupOptionality(node) {
|
|
78
|
+
const groups = getRequestGroups(node);
|
|
79
|
+
const { path, query, header } = getOperationParameters(node);
|
|
80
|
+
const hasRequiredPath = path.some((param) => param.required);
|
|
81
|
+
const hasRequiredQuery = query.some((param) => param.required);
|
|
82
|
+
const hasRequiredHeader = header.some((param) => param.required);
|
|
83
|
+
return {
|
|
84
|
+
groups,
|
|
85
|
+
hasRequiredPath,
|
|
86
|
+
hasRequiredQuery,
|
|
87
|
+
hasRequiredHeader,
|
|
88
|
+
isOptional: !hasRequiredPath && !hasRequiredQuery && !hasRequiredHeader && !groups.body
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Builds the grouped `{ path, query, body, headers }` parameter for a generated client
|
|
93
|
+
* function, typed from the operation's `Options` (minus `url`). Only the groups the
|
|
94
|
+
* operation actually has are destructured. The trailing `config` parameter carries the
|
|
95
|
+
* runtime `RequestConfig` overrides plus `client`.
|
|
96
|
+
*/
|
|
97
|
+
function buildRequestParamsSignature(node, resolver, options = {}) {
|
|
98
|
+
const { isConfigurable = true } = options;
|
|
99
|
+
const { groups, isOptional } = getRequestGroupOptionality(node);
|
|
100
|
+
const names = [
|
|
101
|
+
"path",
|
|
102
|
+
"query",
|
|
103
|
+
"body",
|
|
104
|
+
"headers"
|
|
105
|
+
].filter((key) => groups[key]);
|
|
106
|
+
return {
|
|
107
|
+
signature: [names.length > 0 ? `{ ${names.join(", ")} }: ${resolver.response.options(node)}${isOptional ? " = {}" : ""}` : null, isConfigurable ? `config: ${buildRequestConfigType(node)} = {}` : null].filter(Boolean).join(", "),
|
|
108
|
+
groups
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function getOperationParameters(node) {
|
|
112
|
+
return {
|
|
113
|
+
path: dedupeParams(node.parameters.filter((param) => param.in === "path")),
|
|
114
|
+
query: dedupeParams(node.parameters.filter((param) => param.in === "query")),
|
|
115
|
+
header: dedupeParams(node.parameters.filter((param) => param.in === "header")),
|
|
116
|
+
cookie: dedupeParams(node.parameters.filter((param) => param.in === "cookie"))
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function getStatusCodeNumber(statusCode) {
|
|
120
|
+
const code = Number(statusCode);
|
|
121
|
+
return Number.isNaN(code) ? null : code;
|
|
122
|
+
}
|
|
123
|
+
function isSuccessStatusCode(statusCode) {
|
|
124
|
+
const code = getStatusCodeNumber(statusCode);
|
|
125
|
+
return code !== null && code >= 200 && code < 300;
|
|
126
|
+
}
|
|
127
|
+
function isErrorStatusCode(statusCode) {
|
|
128
|
+
const code = getStatusCodeNumber(statusCode);
|
|
129
|
+
return code !== null && code >= 400;
|
|
130
|
+
}
|
|
131
|
+
function getSuccessResponses(responses) {
|
|
132
|
+
return responses.filter((response) => isSuccessStatusCode(response.statusCode));
|
|
133
|
+
}
|
|
134
|
+
function getOperationSuccessResponses(node) {
|
|
135
|
+
return getSuccessResponses(node.responses);
|
|
136
|
+
}
|
|
137
|
+
function getPrimarySuccessResponse(node) {
|
|
138
|
+
return getOperationSuccessResponses(node)[0] ?? null;
|
|
139
|
+
}
|
|
140
|
+
function resolveErrorNames(node, resolver) {
|
|
141
|
+
return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.response.status(node, response.statusCode));
|
|
142
|
+
}
|
|
143
|
+
function resolveStatusCodeNames(node, resolver) {
|
|
144
|
+
return node.responses.map((response) => resolver.response.status(node, response.statusCode));
|
|
145
|
+
}
|
|
146
|
+
const typeNamesByResolver = /* @__PURE__ */ new WeakMap();
|
|
147
|
+
function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
148
|
+
const cacheKey = `${node.operationId}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${options.includeParams === false ? "noparams" : ""}\0${(options.exclude ?? []).join(",")}`;
|
|
149
|
+
let byResolver = typeNamesByResolver.get(resolver);
|
|
150
|
+
if (byResolver) {
|
|
151
|
+
const cached = byResolver.get(cacheKey);
|
|
152
|
+
if (cached) return cached;
|
|
153
|
+
} else {
|
|
154
|
+
byResolver = /* @__PURE__ */ new Map();
|
|
155
|
+
typeNamesByResolver.set(resolver, byResolver);
|
|
156
|
+
}
|
|
157
|
+
const { path, query, header } = getOperationParameters(node);
|
|
158
|
+
const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
|
|
159
|
+
const exclude = new Set(options.exclude ?? []);
|
|
160
|
+
const paramNames = options.includeParams === false ? [] : [
|
|
161
|
+
...path.map((param) => resolver.param.path(node, param)),
|
|
162
|
+
...query.map((param) => resolver.param.query(node, param)),
|
|
163
|
+
...header.map((param) => resolver.param.headers(node, param))
|
|
164
|
+
];
|
|
165
|
+
const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.response.body(node) : null, resolver.response.response(node)];
|
|
166
|
+
const result = (options.order === "body-response-first" ? [
|
|
167
|
+
...bodyAndResponseNames,
|
|
168
|
+
...paramNames,
|
|
169
|
+
...responseStatusNames
|
|
170
|
+
] : [
|
|
171
|
+
...paramNames,
|
|
172
|
+
...bodyAndResponseNames,
|
|
173
|
+
...responseStatusNames
|
|
174
|
+
]).filter((name) => Boolean(name) && !exclude.has(name));
|
|
175
|
+
byResolver.set(cacheKey, result);
|
|
176
|
+
return result;
|
|
177
|
+
}
|
|
178
|
+
//#endregion
|
|
179
|
+
//#region ../../internals/utils/src/casing.ts
|
|
180
|
+
/**
|
|
181
|
+
* Shared implementation for camelCase and PascalCase conversion.
|
|
182
|
+
* Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
|
|
183
|
+
* and capitalizes each word according to `pascal`.
|
|
184
|
+
*
|
|
185
|
+
* When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
|
|
186
|
+
*/
|
|
187
|
+
function toCamelOrPascal(text, pascal) {
|
|
188
|
+
return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
|
|
189
|
+
if (word.length > 1 && word === word.toUpperCase()) return word;
|
|
190
|
+
return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
|
|
191
|
+
}).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Converts `text` to camelCase.
|
|
195
|
+
*
|
|
196
|
+
* @example Word boundaries
|
|
197
|
+
* `camelCase('hello-world') // 'helloWorld'`
|
|
198
|
+
*
|
|
199
|
+
* @example With a prefix
|
|
200
|
+
* `camelCase('tag', { prefix: 'create' }) // 'createTag'`
|
|
201
|
+
*/
|
|
202
|
+
function camelCase(text, { prefix = "", suffix = "" } = {}) {
|
|
203
|
+
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
204
|
+
}
|
|
205
|
+
//#endregion
|
|
206
|
+
//#region ../../internals/shared/src/group.ts
|
|
207
|
+
/**
|
|
208
|
+
* Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the
|
|
209
|
+
* shared default naming so every plugin groups output consistently:
|
|
210
|
+
*
|
|
211
|
+
* - `path` groups use the second path segment (`/pet/findByStatus` → `pet`).
|
|
212
|
+
* - other groups use the camelCased group (`pet store` → `petStore`).
|
|
213
|
+
*
|
|
214
|
+
* A user-provided `group.name` always wins over the default namer, so callers stay in
|
|
215
|
+
* control of their output folders. Returns `null` when grouping is disabled, matching the
|
|
216
|
+
* per-plugin convention.
|
|
217
|
+
*
|
|
218
|
+
* @param group - The user-supplied group option, or `undefined` to disable grouping.
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```ts
|
|
222
|
+
* createGroupConfig(group) // shared across every plugin
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
function createGroupConfig(group) {
|
|
226
|
+
if (!group) return null;
|
|
227
|
+
const defaultName = (ctx) => {
|
|
228
|
+
if (group.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
229
|
+
return camelCase(ctx.group);
|
|
230
|
+
};
|
|
231
|
+
return {
|
|
232
|
+
...group,
|
|
233
|
+
name: group.name ? group.name : defaultName
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
//#endregion
|
|
237
|
+
//#region src/components/Request.tsx
|
|
238
|
+
function Request({ baseURL = "", name, resolver, node }) {
|
|
239
|
+
if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
|
|
240
|
+
const { signature, groups } = buildRequestParamsSignature(node, resolver, { isConfigurable: false });
|
|
241
|
+
const paramsSignature = [signature, "options: Partial<Cypress.RequestOptions> = {}"].filter(Boolean).join(", ");
|
|
242
|
+
const responseType = resolver.response.response(node);
|
|
243
|
+
const returnType = `Cypress.Chainable<${responseType}>`;
|
|
244
|
+
const urlTemplate = kubb_kit.Url.toGroupedTemplateString(node.path, { prefix: baseURL });
|
|
245
|
+
const requestOptions = [`method: '${node.method}'`, `url: ${urlTemplate}`];
|
|
246
|
+
if (groups.query) requestOptions.push("qs: query");
|
|
247
|
+
if (groups.headers) requestOptions.push("headers");
|
|
248
|
+
if (groups.body) requestOptions.push("body");
|
|
249
|
+
requestOptions.push("...options");
|
|
250
|
+
const requestCall = `return cy.request<${responseType}>({
|
|
251
|
+
${requestOptions.join(",\n ")}
|
|
252
|
+
}).then((res) => res.body)`;
|
|
253
|
+
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
254
|
+
name,
|
|
255
|
+
isIndexable: true,
|
|
256
|
+
isExportable: true,
|
|
257
|
+
children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function, {
|
|
258
|
+
name,
|
|
259
|
+
export: true,
|
|
260
|
+
params: paramsSignature,
|
|
261
|
+
returnType,
|
|
262
|
+
children: requestCall
|
|
263
|
+
})
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
//#endregion
|
|
267
|
+
//#region src/generators/cypressGenerator.tsx
|
|
268
|
+
/**
|
|
269
|
+
* Built-in generator for `@kubb/plugin-cypress`. Emits one typed
|
|
270
|
+
* `cy.request()` wrapper per OpenAPI operation, ready to call inside Cypress
|
|
271
|
+
* test specs and custom commands.
|
|
272
|
+
*/
|
|
273
|
+
const cypressGenerator = (0, kubb_kit.defineGenerator)({
|
|
274
|
+
name: "cypress",
|
|
275
|
+
renderer: kubb_jsx.jsxRenderer,
|
|
276
|
+
operation(node, ctx) {
|
|
277
|
+
if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
|
|
278
|
+
const { config, resolver, driver, root } = ctx;
|
|
279
|
+
const { output, baseURL, group } = ctx.options;
|
|
280
|
+
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
281
|
+
if (!pluginTs) return null;
|
|
282
|
+
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
283
|
+
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, { includeParams: false })];
|
|
284
|
+
const meta = {
|
|
285
|
+
name: resolver.name(node.operationId),
|
|
286
|
+
file: resolver.file({
|
|
287
|
+
name: node.operationId,
|
|
288
|
+
extname: ".ts",
|
|
289
|
+
tag: node.tags[0] ?? "default",
|
|
290
|
+
path: node.path,
|
|
291
|
+
root,
|
|
292
|
+
output,
|
|
293
|
+
group: group ?? void 0
|
|
294
|
+
}),
|
|
295
|
+
fileTs: tsResolver.file({
|
|
296
|
+
name: node.operationId,
|
|
297
|
+
extname: ".ts",
|
|
298
|
+
tag: node.tags[0] ?? "default",
|
|
299
|
+
path: node.path,
|
|
300
|
+
root,
|
|
301
|
+
output: pluginTs.options?.output ?? output,
|
|
302
|
+
group: pluginTs.options?.group ?? void 0
|
|
303
|
+
})
|
|
304
|
+
};
|
|
305
|
+
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File, {
|
|
306
|
+
baseName: meta.file.baseName,
|
|
307
|
+
path: meta.file.path,
|
|
308
|
+
meta: meta.file.meta,
|
|
309
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
310
|
+
output,
|
|
311
|
+
config,
|
|
312
|
+
file: {
|
|
313
|
+
path: meta.file.path,
|
|
314
|
+
baseName: meta.file.baseName
|
|
315
|
+
}
|
|
316
|
+
}),
|
|
317
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
318
|
+
output,
|
|
319
|
+
config,
|
|
320
|
+
file: {
|
|
321
|
+
path: meta.file.path,
|
|
322
|
+
baseName: meta.file.baseName
|
|
323
|
+
}
|
|
324
|
+
}),
|
|
325
|
+
children: [importedTypeNames.length > 0 && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
326
|
+
name: importedTypeNames,
|
|
327
|
+
root: meta.file.path,
|
|
328
|
+
path: meta.fileTs.path,
|
|
329
|
+
isTypeOnly: true
|
|
330
|
+
}), /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(Request, {
|
|
331
|
+
name: meta.name,
|
|
332
|
+
node,
|
|
333
|
+
resolver: tsResolver,
|
|
334
|
+
baseURL
|
|
335
|
+
})]
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
//#endregion
|
|
340
|
+
//#region src/resolvers/resolverCypress.ts
|
|
341
|
+
/**
|
|
342
|
+
* Default resolver used by `@kubb/plugin-cypress`. Decides the names and file
|
|
343
|
+
* paths for every generated `cy.request()` wrapper. Functions and files use
|
|
344
|
+
* camelCase, matching the convention from `@kubb/plugin-axios` and `@kubb/plugin-fetch`.
|
|
345
|
+
*
|
|
346
|
+
* @example Resolve a helper name
|
|
347
|
+
* ```ts
|
|
348
|
+
* import { resolverCypress } from '@kubb/plugin-cypress'
|
|
349
|
+
*
|
|
350
|
+
* resolverCypress.name('list pets') // 'listPets'
|
|
351
|
+
* ```
|
|
352
|
+
*/
|
|
353
|
+
const resolverCypress = (0, kubb_kit.createResolver)({ pluginName: "plugin-cypress" });
|
|
354
|
+
//#endregion
|
|
9
355
|
//#region src/plugin.ts
|
|
356
|
+
/**
|
|
357
|
+
* Canonical plugin name for `@kubb/plugin-cypress`. Used for driver lookups and
|
|
358
|
+
* cross-plugin dependency references.
|
|
359
|
+
*/
|
|
10
360
|
const pluginCypressName = "plugin-cypress";
|
|
11
|
-
|
|
361
|
+
/**
|
|
362
|
+
* Generates one typed `cy.request()` wrapper per OpenAPI operation. Each helper
|
|
363
|
+
* has typed path params, body, query, and a typed response, so failing API
|
|
364
|
+
* calls in Cypress show up at compile time instead of inside the test runner.
|
|
365
|
+
*
|
|
366
|
+
* @example
|
|
367
|
+
* ```ts
|
|
368
|
+
* import { defineConfig } from 'kubb/config'
|
|
369
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
370
|
+
* import { pluginCypress } from '@kubb/plugin-cypress'
|
|
371
|
+
*
|
|
372
|
+
* export default defineConfig({
|
|
373
|
+
* input: './petStore.yaml',
|
|
374
|
+
* output: { path: './src/gen' },
|
|
375
|
+
* plugins: [
|
|
376
|
+
* pluginTs(),
|
|
377
|
+
* pluginCypress({
|
|
378
|
+
* output: { path: './cypress' },
|
|
379
|
+
* }),
|
|
380
|
+
* ],
|
|
381
|
+
* })
|
|
382
|
+
* ```
|
|
383
|
+
*/
|
|
384
|
+
const pluginCypress = (0, kubb_kit.definePlugin)((options) => {
|
|
12
385
|
const { output = {
|
|
13
386
|
path: "cypress",
|
|
14
|
-
|
|
15
|
-
}, group,
|
|
387
|
+
barrel: { type: "named" }
|
|
388
|
+
}, group, exclude = [], include, override = [], baseURL, resolver: userResolver, macros: userMacros } = options;
|
|
389
|
+
const groupConfig = createGroupConfig(group);
|
|
16
390
|
return {
|
|
17
391
|
name: pluginCypressName,
|
|
18
|
-
options
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
paramsType,
|
|
25
|
-
pathParamsType
|
|
26
|
-
},
|
|
27
|
-
pre: [_kubb_plugin_oas.pluginOasName, _kubb_plugin_ts.pluginTsName].filter(Boolean),
|
|
28
|
-
resolvePath(baseName, pathMode, options) {
|
|
29
|
-
const root = node_path.default.resolve(this.config.root, this.config.output.path);
|
|
30
|
-
if ((pathMode ?? (0, _kubb_core.getMode)(node_path.default.resolve(root, output.path))) === "single")
|
|
31
|
-
/**
|
|
32
|
-
* when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
|
|
33
|
-
* Other plugins then need to call addOrAppend instead of just add from the fileManager class
|
|
34
|
-
*/
|
|
35
|
-
return node_path.default.resolve(root, output.path);
|
|
36
|
-
if (group && (options?.group?.path || options?.group?.tag)) {
|
|
37
|
-
const groupName = group?.name ? group.name : (ctx) => {
|
|
38
|
-
if (group?.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
39
|
-
return `${require_components.camelCase(ctx.group)}Requests`;
|
|
40
|
-
};
|
|
41
|
-
return node_path.default.resolve(root, output.path, groupName({ group: group.type === "path" ? options.group.path : options.group.tag }), baseName);
|
|
42
|
-
}
|
|
43
|
-
return node_path.default.resolve(root, output.path, baseName);
|
|
44
|
-
},
|
|
45
|
-
resolveName(name, type) {
|
|
46
|
-
const resolvedName = require_components.camelCase(name, { isFile: type === "file" });
|
|
47
|
-
if (type) return transformers?.name?.(resolvedName, type) || resolvedName;
|
|
48
|
-
return resolvedName;
|
|
49
|
-
},
|
|
50
|
-
async install() {
|
|
51
|
-
const root = node_path.default.resolve(this.config.root, this.config.output.path);
|
|
52
|
-
const mode = (0, _kubb_core.getMode)(node_path.default.resolve(root, output.path));
|
|
53
|
-
const oas = await this.getOas();
|
|
54
|
-
const files = await new _kubb_plugin_oas.OperationGenerator(this.plugin.options, {
|
|
55
|
-
fabric: this.fabric,
|
|
56
|
-
oas,
|
|
57
|
-
driver: this.driver,
|
|
58
|
-
events: this.events,
|
|
59
|
-
plugin: this.plugin,
|
|
60
|
-
contentType,
|
|
392
|
+
options,
|
|
393
|
+
dependencies: [_kubb_plugin_ts.pluginTsName],
|
|
394
|
+
hooks: { "kubb:plugin:setup"(ctx) {
|
|
395
|
+
const resolver = userResolver ? kubb_kit.Resolver.merge(resolverCypress, userResolver) : resolverCypress;
|
|
396
|
+
ctx.setOptions({
|
|
397
|
+
output,
|
|
61
398
|
exclude,
|
|
62
399
|
include,
|
|
63
400
|
override,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const barrelFiles = await (0, _kubb_core.getBarrelFiles)(this.fabric.files, {
|
|
68
|
-
type: output.barrelType ?? "named",
|
|
69
|
-
root,
|
|
70
|
-
output,
|
|
71
|
-
meta: { pluginName: this.plugin.name }
|
|
401
|
+
group: groupConfig,
|
|
402
|
+
baseURL,
|
|
403
|
+
resolver
|
|
72
404
|
});
|
|
73
|
-
|
|
74
|
-
|
|
405
|
+
ctx.setResolver(resolver);
|
|
406
|
+
if (userMacros?.length) ctx.setMacros(userMacros);
|
|
407
|
+
ctx.addGenerator(cypressGenerator);
|
|
408
|
+
} }
|
|
75
409
|
};
|
|
76
410
|
});
|
|
77
411
|
//#endregion
|
|
412
|
+
exports.Request = Request;
|
|
413
|
+
exports.cypressGenerator = cypressGenerator;
|
|
414
|
+
exports.default = pluginCypress;
|
|
78
415
|
exports.pluginCypress = pluginCypress;
|
|
79
416
|
exports.pluginCypressName = pluginCypressName;
|
|
417
|
+
exports.resolverCypress = resolverCypress;
|
|
80
418
|
|
|
81
419
|
//# sourceMappingURL=index.cjs.map
|