Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cypress Plugin #1580

Merged
merged 22 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/angry-eggs-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kubb/plugin-cypress": minor
---

support for `cy.request` with new plugin `@kubb/plugin-cypress`
5 changes: 5 additions & 0 deletions .changeset/happy-lands-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kubb/plugin-cypress": patch
---

Add a Cypress plugin for generating cypress requests
2 changes: 2 additions & 0 deletions .codesandbox/ci.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"packages/plugin-oas",
"packages/plugin-redoc",
"packages/plugin-client",
"packages/plugin-cypress",
"packages/plugin-faker",
"packages/plugin-msw",
"packages/plugin-swr",
Expand All @@ -21,6 +22,7 @@
],
"sandboxes": [
"/examples/advanced",
"/examples/cypress",
"/examples/faker",
"/examples/msw",
"/examples/react-query",
Expand Down
13 changes: 13 additions & 0 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ const mainSidebar = [
},
],
},
{
text: '@kubb/plugin-cypress <span class="new">new in 3.7.0</span>',
link: '/plugins/plugin-cypress/',
},
{
text: '@kubb/plugin-client',
link: '/plugins/plugin-client/',
Expand Down Expand Up @@ -301,6 +305,10 @@ const examplesSidebar = [
text: 'Fetch',
link: '/examples/fetch',
},
{
text: 'Cypress <span class="new">new in 3.7.0</span>',
link: '/examples/cypress',
},
{
text: 'Advanced',
link: '/examples/advanced',
Expand Down Expand Up @@ -372,6 +380,10 @@ const documentationMenu = [
text: '@kubb/plugin-oas',
link: '/plugins/plugin-oas/',
},
{
text: '@kubb/plugin-cypress',
link: '/plugins/plugin-cypress/',
},
{
text: '@kubb/plugin-client',
link: '/plugins/plugin-client/',
Expand Down Expand Up @@ -504,6 +516,7 @@ export default defineConfig({
'@kubb/core/transformers': ['../packages/core/src/transformers/index.ts'],
'@kubb/fs': ['../packages/fs/src/index.ts'],
'@kubb/fs/types': ['../packages/fs/src/types.ts'],
'@kubb/plugin-cypress': ['../packages/plugin-cypress/src/index.ts'],
'@kubb/plugin-oas': ['../packages/plugin-oas/src/index.ts'],
'@kubb/plugin-oas/hooks': ['../packages/plugin-oas/src/hooks/index.ts'],
'@kubb/plugin-client': ['../packages/plugin-client/src/index.ts'],
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ title: Changelog

# Changelog

## 3.7.0
- [`plugin-cypress`](/plugins/plugin-cypress): support for `cy.request` with new plugin `@kubb/plugin-cypress`

## 3.6.5
- [`plugin-react-query`](/plugins/plugin-react-query/): `TVariables` set to `void` as default
- [`plugin-svelte-query`](/plugins/plugin-svelte-query/): `TVariables` set to `void` as default
Expand Down
18 changes: 18 additions & 0 deletions docs/examples/cypress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: Cypress PetStore
aside: false
---

<iframe
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"
:style="{
width: '100%',
height: '700px',
border: 0,
borderRadius: '4px',
overflow: 'hidden'
}"
title="cypress"
allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking"
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
/>
18 changes: 12 additions & 6 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@ features:
link: /plugins/plugin-react-query
linkText: Learn more
- icon:
dark: ./feature/swr-dark.svg
light: ./feature/swr-light.svg
height: 24
title: SWR
details: Creates React Hooks for <a href="https://swr.vercel.app/">SWR</a>.
link: /plugins/plugin-swr
src: ./feature/cypress.svg
title: Cypress <span class="new">new in 3.7.0</span>
details: Make type-safe Cypress requests with <b>cy.request</b>.
link: /plugins/plugin-cypress
linkText: Learn more
- icon:
src: ./feature/axios.svg
Expand All @@ -77,6 +75,14 @@ features:
details: Use of <a href="https://fakerjs.dev/">Faker.js</a> to create mocked data.
link: /plugins/plugin-faker
linkText: Learn more
- icon:
dark: ./feature/swr-dark.svg
light: ./feature/swr-light.svg
height: 24
title: SWR
details: Creates React Hooks for <a href="https://swr.vercel.app/">SWR</a>.
link: /plugins/plugin-swr
linkText: Learn more
- icon:
src: ./feature/json.svg
title: JSON Schemas
Expand Down
1 change: 1 addition & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@kubb/cli": "workspace:*",
"@kubb/core": "workspace:*",
"@kubb/plugin-client": "workspace:*",
"@kubb/plugin-cypress": "workspace:*",
"@kubb/plugin-faker": "workspace:*",
"@kubb/plugin-msw": "workspace:*",
"@kubb/plugin-oas": "workspace:*",
Expand Down
180 changes: 180 additions & 0 deletions docs/plugins/plugin-cypress/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
---
layout: doc

title: \@kubb/plugin-cypress
outline: deep
---

# @kubb/plugin-cypress

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.

## Installation

::: code-group

```shell [bun]
bun add -d @kubb/plugin-cypress
```

```shell [pnpm]
pnpm add -D @kubb/plugin-cypress
```

```shell [npm]
npm install --save-dev @kubb/plugin-cypress
```

```shell [yarn]
yarn add -D @kubb/plugin-cypress
```

:::

## Options

### output
Specify the export location for the files and define the behavior of the output.

#### output.path

Path to the output folder or file that will contain the generated code.

> [!TIP]
> if `output.path` is a file, `group` cannot be used.

| | |
|----------:|:----------|
| Type: | `string` |
| Required: | `true` |
| Default: | `'cypress'` |

#### output.barrelType

Define what needs to be exported, here you can also disable the export of barrel files.

> [!TIP]
> 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.

| | |
|----------:|:--------------------------------|
| Type: | `'all' \| 'named' \| 'propagate' \| false` |
| Required: | `false` |
| Default: | `'named'` |

<!--@include: ../core/barrelTypes.md-->

#### output.banner
Add a banner text in the beginning of every file.

| | |
|----------:|:--------------------------------------|
| Type: | `string \| (oas: Oas) => string` |
| Required: | `false` |

#### output.footer
Add a footer text at the end of every file.

| | |
|----------:|:--------------------------------------|
| Type: | `string \| (oas: Oas) => string` |
| Required: | `false` |

### contentType
<!--@include: ../core/contentType.md-->

### baseURL
<!--@include: ../plugin-client/baseURL.md-->

### group
<!--@include: ../core/group.md-->

#### group.type
Define a type where to group the files on.

| | |
|----------:|:--------|
| Type: | `'tag'` |
| Required: | `true` |

<!--@include: ../core/groupTypes.md-->

#### group.name

Return the name of a group based on the group name, this will be used for the file and name generation.

| | |
|----------:|:------------------------------------|
| Type: | `(context: GroupContext) => string` |
| Required: | `false` |
| Default: | `(ctx) => '${ctx.group}Requests'` |

### include
<!--@include: ../core/include.md-->

### exclude
<!--@include: ../core/exclude.md-->

### override
<!--@include: ../core/override.md-->

### generators <img src="/icons/experimental.svg"/>
<!--@include: ../core/generators.md-->

| | |
|----------:|:------------------------------|
| Type: | `Array<Generator<PluginMsw>>` |
| Required: | `false` |


### transformers
<!--@include: ../core/transformers.md-->

#### transformers.name
Customize the names based on the type that is provided by the plugin.

| | |
|----------:|:------------------------------------------------------------------------------|
| Type: | `(name: string, type?: ResolveType) => string` |
| Required: | `false` |

```typescript
type ResolveType = 'file' | 'function' | 'type' | 'const'
```

## Example

```typescript twoslash
import { defineConfig } from '@kubb/core'
import { pluginOas } from '@kubb/plugin-oas'
import { pluginTs } from '@kubb/plugin-ts'
import { pluginCypress } from '@kubb/plugin-cypress'

export default defineConfig({
input: {
path: './petStore.yaml',
},
output: {
path: './src/gen',
},
plugins: [
pluginOas(),
pluginTs(),
pluginCypress({
output: {
path: './cypress',
barrelType: 'named',
banner: '/* eslint-disable no-alert, no-console */',
footer: ''
},
group: {
type: 'tag',
name: ({ group }) => `${group}Requests`,
},
}),
],
})
```
## Links

- [Cypress](https://docs.cypress.io/)
54 changes: 54 additions & 0 deletions docs/public/feature/cypress.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading