Skip to content

Commit 0bc628c

Browse files
Merge pull request #1580 from Ericlm/main
Cypress Plugin
2 parents d6f63aa + b7e531a commit 0bc628c

File tree

130 files changed

+4239
-86
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+4239
-86
lines changed

.changeset/angry-eggs-film.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@kubb/plugin-cypress": minor
3+
---
4+
5+
support for `cy.request` with new plugin `@kubb/plugin-cypress`

.changeset/happy-lands-kick.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@kubb/plugin-cypress": patch
3+
---
4+
5+
Add a Cypress plugin for generating cypress requests

.codesandbox/ci.json

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"packages/plugin-oas",
88
"packages/plugin-redoc",
99
"packages/plugin-client",
10+
"packages/plugin-cypress",
1011
"packages/plugin-faker",
1112
"packages/plugin-msw",
1213
"packages/plugin-swr",
@@ -21,6 +22,7 @@
2122
],
2223
"sandboxes": [
2324
"/examples/advanced",
25+
"/examples/cypress",
2426
"/examples/faker",
2527
"/examples/msw",
2628
"/examples/react-query",

docs/.vitepress/config.ts

+13
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ const mainSidebar = [
179179
},
180180
],
181181
},
182+
{
183+
text: '@kubb/plugin-cypress <span class="new">new in 3.7.0</span>',
184+
link: '/plugins/plugin-cypress/',
185+
},
182186
{
183187
text: '@kubb/plugin-client',
184188
link: '/plugins/plugin-client/',
@@ -301,6 +305,10 @@ const examplesSidebar = [
301305
text: 'Fetch',
302306
link: '/examples/fetch',
303307
},
308+
{
309+
text: 'Cypress <span class="new">new in 3.7.0</span>',
310+
link: '/examples/cypress',
311+
},
304312
{
305313
text: 'Advanced',
306314
link: '/examples/advanced',
@@ -372,6 +380,10 @@ const documentationMenu = [
372380
text: '@kubb/plugin-oas',
373381
link: '/plugins/plugin-oas/',
374382
},
383+
{
384+
text: '@kubb/plugin-cypress',
385+
link: '/plugins/plugin-cypress/',
386+
},
375387
{
376388
text: '@kubb/plugin-client',
377389
link: '/plugins/plugin-client/',
@@ -504,6 +516,7 @@ export default defineConfig({
504516
'@kubb/core/transformers': ['../packages/core/src/transformers/index.ts'],
505517
'@kubb/fs': ['../packages/fs/src/index.ts'],
506518
'@kubb/fs/types': ['../packages/fs/src/types.ts'],
519+
'@kubb/plugin-cypress': ['../packages/plugin-cypress/src/index.ts'],
507520
'@kubb/plugin-oas': ['../packages/plugin-oas/src/index.ts'],
508521
'@kubb/plugin-oas/hooks': ['../packages/plugin-oas/src/hooks/index.ts'],
509522
'@kubb/plugin-client': ['../packages/plugin-client/src/index.ts'],

docs/changelog.md

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ title: Changelog
44

55
# Changelog
66

7+
## 3.7.0
8+
- [`plugin-cypress`](/plugins/plugin-cypress): support for `cy.request` with new plugin `@kubb/plugin-cypress`
9+
710
## 3.6.5
811
- [`plugin-react-query`](/plugins/plugin-react-query/): `TVariables` set to `void` as default
912
- [`plugin-svelte-query`](/plugins/plugin-svelte-query/): `TVariables` set to `void` as default

docs/examples/cypress.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: Cypress PetStore
3+
aside: false
4+
---
5+
6+
<iframe
7+
src="https://codesandbox.io/embed/github/kubb-labs/kubb/tree/main/examples/cypress?fontsize=14&module=%2Fsrc%2Fgen%2Fmodels%2FPerson.ts&theme=dark&view=editor"
8+
:style="{
9+
width: '100%',
10+
height: '700px',
11+
border: 0,
12+
borderRadius: '4px',
13+
overflow: 'hidden'
14+
}"
15+
title="cypress"
16+
allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking"
17+
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
18+
/>

docs/index.md

+12-6
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,10 @@ features:
4545
link: /plugins/plugin-react-query
4646
linkText: Learn more
4747
- icon:
48-
dark: ./feature/swr-dark.svg
49-
light: ./feature/swr-light.svg
50-
height: 24
51-
title: SWR
52-
details: Creates React Hooks for <a href="https://swr.vercel.app/">SWR</a>.
53-
link: /plugins/plugin-swr
48+
src: ./feature/cypress.svg
49+
title: Cypress <span class="new">new in 3.7.0</span>
50+
details: Make type-safe Cypress requests with <b>cy.request</b>.
51+
link: /plugins/plugin-cypress
5452
linkText: Learn more
5553
- icon:
5654
src: ./feature/axios.svg
@@ -77,6 +75,14 @@ features:
7775
details: Use of <a href="https://fakerjs.dev/">Faker.js</a> to create mocked data.
7876
link: /plugins/plugin-faker
7977
linkText: Learn more
78+
- icon:
79+
dark: ./feature/swr-dark.svg
80+
light: ./feature/swr-light.svg
81+
height: 24
82+
title: SWR
83+
details: Creates React Hooks for <a href="https://swr.vercel.app/">SWR</a>.
84+
link: /plugins/plugin-swr
85+
linkText: Learn more
8086
- icon:
8187
src: ./feature/json.svg
8288
title: JSON Schemas

docs/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"@kubb/cli": "workspace:*",
3333
"@kubb/core": "workspace:*",
3434
"@kubb/plugin-client": "workspace:*",
35+
"@kubb/plugin-cypress": "workspace:*",
3536
"@kubb/plugin-faker": "workspace:*",
3637
"@kubb/plugin-msw": "workspace:*",
3738
"@kubb/plugin-oas": "workspace:*",

docs/plugins/plugin-cypress/index.md

+180
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
---
2+
layout: doc
3+
4+
title: \@kubb/plugin-cypress
5+
outline: deep
6+
---
7+
8+
# @kubb/plugin-cypress
9+
10+
With the [Cypress](https://docs.cypress.io/app/get-started/why-cypress) plugin you can use any of your API's endpoint as a Cypress request.
11+
12+
## Installation
13+
14+
::: code-group
15+
16+
```shell [bun]
17+
bun add -d @kubb/plugin-cypress
18+
```
19+
20+
```shell [pnpm]
21+
pnpm add -D @kubb/plugin-cypress
22+
```
23+
24+
```shell [npm]
25+
npm install --save-dev @kubb/plugin-cypress
26+
```
27+
28+
```shell [yarn]
29+
yarn add -D @kubb/plugin-cypress
30+
```
31+
32+
:::
33+
34+
## Options
35+
36+
### output
37+
Specify the export location for the files and define the behavior of the output.
38+
39+
#### output.path
40+
41+
Path to the output folder or file that will contain the generated code.
42+
43+
> [!TIP]
44+
> if `output.path` is a file, `group` cannot be used.
45+
46+
| | |
47+
|----------:|:----------|
48+
| Type: | `string` |
49+
| Required: | `true` |
50+
| Default: | `'cypress'` |
51+
52+
#### output.barrelType
53+
54+
Define what needs to be exported, here you can also disable the export of barrel files.
55+
56+
> [!TIP]
57+
> Using propagate will prevent a plugin from creating a barrel file, but it will still propagate, allowing [`output.barrelType`](/getting-started/configure#output-barreltype) to export the specific function or type.
58+
59+
| | |
60+
|----------:|:--------------------------------|
61+
| Type: | `'all' \| 'named' \| 'propagate' \| false` |
62+
| Required: | `false` |
63+
| Default: | `'named'` |
64+
65+
<!--@include: ../core/barrelTypes.md-->
66+
67+
#### output.banner
68+
Add a banner text in the beginning of every file.
69+
70+
| | |
71+
|----------:|:--------------------------------------|
72+
| Type: | `string \| (oas: Oas) => string` |
73+
| Required: | `false` |
74+
75+
#### output.footer
76+
Add a footer text at the end of every file.
77+
78+
| | |
79+
|----------:|:--------------------------------------|
80+
| Type: | `string \| (oas: Oas) => string` |
81+
| Required: | `false` |
82+
83+
### contentType
84+
<!--@include: ../core/contentType.md-->
85+
86+
### baseURL
87+
<!--@include: ../plugin-client/baseURL.md-->
88+
89+
### group
90+
<!--@include: ../core/group.md-->
91+
92+
#### group.type
93+
Define a type where to group the files on.
94+
95+
| | |
96+
|----------:|:--------|
97+
| Type: | `'tag'` |
98+
| Required: | `true` |
99+
100+
<!--@include: ../core/groupTypes.md-->
101+
102+
#### group.name
103+
104+
Return the name of a group based on the group name, this will be used for the file and name generation.
105+
106+
| | |
107+
|----------:|:------------------------------------|
108+
| Type: | `(context: GroupContext) => string` |
109+
| Required: | `false` |
110+
| Default: | `(ctx) => '${ctx.group}Requests'` |
111+
112+
### include
113+
<!--@include: ../core/include.md-->
114+
115+
### exclude
116+
<!--@include: ../core/exclude.md-->
117+
118+
### override
119+
<!--@include: ../core/override.md-->
120+
121+
### generators <img src="/icons/experimental.svg"/>
122+
<!--@include: ../core/generators.md-->
123+
124+
| | |
125+
|----------:|:------------------------------|
126+
| Type: | `Array<Generator<PluginMsw>>` |
127+
| Required: | `false` |
128+
129+
130+
### transformers
131+
<!--@include: ../core/transformers.md-->
132+
133+
#### transformers.name
134+
Customize the names based on the type that is provided by the plugin.
135+
136+
| | |
137+
|----------:|:------------------------------------------------------------------------------|
138+
| Type: | `(name: string, type?: ResolveType) => string` |
139+
| Required: | `false` |
140+
141+
```typescript
142+
type ResolveType = 'file' | 'function' | 'type' | 'const'
143+
```
144+
145+
## Example
146+
147+
```typescript twoslash
148+
import { defineConfig } from '@kubb/core'
149+
import { pluginOas } from '@kubb/plugin-oas'
150+
import { pluginTs } from '@kubb/plugin-ts'
151+
import { pluginCypress } from '@kubb/plugin-cypress'
152+
153+
export default defineConfig({
154+
input: {
155+
path: './petStore.yaml',
156+
},
157+
output: {
158+
path: './src/gen',
159+
},
160+
plugins: [
161+
pluginOas(),
162+
pluginTs(),
163+
pluginCypress({
164+
output: {
165+
path: './cypress',
166+
barrelType: 'named',
167+
banner: '/* eslint-disable no-alert, no-console */',
168+
footer: ''
169+
},
170+
group: {
171+
type: 'tag',
172+
name: ({ group }) => `${group}Requests`,
173+
},
174+
}),
175+
],
176+
})
177+
```
178+
## Links
179+
180+
- [Cypress](https://docs.cypress.io/)

docs/public/feature/cypress.svg

+54
Loading

0 commit comments

Comments
 (0)