You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: npm/cypress-schematic/README.md
+88-14
Original file line number
Diff line number
Diff line change
@@ -19,26 +19,36 @@
19
19
20
20
✅ Install Cypress
21
21
22
-
✅ Add npm scripts for running Cypress in `run` mode and `open` mode
22
+
✅ Add npm scripts for running Cypress e2e tests in `run` mode and `open` mode
23
23
24
24
✅ Scaffold base Cypress files and directories
25
25
26
-
✅ Provide the ability to add new e2e files easily using `ng-generate`
26
+
✅ Provide the ability to add new e2e and component specs easily using `ng-generate`
27
27
28
-
✅ Optional: prompt you to add or update the default `ng e2e` command to use Cypress.
28
+
✅ Optional: prompt you to add or update the default `ng e2e` command to use Cypress for e2e tests.
29
+
30
+
✅ Optional: prompt you to add a `ng ct` command to use Cypress component testing.
29
31
30
32
## Requirements
31
33
32
-
- Angular 12+
34
+
- Angular 13+
33
35
34
36
## Usage ⏯
35
37
36
-
Install the schematic:
38
+
### Adding E2E and Component Testing
39
+
40
+
To install the schematic via prompts:
37
41
38
42
```shell
39
43
ng add @cypress/schematic
40
44
```
41
45
46
+
To install the schematic via cli arguments (installs both e2e and component testing):
47
+
48
+
```shell
49
+
ng add @cypress/schematic --e2e --component
50
+
```
51
+
42
52
To run Cypress in `open` mode within your project:
43
53
44
54
```shell script
@@ -57,11 +67,49 @@ If you have chosen to add or update the `ng e2e` command, you can also run Cypre
57
67
ng e2e
58
68
```
59
69
60
-
To generate new e2e spec files:
70
+
If you have chosen to add Cypress component testing, you can run component tests in `open` mode using this:
71
+
72
+
```shell script
73
+
ng run {project-name}:ct
74
+
```
75
+
76
+
### Generating New Cypress Spec Files
77
+
78
+
To generate a new e2e spec file:
79
+
80
+
```shell script
81
+
ng generate @cypress/schematic:spec
82
+
```
83
+
84
+
or (without cli prompt)
85
+
86
+
```shell script
87
+
ng generate @cypress/schematic:spec {name}
88
+
```
89
+
90
+
To generate a new component spec file:
91
+
92
+
```shell script
93
+
ng generate @cypress/schematic:spec --component
94
+
```
95
+
96
+
or (without cli prompt)
97
+
98
+
```shell script
99
+
ng generate @cypress/schematic:spec {component name} --component
100
+
```
101
+
102
+
To generate a new component spec file in a specific folder:
103
+
104
+
```shell script
105
+
ng generate @cypress/schematic:spec {component name} --component --path {path relative to project root}
106
+
```
107
+
108
+
To generate new component spec files alongside all component files in a project:
61
109
62
110
```shell script
63
-
ng generate @cypress/schematic:e2e
64
-
```
111
+
ng generate @cypress/schematic:specs-ct
112
+
```
65
113
66
114
## Builder Options 🛠
67
115
@@ -109,7 +157,7 @@ We recommend setting your [Cypress Dashboard](https://on.cypress.io/features-das
109
157
110
158
Read our docs to learn more about [recording test results](https://on.cypress.io/recording-project-runs) to the [Cypress Dashboard](https://on.cypress.io/features-dashboard).
111
159
112
-
### Specifying a custom `cypress.json`config file
160
+
### Specifying a custom config file
113
161
114
162
It may be useful to have different Cypress configuration files per environment (ie. development, staging, production).
115
163
@@ -223,12 +271,22 @@ In order to prevent the application from building, add the following to the end
223
271
224
272
## Generator Options
225
273
274
+
### Specify Testing Type
275
+
276
+
The default generated spec is E2E. In order to generate a component test you can run:
277
+
278
+
```shell script
279
+
ng generate @cypress/schematic:spec --name=button -t component
280
+
```
281
+
282
+
`-t` is an alias for `testing-type`. It accepts `e2e` or `component` as arguments. If you are using the CLI tool, a prompt will appear asking which spec type you want to generate.
283
+
226
284
### Specify Filename (bypassing CLI prompt)
227
285
228
-
In order to bypass the prompt asking for your e2e spec name, simply add a `--name=` flag like this:
286
+
In order to bypass the prompt asking for your spec name add a `--name=` flag like this:
229
287
230
288
```shell script
231
-
ng generate @cypress/schematic:e2e --name=login
289
+
ng generate @cypress/schematic:spec --name=login
232
290
```
233
291
234
292
This will create a new spec file named `login.cy.ts` in the default Cypress folder location.
@@ -238,17 +296,33 @@ This will create a new spec file named `login.cy.ts` in the default Cypress fold
238
296
Add a `--project=` flag to specify the project:
239
297
240
298
```shell script
241
-
ng generate @cypress/schematic:e2e --name=login --project=sandbox
299
+
ng generate @cypress/schematic:spec --name=login --project=sandbox
242
300
```
243
301
### Specify Path
244
302
245
303
Add a `--path=` flag to specify the project:
246
304
247
305
```shell script
248
-
ng generate @cypress/schematic:e2e --name=login --path=src/app/tests
306
+
ng generate @cypress/schematic:spec --name=login --path=src/app/tests
307
+
```
308
+
309
+
This will create a spec file in your specific location, creating folders as needed. By default, new specs are created in either `cypress/e2e` for E2E specs or `cypress/ct` for component specs.
310
+
311
+
### Generate Tests for All Components
312
+
313
+
You can scaffold component test specs alongside all your components in the default project by using:
314
+
315
+
```shell script
316
+
ng generate @cypress/schematic:specs-ct -g
249
317
```
250
318
251
-
This will create the e2e spec file in your specific location, creating folders as needed.
319
+
This will identify files ending in `component.ts`. It will then create spec files alongside them - if they don't exist.
320
+
321
+
If you would like to specify a project, you can use the command:
322
+
323
+
```shell script
324
+
ng generate @cypress/schematic:specs-ct -g -p {project-name}
0 commit comments