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
feat: rework test phases to make onSuccess default (#133)
BREAKING CHANGE: now the onSuccess step is the default testing
step, running the Cypress tests against the preview or production
deploy. Another change is the default browser is Chromium instead
of Electron.
```toml
[[plugins]]
# runs Cypress tests against the deployed URL
package = "netlify-plugin-cypress"
```
> Runs Cypress end-to-end tests after Netlify builds the site but before it is deployed
4
-
5
-
**Note:** currently the built site is served statically and tested _without proxying redirects_.
3
+
> Runs Cypress end-to-end tests on Netlify Build
6
4
7
5
## Install and use
8
6
@@ -26,7 +24,7 @@ This plugin installs [via Puppeteer](https://github.com/puppeteer/puppeteer) Chr
26
24
27
25
## How does it work
28
26
29
-
When Netlify Build runs, it "knows" the output folder name and calls the `netlify-plugin-cypress` after the build has finished with that folder. Then the plugin runs Cypress tests using its [NPM module API](https://on.cypress.io/module-api). If the tests pass, the plugin finishes and the Netlify deploy starts.
27
+
When Netlify Build runs, it calls the plugin `netlify-plugin-cypress`before and after the build, and after the deployment. The plugin runs the Cypress tests using its [NPM module API](https://on.cypress.io/module-api) against the local folder or against the deployed URL.
30
28
31
29
## Examples
32
30
@@ -36,7 +34,7 @@ Here is the most basic [Netlify config file](https://docs.netlify.com/configure-
36
34
37
35
```toml
38
36
[[plugins]]
39
-
#local Cypress plugin will test our site after it is built
#local Cypress plugin will test our site after it is built
62
+
#runs Cypress tests against the deployed URL
65
63
package = "netlify-plugin-cypress"
66
64
```
67
65
@@ -77,22 +75,15 @@ publish = "build"
77
75
# ...remaining configuration...
78
76
```
79
77
80
-
### testing deployed url
78
+
### tutorial
81
79
82
-
After successful deployment you can run tests against the `DEPLOY_PRIME_URL` provided by the Netlify system.
80
+
Read the full tutorial at [Test Sites Deployed To Netlify Using netlify-plugin-cypress](https://glebbahmutov.com/blog/test-netlify/).
83
81
84
-
```toml
85
-
[[plugins]]
86
-
package = "netlify-plugin-cypress"
87
-
[plugins.inputs.onSuccess]
88
-
enable = true
89
-
```
90
-
91
-
The following parameters can be used with "onSuccess" tests: `record`, `group`, `tag`, `spec`.
82
+
**Note:** if any tests against the deployed URL fail, the Netlify build still considers it a success. Thus if you want to have a test check against the deploy, install [Cypress GitHub App](https://on.cypress.io/github-integration). The app will provide its own failing status check in this case.
92
83
93
-
Read the full tutorial [Test Sites Deployed To Netlify Using netlify-plugin-cypress](https://glebbahmutov.com/blog/test-netlify/).
84
+
### options
94
85
95
-
**Note:** if any tests against the deployed URL fail, the Netlify build still considers it a success. Thus if you want to have a test check against the deploy, install [Cypress GitHub App](https://on.cypress.io/github-integration). The app will provide its own failing status check in this case.
86
+
You can control the browser, the specs to run, record tests on Cypress Dashboard, etc, see [manifest.yml](./manifest.yml) file.
96
87
97
88
### recording
98
89
@@ -110,7 +101,7 @@ publish = "build"
110
101
TERM = "xterm"
111
102
112
103
[[plugins]]
113
-
#local Cypress plugin will test our site after it is built
104
+
#runs Cypress tests against the deployed URL
114
105
package = "netlify-plugin-cypress"
115
106
[plugins.inputs]
116
107
record = true
@@ -132,7 +123,7 @@ You can change the group name for the recorded run using `group` parameter
132
123
133
124
```toml
134
125
[[plugins]]
135
-
#local Cypress plugin will test our site after it is built
126
+
#runs Cypress tests against the deployed URL
136
127
package = "netlify-plugin-cypress"
137
128
[plugins.inputs]
138
129
record = true
@@ -145,7 +136,7 @@ You can give recorded run [tags](https://on.cypress.io/module-api#cypress-run) u
145
136
146
137
```toml
147
138
[[plugins]]
148
-
#local Cypress plugin will test our site after it is built
139
+
#runs Cypress tests against the deployed URL
149
140
package = "netlify-plugin-cypress"
150
141
[plugins.inputs]
151
142
record = true
@@ -169,17 +160,17 @@ publish = "build"
169
160
TERM = "xterm"
170
161
171
162
[[plugins]]
172
-
#local Cypress plugin will test our site after it is built
163
+
#runs Cypress tests against the deployed URL
173
164
package = "netlify-plugin-cypress"
174
165
[plugins.inputs]
175
166
spec = "cypress/integration/smoke*.js"
176
167
```
177
168
178
169
See [cypress-example-kitchensink](https://github.com/cypress-io/cypress-example-kitchensink) for instance.
179
170
180
-
### Chromium
171
+
### browser
181
172
182
-
By default all tests run using built-in Electron browser. If you want to use Chromium:
173
+
By default all tests run using the Chromium browser. If you want to use Electron:
183
174
184
175
```toml
185
176
[build]
@@ -195,12 +186,13 @@ publish = "build"
195
186
[[plugins]]
196
187
package = "netlify-plugin-cypress"
197
188
[plugins.inputs]
198
-
browser = "chromium"
189
+
# allowed values: electron, chromium
190
+
browser = "electron"
199
191
```
200
192
201
193
### testing SPA routes
202
194
203
-
SPAs need catch-all redirect setup to make non-root paths accesssible by tests. You can enable this with `spa` parameter.
195
+
SPAs need catch-all redirect setup to make non-root paths accessible by tests. You can enable this with `spa` parameter.
204
196
205
197
```
206
198
[[plugins]]
@@ -215,7 +207,7 @@ See [lws-spa](https://github.com/lwsjs/spa) for more options and [tests/routing]
215
207
216
208
### testing the site before build
217
209
218
-
By default this plugin tests static site _after build_. But maybe you want to run end-to-end tests against the _local development server_. You can start local server, wait for it to respond and then run Cypress tests by passing parameters to this plugin. Here is a sample config file
210
+
By default this plugin tests static site _after deploy_. But maybe you want to run end-to-end tests against the _local development server_. You can start the local server, wait for it to respond and then run Cypress tests by passing parameters to this plugin. Here is a sample config file
219
211
220
212
```toml
221
213
[[plugins]]
@@ -228,10 +220,42 @@ By default this plugin tests static site _after build_. But maybe you want to ru
228
220
wait-on-timeout = '30'# seconds
229
221
```
230
222
231
-
Parameters you can place into `preBuild` inputs: `start`, `wait-on`, `wait-on-timeout`, `spec`, `record`, `group`, and `tag`. If there is `preBuild` and `postBuild` testing with different tags, the first one wins :)
223
+
Parameters you can place into `preBuild` inputs: `start`, `wait-on`, `wait-on-timeout`, `spec`, `record`, `group`, and `tag`.
232
224
233
225
See [netlify-plugin-prebuild-example](https://github.com/cypress-io/netlify-plugin-prebuild-example) repo
234
226
227
+
### testing the site after build
228
+
229
+
By default this plugin tests static site _after deploy_. But maybe you want to run end-to-end tests locally after building the static site. Cypress includes a local static server for this case. Here is a sample config file
230
+
231
+
```toml
232
+
[[plugins]]
233
+
package = "netlify-plugin-cypress"
234
+
# let's run tests against the built site
235
+
[plugins.inputs.postBuild]
236
+
enable = true
237
+
```
238
+
239
+
Parameters you can place into `postBuild` inputs: `spec`, `record`, `group`, `tag`, and `spa`.
240
+
241
+
#### The SPA parameter
242
+
243
+
If your site requires all unknown URLs to redirect back to the index page, use the `spa` parameter
244
+
245
+
```toml
246
+
[[plugins]]
247
+
package = "netlify-plugin-cypress"
248
+
# let's run tests against the built site
249
+
[plugins.inputs.postBuild]
250
+
enable = true
251
+
# must allow our test server to redirect unknown routes to "/"
252
+
# so that client-side routing can correctly route them
253
+
# can be set to true or "index.html" (or similar fallback filename in the built folder)
254
+
spa = true
255
+
```
256
+
257
+
See [the routing example](./tests/routing/netlify.toml).
258
+
235
259
### using Netlify CLI
236
260
237
261
Even better when testing the prebuilt site is to run the [Netlify CLI](https://cli.netlify.com/) to make sure the local API redirects and Netlify functions work in addition to the web site. Add `netlify-cli` as a dev dependency and start it during testing.
@@ -253,13 +277,17 @@ For more, see [tests/test-netlify-dev](./tests/test-netlify-dev) example and rea
253
277
254
278
### skipping tests
255
279
256
-
If you are testing the site before building it, you probably want to skip testing it after the build. See [tests/test-prebuild-only](./tests/test-prebuild-only/netlify.toml):
280
+
If you are testing the site before building it and want to skip testing the deployed URL
257
281
258
282
```toml
259
283
[[plugins]]
260
284
package = "netlify-plugin-cypress"
285
+
# do not test the deployed URL
261
286
[plugins.inputs]
262
-
skip = true
287
+
enable = false
288
+
# test the local site
289
+
[plugins.inputs.preBuild]
290
+
enable = true
263
291
```
264
292
265
293
### parallelization
@@ -294,6 +322,13 @@ Name | Description
294
322
[bahmutov/eleventyone](https://github.com/bahmutov/eleventyone) | Example used in [Test Sites Deployed To Netlify Using netlify-plugin-cypress](https://glebbahmutov.com/blog/test-netlify/) tutorial
295
323
[gatsby-starter-portfolio-cara](https://github.com/bahmutov/gatsby-starter-portfolio-cara) | A Gatsby site example
296
324
325
+
## Major upgrades
326
+
327
+
### v1 to v2
328
+
329
+
- The default browser has been switched to Chromium. If you want to use the built-in Electron use an explicit option [browser](#browser)
330
+
- We have changed the default testing phase. In v1 the tests executed after building the site by default. In v2 the tests run against the deployed URL by default, and you need to enable the testing during `preBuild` or `postBuild` steps.
331
+
297
332
## Debugging
298
333
299
334
Set environment variable `DEBUG=netlify-plugin-cypress` to see the debug logs. To see even more information, set `DEBUG=netlify-plugin-cypress,netlify-plugin-cypress:verbose`
@@ -332,6 +367,11 @@ Set environment variable `DEBUG=netlify-plugin-cypress` to see the debug logs. T
332
367
Switch to using Chromium browser that seems to be a bit more reliable. Use <code>browser = "chromium"</code> setting.
333
368
</details>
334
369
370
+
<details>
371
+
<summary>You want to skip Puppeteer download</summary>
372
+
If you do not plan on using Chromium to run the tests, if you want to use the built-in Electron browser, you can save time by skipping the Puppeteer download. Set the environment variable <code>PUPPETEER_SKIP_DOWNLOAD = 1</code> on your CI.
373
+
</details>
374
+
335
375
## License
336
376
337
377
This project is licensed under the terms of the [MIT license](LICENSE.md).
0 commit comments