Skip to content

Commit 636e5a3

Browse files
authored
added preBuild testing support (#13)
* chore: refactor postBuild * feat: install cypress binary preBuild * chore: run semantic release from beta branch * trigger build without PR on Circle * if debug is on, inherit stdio when installing Cypress binary * update README examples * add contributing guide, close #12 * add local Netlify setup * fix missing quote * add Cypress spec * add link to netlify cli * add link to CircleCI beta * add local testing * move index.js to src folder * add wait-on parameter preBuild * allow testing in preBuild step * feat: allow testing preBuild site * add example to README * feat: add group name * pass ci build id * add tag support * feat: use Netlify context as default tag * fix: add tag to manifest * fix: use default context for both tags if not specified
1 parent d52649e commit 636e5a3

13 files changed

+2513
-132
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
node_modules/
2+
cypress/videos
3+
cypress/screenshots

CONTRIBUTING.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
How to [code a plugin](https://github.com/netlify/build/blob/master/docs/creating-a-plugin.md)
2+
3+
## Testing and releasing a new version
4+
5+
If helps to install [Netlify CLI](https://github.com/netlify/cli) to test the plugin locally
6+
7+
```shell
8+
npm install netlify-cli -g
9+
netlify build
10+
```
11+
12+
Try using `beta` branch to release new pre-release versions of the plugin by following [the semantic release guide](https://github.com/semantic-release/semantic-release/blob/master/docs/recipes/pre-releases.md). You can fork and test out new versions published to NPM using the [netlify-plugin-cypress-example](https://github.com/cypress-io/netlify-plugin-cypress-example) repository. Hope the `master` branch merged into `beta` does not bring features and fixes *already released*. Thus I suggest using `beta` branch for new features.
13+
14+
**Do not open pull request on CircleCI** while adding new features to the `beta` branch. If there is a pull request, semantic-release refuses to publish new versions. Instead just watch the [builds on CircleCI](https://circleci.com/gh/cypress-io/netlify-plugin-cypress/tree/beta) directly and open the PR after the new version has been tested.

README.md

+51-3
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,39 @@ publish = "build"
7676
[[plugins]]
7777
# local Cypress plugin will test our site after it is built
7878
package = "netlify-plugin-cypress"
79-
[plugins.config]
79+
[plugins.inputs]
8080
record = true
8181
```
8282

8383
See [cypress-example-kitchensink](https://github.com/cypress-io/cypress-example-kitchensink) and recorded results at [![Cypress Dashboard](https://img.shields.io/badge/cypress-dashboard-brightgreen.svg)](https://dashboard.cypress.io/#/projects/4b7344/runs)
8484

85+
#### group
86+
87+
You can change the group name for the recorded run using `group` parameter
88+
89+
```toml
90+
[[plugins]]
91+
# local Cypress plugin will test our site after it is built
92+
package = "netlify-plugin-cypress"
93+
[plugins.inputs]
94+
record = true
95+
group = "built site"
96+
```
97+
98+
#### tag
99+
100+
You can give recorded run [tags](https://on.cypress.io/module-api#cypress-run) using a comma-separated string. If the tag is not specified, Netlify context will be used (`production`, `deploy-preview` or `branch-deploy`)
101+
102+
```toml
103+
[[plugins]]
104+
# local Cypress plugin will test our site after it is built
105+
package = "netlify-plugin-cypress"
106+
[plugins.inputs]
107+
record = true
108+
group = "built site"
109+
tag = "nightly,production"
110+
```
111+
85112
### spec
86113

87114
Run only a single spec or specs matching a wildcard
@@ -102,12 +129,29 @@ publish = "build"
102129
[[plugins]]
103130
# local Cypress plugin will test our site after it is built
104131
package = "netlify-plugin-cypress"
105-
[plugins.config]
132+
[plugins.inputs]
106133
spec = "cypress/integration/smoke*.js"
107134
```
108135

109136
See [cypress-example-kitchensink](https://github.com/cypress-io/cypress-example-kitchensink) for instance.
110137

138+
### testing the site before build
139+
140+
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
141+
142+
```toml
143+
[[plugins]]
144+
package = "netlify-plugin-cypress"
145+
# let's run tests against development server
146+
# before building it (and testing the built site)
147+
[plugins.inputs.preBuild]
148+
start = 'npm start'
149+
wait-on = 'http://localhost:5000'
150+
wait-on-timeout = '30' # seconds
151+
```
152+
153+
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 :)
154+
111155
## Debugging
112156

113157
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`
@@ -141,4 +185,8 @@ Set environment variable `DEBUG=netlify-plugin-cypress` to see the debug logs. T
141185

142186
## License
143187

144-
This project is licensed under the terms of the [MIT license](/LICENSE.md).
188+
This project is licensed under the terms of the [MIT license](LICENSE.md).
189+
190+
## Contributing
191+
192+
Read the [contributing guide](CONTRIBUTING.md)

cypress.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"supportFile": false,
3+
"pluginsFile": false,
4+
"fixturesFolder": false,
5+
"baseUrl": "http://localhost:5000"
6+
}

cypress/integration/spec.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference types="cypress" />
2+
it('loads page', () => {
3+
cy.visit('/')
4+
cy.contains('Placeholder').should('be.visible')
5+
})

index.js

-119
This file was deleted.

manifest.yml

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
name: netlify-plugin-cypress
22
inputs:
3+
# these settings apply during postBuild step
4+
# when we are testing the site served from the distribution folder
35
- name: record
46
default: false
57
- name: spec
8+
- name: group
9+
- name: tag
10+
11+
# tells the plugin how to start the server using custom command
12+
# and waiting for an url, record to the dashboard, tag, etc
13+
# see README "testing the site before build"
14+
- name: preBuild

netlify.toml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# WARNING ⚠️: this is a Netlify file with local Cypress plugin
2+
# so it might look quite different from the user's Netlify configuration
3+
[build]
4+
command = "echo 'Netlify build command ...'"
5+
publish = "public"
6+
[build.environment]
7+
CI = "1"
8+
TERM = "xterm"
9+
CYPRESS_CACHE_FOLDER = "./node_modules/CypressBinary"
10+
11+
[[plugins]]
12+
# local Cypress plugin will test our site after it is built
13+
package = "."
14+
# [plugins.inputs]
15+
# spec = 'cypress/integration/spec.js'
16+
# [plugins.inputs.preBuild]
17+
# start = 'npm start'
18+
# wait-on = 'http://localhost:5000'
19+
# wait-on-timeout = '3' # seconds

0 commit comments

Comments
 (0)