Skip to content

Commit c05fee5

Browse files
authored
feat: add skip=true flag to postBuild tests (#105)
1 parent 5063885 commit c05fee5

File tree

9 files changed

+83
-0
lines changed

9 files changed

+83
-0
lines changed

CONTRIBUTING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ How to [code a plugin](https://github.com/netlify/build/blob/master/docs/creatin
44

55
End-to-end tests are in folder [tests](tests) and they use this [plugin locally](https://github.com/netlify/build/blob/master/README.md#using-a-local-plugin) and build each subfolder using Netlify CLI on CircleCI. You can find the test recordings at [Cypress Dashboard](https://dashboard.cypress.io/projects/ixroqc/)
66

7+
To run locally:
8+
9+
- `npx netlify link` once
10+
- from every subfolder of `tests` execute `npm run build`
11+
712
### Authentication (local)
813

914
- use `netlify-cli` to authenticate locally. It will also create a local site and store its ID in `.netlify` folder (ignored by `git`)

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,17 @@ Parameters you can place into `preBuild` inputs: `start`, `wait-on`, `wait-on-ti
189189

190190
See [netlify-plugin-prebuild-example](https://github.com/cypress-io/netlify-plugin-prebuild-example) repo
191191

192+
### skipping tests
193+
194+
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):
195+
196+
```toml
197+
[[plugins]]
198+
package = "netlify-plugin-cypress"
199+
[plugins.inputs]
200+
skip = true
201+
```
202+
192203
### parallelization
193204

194205
Running tests in parallel **is not supported** because Netlify plugin system runs on a single machine. Thus you can record the tests on Cypress Dashboard, but not run tests in parallel. If Netlify expands its build offering by allowing multiple build machines, we could take advantage of it and run tests in parallel.

circle.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,19 @@ jobs:
7676
environment:
7777
DEBUG: netlify-plugin-cypress
7878

79+
'test-prebuild-only':
80+
executor: cypress/base-12-14-0
81+
steps:
82+
# all dependencies were installed in previous job
83+
- attach_workspace:
84+
at: ~/
85+
- run:
86+
name: Netlify Build 🏗
87+
command: npx netlify build
88+
working_directory: tests/test-prebuild-only
89+
environment:
90+
DEBUG: netlify-plugin-cypress
91+
7992
routing:
8093
executor: cypress/base-12-14-0
8194
steps:
@@ -107,6 +120,9 @@ workflows:
107120
- 'test-twice':
108121
requires:
109122
- cypress/install
123+
- 'test-prebuild-only':
124+
requires:
125+
- cypress/install
110126
- routing:
111127
requires:
112128
- cypress/install
@@ -117,6 +133,7 @@ workflows:
117133
- 'recommended test'
118134
- 'recording test'
119135
- 'test-twice'
136+
- 'test-prebuild-only'
120137
- 'routing'
121138
filters:
122139
branches:

manifest.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ inputs:
88
- name: group
99
- name: tag
1010
- name: spa
11+
# by default run the tests
12+
- name: skip
13+
default: false
1114

1215
# tells the plugin how to start the server using custom command
1316
# and waiting for an url, record to the dashboard, tag, etc

src/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,12 @@ module.exports = {
255255
debugVerbose('postBuild arg %o', arg)
256256
debug('cypress plugin postBuild inputs %o', arg.inputs)
257257

258+
const skipTests = Boolean(arg.inputs.skip)
259+
if (skipTests) {
260+
console.log('Skipping tests because skip=true')
261+
return
262+
}
263+
258264
const fullPublishFolder = arg.constants.PUBLISH_DIR
259265
debug('folder to publish is "%s"', fullPublishFolder)
260266

tests/test-prebuild-only/cypress.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"pluginsFile": false,
3+
"supportFile": false,
4+
"fixturesFolder": false,
5+
"baseUrl": "http://localhost:5000",
6+
"projectId": "ixroqc"
7+
}
Lines changed: 5 additions & 0 deletions
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+
})

tests/test-prebuild-only/netlify.toml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[build]
2+
command = "echo 'Netlify build command ...'"
3+
publish = "public"
4+
5+
[build.environment]
6+
# cache Cypress binary in local "node_modules" folder
7+
# so Netlify caches it
8+
CYPRESS_CACHE_FOLDER = "./node_modules/CypressBinary"
9+
# set TERM variable for terminal output
10+
TERM = "xterm"
11+
12+
[[plugins]]
13+
# local Cypress plugin will test our site after it is built
14+
# in production, please use: package = "netlify-plugin-cypress"
15+
package = "../../"
16+
17+
# run Cypress tests once on the site before it is built
18+
# and do not run the tests after it was built
19+
20+
# let's run tests against development server
21+
[plugins.inputs.preBuild]
22+
start = 'npx serve public'
23+
wait-on = 'http://localhost:5000'
24+
wait-on-timeout = '30' # seconds
25+
26+
# and skip tests after building it
27+
[plugins.inputs]
28+
skip = true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<body>Placeholder</body>

0 commit comments

Comments
 (0)