Skip to content

Commit e1d95ed

Browse files
authored
feat: add configFile parameter (#147)
1 parent 9456bf1 commit e1d95ed

File tree

11 files changed

+137
-11
lines changed

11 files changed

+137
-11
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,27 @@ package = "netlify-plugin-cypress"
214214
browser = "electron"
215215
```
216216

217+
### configFile
218+
219+
If you would like to use a different Cypress config file instead of `cypress.json`, specify it using the `configFile` option
220+
221+
```toml
222+
[build]
223+
command = "npm run build"
224+
publish = "build"
225+
[build.environment]
226+
# cache Cypress binary in local "node_modules" folder
227+
# so Netlify caches it
228+
CYPRESS_CACHE_FOLDER = "./node_modules/CypressBinary"
229+
# set TERM variable for terminal output
230+
TERM = "xterm"
231+
232+
[[plugins]]
233+
package = "netlify-plugin-cypress"
234+
[plugins.inputs]
235+
configFile = "cypress.netlify.json"
236+
```
237+
217238
### testing SPA routes
218239

219240
SPAs need catch-all redirect setup to make non-root paths accessible by tests. You can enable this with `spa` parameter.

circle.yml

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ jobs:
2121
# since we do not need Cypress to publish the NPM package
2222
# we can skip the binary download
2323
CYPRESS_INSTALL_BINARY: 0
24+
# we also skip Puppeteer Chromium download
25+
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
26+
2427
steps:
2528
- checkout
2629
- node/with-cache:
@@ -154,6 +157,19 @@ jobs:
154157
environment:
155158
DEBUG: netlify-plugin-cypress
156159

160+
config-file:
161+
executor: cypress/base-12-14-0
162+
steps:
163+
# all dependencies were installed in previous job
164+
- attach_workspace:
165+
at: ~/
166+
- run:
167+
name: Netlify Build 🏗
168+
command: npm run netlify:build
169+
working_directory: tests/config-file
170+
environment:
171+
DEBUG: netlify-plugin-cypress
172+
157173
workflows:
158174
version: 2
159175
test_and_release:
@@ -187,18 +203,20 @@ workflows:
187203
- routing:
188204
requires:
189205
- cypress/install
206+
- config-file:
207+
requires:
208+
- cypress/install
190209
- release:
191210
# run the release job on all branches
192211
# since we might want to release a beta version
193212
requires:
194213
- build
195-
# temporary while publishing pre-release
196-
# - 'basic test'
197-
# - 'html-pages'
198-
# - 'recommended test'
199-
# - 'recording test'
200-
# - 'test-twice'
201-
# - 'test-prebuild-only'
202-
# - test-using-chromium
203-
# - test-netlify-dev
204-
# - 'routing'
214+
- 'basic test'
215+
- 'html-pages'
216+
- 'recommended test'
217+
- 'recording test'
218+
- 'test-twice'
219+
- 'test-prebuild-only'
220+
- test-using-chromium
221+
- test-netlify-dev
222+
- 'routing'

manifest.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ inputs:
1212
description: Allowed values are chromium, electron
1313
default: chromium
1414

15+
- name: configFile
16+
description: Path to the Cypress config file to use
17+
1518
- name: record
1619
description: Record test results to Cypress Dashboard
1720
default: false

src/index.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,15 @@ async function waitOnMaybe(buildUtils, options = {}) {
5959

6060
const isValidBrowser = (name) => name === 'electron' || name === 'chromium'
6161

62-
async function runCypressTests(baseUrl, record, spec, group, tag, browser) {
62+
async function runCypressTests(
63+
baseUrl,
64+
record,
65+
spec,
66+
group,
67+
tag,
68+
browser,
69+
configFile,
70+
) {
6371
if (!isValidBrowser(browser)) {
6472
throw new Error(`Invalid browser name "${browser}"`)
6573
}
@@ -99,6 +107,7 @@ async function runCypressTests(baseUrl, record, spec, group, tag, browser) {
99107
ciBuildId,
100108
browser: browserPath,
101109
headless: true,
110+
configFile,
102111
})
103112
}
104113

@@ -236,6 +245,7 @@ async function postBuild({
236245
tag,
237246
spa,
238247
browser,
248+
configFile,
239249
errorCallback,
240250
summaryCallback,
241251
}) {
@@ -260,6 +270,7 @@ async function postBuild({
260270
group,
261271
tag,
262272
browser,
273+
configFile,
263274
)
264275

265276
await new Promise((resolve, reject) => {
@@ -315,13 +326,16 @@ module.exports = {
315326
}
316327
}
317328

329+
const configFile = preBuildInputs.configFile
330+
318331
const results = await runCypressTests(
319332
baseUrl,
320333
record,
321334
spec,
322335
group,
323336
tag,
324337
browser,
338+
configFile,
325339
)
326340

327341
if (closeServer) {
@@ -369,6 +383,7 @@ module.exports = {
369383
}
370384
}
371385
const spa = postBuildInputs.spa
386+
const configFile = postBuildInputs.configFile
372387

373388
const errorCallback = utils.build.failBuild.bind(utils.build)
374389
const summaryCallback = utils.status.show.bind(utils.status)
@@ -381,6 +396,7 @@ module.exports = {
381396
tag,
382397
spa,
383398
browser,
399+
configFile,
384400
errorCallback,
385401
summaryCallback,
386402
})
@@ -448,6 +464,8 @@ module.exports = {
448464
tag,
449465
})
450466

467+
const configFile = onSuccessInputs.configFile
468+
451469
console.log('testing deployed url %s', deployPrimeUrl)
452470
const results = await runCypressTests(
453471
deployPrimeUrl,
@@ -456,6 +474,7 @@ module.exports = {
456474
group,
457475
tag,
458476
browser,
477+
configFile,
459478
)
460479
processCypressResults(results, errorCallback, summaryCallback)
461480
},

tests/config-file/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# using specific config file
2+
3+
These tests specify non-default Cypress configuration file to use
4+
5+
These tests run:
6+
- [ ] before the build
7+
- [x] after the build
8+
- [ ] on deploy success
9+
10+
## Local testing
11+
12+
```
13+
DEBUG=netlify-plugin-cypress npm run netlify:build
14+
```

tests/config-file/cypress.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"pluginsFile": false,
3+
"supportFile": false,
4+
"fixturesFolder": false
5+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"pluginsFile": false,
3+
"supportFile": false,
4+
"fixturesFolder": false,
5+
"env": {
6+
"CUSTOM_FILE": 42
7+
}
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/// <reference types="cypress" />
2+
describe('custom config file', () => {
3+
it('uses cypress.netlify.json', () => {
4+
// this property is set in the cypress.netlify.json file
5+
expect(Cypress.env()).to.have.property('CUSTOM_FILE', 42)
6+
})
7+
})

tests/config-file/netlify.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[build]
2+
command = "echo 'Netlify build command ...'"
3+
publish = "public"
4+
5+
[[plugins]]
6+
# local Cypress plugin will test our site after it is built
7+
# in production, please use: package = "netlify-plugin-cypress"
8+
package = "../../"
9+
10+
# do not run tests after deploy (testing)
11+
[plugins.inputs]
12+
enable = false
13+
configFile = "cypress.netlify.json"
14+
15+
# run tests postBuild
16+
[plugins.inputs.postBuild]
17+
enable = true
18+
configFile = "cypress.netlify.json"

tests/config-file/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "config-file",
3+
"version": "0.1.0",
4+
"private": true,
5+
"scripts": {
6+
"start": "../../node_modules/.bin/react-scripts start",
7+
"build": "../../node_modules/.bin/react-scripts build",
8+
"cypress:open": "../../node_modules/.bin/cypress open",
9+
"cypress:run": "../../node_modules/.bin/cypress run",
10+
"netlify:build": "../../node_modules/.bin/netlify build"
11+
}
12+
}

tests/config-file/public/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h1>Basic</h1>

0 commit comments

Comments
 (0)