@kubb/plugin-cypress 5.0.0-beta.22 → 5.0.0-beta.25
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/dist/index.cjs +38 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +54 -30
- package/dist/index.js +38 -22
- package/dist/index.js.map +1 -1
- package/extension.yaml +614 -152
- package/package.json +5 -5
- package/src/components/Request.tsx +1 -1
- package/src/generators/cypressGenerator.tsx +10 -2
- package/src/plugin.ts +17 -10
- package/src/resolvers/resolverCypress.ts +8 -4
- package/src/types.ts +25 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-cypress",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.25",
|
|
4
4
|
"description": "Generate Cypress request commands and e2e test fixtures from your OpenAPI specification, enabling automated API testing with zero manual setup.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"code-generation",
|
|
@@ -47,16 +47,16 @@
|
|
|
47
47
|
"registry": "https://registry.npmjs.org/"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@kubb/core": "5.0.0-beta.
|
|
51
|
-
"@kubb/renderer-jsx": "5.0.0-beta.
|
|
52
|
-
"@kubb/plugin-ts": "5.0.0-beta.
|
|
50
|
+
"@kubb/core": "5.0.0-beta.25",
|
|
51
|
+
"@kubb/renderer-jsx": "5.0.0-beta.25",
|
|
52
|
+
"@kubb/plugin-ts": "5.0.0-beta.25"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@internals/shared": "0.0.0",
|
|
56
56
|
"@internals/utils": "0.0.0"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@kubb/renderer-jsx": "5.0.0-beta.
|
|
59
|
+
"@kubb/renderer-jsx": "5.0.0-beta.25"
|
|
60
60
|
},
|
|
61
61
|
"size-limit": [
|
|
62
62
|
{
|
|
@@ -60,7 +60,7 @@ export function Request({ baseURL = '', name, dataReturnType, resolver, node, pa
|
|
|
60
60
|
replacer: (param) => pathParamNameMap.get(camelCase(param)) ?? param,
|
|
61
61
|
})
|
|
62
62
|
|
|
63
|
-
const requestOptions: string
|
|
63
|
+
const requestOptions: Array<string> = [`method: '${node.method}'`, `url: ${urlTemplate}`]
|
|
64
64
|
|
|
65
65
|
const queryParams = getOperationParameters(node).query
|
|
66
66
|
if (queryParams.length > 0) {
|
|
@@ -5,6 +5,11 @@ import { File, jsxRendererSync } from '@kubb/renderer-jsx'
|
|
|
5
5
|
import { Request } from '../components/Request.tsx'
|
|
6
6
|
import type { PluginCypress } from '../types.ts'
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Built-in generator for `@kubb/plugin-cypress`. Emits one typed
|
|
10
|
+
* `cy.request()` wrapper per OpenAPI operation, ready to call inside Cypress
|
|
11
|
+
* test specs and custom commands.
|
|
12
|
+
*/
|
|
8
13
|
export const cypressGenerator = defineGenerator<PluginCypress>({
|
|
9
14
|
name: 'cypress',
|
|
10
15
|
renderer: jsxRendererSync,
|
|
@@ -24,13 +29,16 @@ export const cypressGenerator = defineGenerator<PluginCypress>({
|
|
|
24
29
|
|
|
25
30
|
const meta = {
|
|
26
31
|
name: resolver.resolveName(node.operationId),
|
|
27
|
-
file: resolver.resolveFile(
|
|
32
|
+
file: resolver.resolveFile(
|
|
33
|
+
{ name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
34
|
+
{ root, output, group: group ?? undefined },
|
|
35
|
+
),
|
|
28
36
|
fileTs: tsResolver.resolveFile(
|
|
29
37
|
{ name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
30
38
|
{
|
|
31
39
|
root,
|
|
32
40
|
output: pluginTs.options?.output ?? output,
|
|
33
|
-
group: pluginTs.options?.group,
|
|
41
|
+
group: pluginTs.options?.group ?? undefined,
|
|
34
42
|
},
|
|
35
43
|
),
|
|
36
44
|
} as const
|
package/src/plugin.ts
CHANGED
|
@@ -6,24 +6,31 @@ import { resolverCypress } from './resolvers/resolverCypress.ts'
|
|
|
6
6
|
import type { PluginCypress } from './types.ts'
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* Canonical plugin name for `@kubb/plugin-cypress
|
|
10
|
-
*
|
|
9
|
+
* Canonical plugin name for `@kubb/plugin-cypress`. Used for driver lookups and
|
|
10
|
+
* cross-plugin dependency references.
|
|
11
11
|
*/
|
|
12
12
|
export const pluginCypressName = 'plugin-cypress' satisfies PluginCypress['name']
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* Walks operations, delegates rendering to the active generators,
|
|
19
|
-
* and writes barrel files based on `output.barrelType`.
|
|
15
|
+
* Generates one typed `cy.request()` wrapper per OpenAPI operation. Each helper
|
|
16
|
+
* has typed path params, body, query, and a typed response, so failing API
|
|
17
|
+
* calls in Cypress show up at compile time instead of inside the test runner.
|
|
20
18
|
*
|
|
21
19
|
* @example
|
|
22
20
|
* ```ts
|
|
23
|
-
* import
|
|
21
|
+
* import { defineConfig } from 'kubb'
|
|
22
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
23
|
+
* import { pluginCypress } from '@kubb/plugin-cypress'
|
|
24
24
|
*
|
|
25
25
|
* export default defineConfig({
|
|
26
|
-
*
|
|
26
|
+
* input: { path: './petStore.yaml' },
|
|
27
|
+
* output: { path: './src/gen' },
|
|
28
|
+
* plugins: [
|
|
29
|
+
* pluginTs(),
|
|
30
|
+
* pluginCypress({
|
|
31
|
+
* output: { path: './cypress' },
|
|
32
|
+
* }),
|
|
33
|
+
* ],
|
|
27
34
|
* })
|
|
28
35
|
* ```
|
|
29
36
|
*/
|
|
@@ -56,7 +63,7 @@ export const pluginCypress = definePlugin<PluginCypress>((options) => {
|
|
|
56
63
|
return `${camelCase(ctx.group)}Requests`
|
|
57
64
|
},
|
|
58
65
|
} satisfies Group)
|
|
59
|
-
:
|
|
66
|
+
: null
|
|
60
67
|
|
|
61
68
|
return {
|
|
62
69
|
name: pluginCypressName,
|
|
@@ -3,12 +3,16 @@ import { defineResolver } from '@kubb/core'
|
|
|
3
3
|
import type { PluginCypress } from '../types.ts'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Default resolver used by `@kubb/plugin-cypress`. Decides the names and file
|
|
7
|
+
* paths for every generated `cy.request()` wrapper. Functions and files use
|
|
8
|
+
* camelCase, matching the convention from `@kubb/plugin-client`.
|
|
7
9
|
*
|
|
8
|
-
*
|
|
10
|
+
* @example Resolve a helper name
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { resolverCypress } from '@kubb/plugin-cypress'
|
|
9
13
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
14
|
+
* resolverCypress.default('list pets', 'function') // 'listPets'
|
|
15
|
+
* ```
|
|
12
16
|
*/
|
|
13
17
|
export const resolverCypress = defineResolver<PluginCypress>(() => ({
|
|
14
18
|
name: 'default',
|
package/src/types.ts
CHANGED
|
@@ -23,21 +23,23 @@ export type ResolverCypress = Resolver & {
|
|
|
23
23
|
type ParamsTypeOptions =
|
|
24
24
|
| {
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
26
|
+
* Every operation parameter is wrapped in a single destructured object argument.
|
|
27
27
|
*/
|
|
28
28
|
paramsType: 'object'
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
30
|
+
* `pathParamsType` has no effect when `paramsType` is `'object'`.
|
|
31
31
|
*/
|
|
32
32
|
pathParamsType?: never
|
|
33
33
|
}
|
|
34
34
|
| {
|
|
35
35
|
/**
|
|
36
|
-
* Each parameter group emitted as a separate function argument.
|
|
36
|
+
* Each parameter group is emitted as a separate positional function argument.
|
|
37
37
|
*/
|
|
38
38
|
paramsType?: 'inline'
|
|
39
39
|
/**
|
|
40
|
-
* How path parameters are arranged
|
|
40
|
+
* How URL path parameters are arranged inside the inline argument list.
|
|
41
|
+
* - `'object'` groups them into one destructured object.
|
|
42
|
+
* - `'inline'` emits each path param as its own argument.
|
|
41
43
|
*
|
|
42
44
|
* @default 'inline'
|
|
43
45
|
*/
|
|
@@ -46,50 +48,56 @@ type ParamsTypeOptions =
|
|
|
46
48
|
|
|
47
49
|
export type Options = {
|
|
48
50
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
+
* Where the generated Cypress helpers are written and how they are exported.
|
|
52
|
+
*
|
|
53
|
+
* @default { path: 'cypress', barrel: { type: 'named' } }
|
|
51
54
|
*/
|
|
52
55
|
output?: Output
|
|
53
56
|
/**
|
|
54
|
-
*
|
|
57
|
+
* Shape of the value returned from each helper.
|
|
58
|
+
* - `'data'` — only the response body.
|
|
59
|
+
* - `'full'` — the full Cypress response object (headers, status, body).
|
|
55
60
|
*
|
|
56
61
|
* @default 'data'
|
|
57
62
|
*/
|
|
58
63
|
dataReturnType?: 'data' | 'full'
|
|
59
64
|
/**
|
|
60
|
-
*
|
|
65
|
+
* Rename parameter properties in the generated helpers (path, query, headers).
|
|
66
|
+
*
|
|
67
|
+
* @note Must match the value of `paramsCasing` on `@kubb/plugin-ts`.
|
|
61
68
|
*/
|
|
62
69
|
paramsCasing?: 'camelcase'
|
|
63
70
|
/**
|
|
64
|
-
* Base URL prepended to every
|
|
71
|
+
* Base URL prepended to every request URL. When omitted, falls back to the
|
|
72
|
+
* adapter's server URL (typically `servers[0].url`).
|
|
65
73
|
*/
|
|
66
74
|
baseURL?: string
|
|
67
75
|
/**
|
|
68
|
-
*
|
|
76
|
+
* Split generated files into subfolders based on the operation's tag.
|
|
69
77
|
*/
|
|
70
78
|
group?: Group
|
|
71
79
|
/**
|
|
72
|
-
*
|
|
80
|
+
* Skip operations matching at least one entry in the list.
|
|
73
81
|
*/
|
|
74
82
|
exclude?: Array<Exclude>
|
|
75
83
|
/**
|
|
76
|
-
*
|
|
84
|
+
* Restrict generation to operations matching at least one entry in the list.
|
|
77
85
|
*/
|
|
78
86
|
include?: Array<Include>
|
|
79
87
|
/**
|
|
80
|
-
*
|
|
88
|
+
* Apply a different options object to operations matching a pattern.
|
|
81
89
|
*/
|
|
82
90
|
override?: Array<Override<ResolvedOptions>>
|
|
83
91
|
/**
|
|
84
|
-
* Override
|
|
92
|
+
* Override how helper names and file paths are built.
|
|
85
93
|
*/
|
|
86
94
|
resolver?: Partial<ResolverCypress> & ThisType<ResolverCypress>
|
|
87
95
|
/**
|
|
88
|
-
* AST visitor to
|
|
96
|
+
* AST visitor applied to each operation node before printing.
|
|
89
97
|
*/
|
|
90
98
|
transformer?: ast.Visitor
|
|
91
99
|
/**
|
|
92
|
-
*
|
|
100
|
+
* Custom generators that run alongside the built-in Cypress generators.
|
|
93
101
|
*/
|
|
94
102
|
generators?: Array<Generator<PluginCypress>>
|
|
95
103
|
} & ParamsTypeOptions
|
|
@@ -99,7 +107,7 @@ type ResolvedOptions = {
|
|
|
99
107
|
exclude: Array<Exclude>
|
|
100
108
|
include: Array<Include> | undefined
|
|
101
109
|
override: Array<Override<ResolvedOptions>>
|
|
102
|
-
group: Group |
|
|
110
|
+
group: Group | null
|
|
103
111
|
baseURL: Options['baseURL'] | undefined
|
|
104
112
|
dataReturnType: NonNullable<Options['dataReturnType']>
|
|
105
113
|
pathParamsType: NonNullable<NonNullable<Options['pathParamsType']>>
|