Skip to content

Commit f4054a7

Browse files
committed
feat: allow testing preBuild site
1 parent e47c5df commit f4054a7

File tree

5 files changed

+19
-18
lines changed

5 files changed

+19
-18
lines changed

manifest.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
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

netlify.toml

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ publish = "public"
1111
[[plugins]]
1212
# local Cypress plugin will test our site after it is built
1313
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
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

package-lock.json

+2-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
"license": "ISC",
1818
"dependencies": {
1919
"argument-vector": "1.0.2",
20+
"check-more-types": "2.24.0",
2021
"debug": "4.1.1",
2122
"ecstatic": "4.1.2",
2223
"execa": "3.4.0",
23-
"got": "9.6.0"
24+
"got": "9.6.0",
25+
"lazy-ass": "1.6.0"
2426
},
2527
"repository": {
2628
"type": "git",

src/index.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const http = require('http')
44
const execa = require('execa')
55
const debug = require('debug')('netlify-plugin-cypress')
66
const debugVerbose = require('debug')('netlify-plugin-cypress:verbose')
7+
const la = require('lazy-ass')
8+
const is = require('check-more-types')
79
const { ping } = require('./utils')
810

911
function serveFolder (folder, port) {
@@ -133,11 +135,6 @@ async function postBuild({ fullPublishFolder, record, spec, failBuild }) {
133135
processCypressResults(results, failBuild)
134136
}
135137

136-
const throwAnError = (message, info) => {
137-
console.error('Exit with error: %s', message)
138-
throw info.error
139-
}
140-
141138
const hasRecordKey = () => typeof process.env.CYPRESS_RECORD_KEY === 'string'
142139

143140
module.exports = function cypressPlugin (pluginConfig) {
@@ -170,7 +167,8 @@ module.exports = function cypressPlugin (pluginConfig) {
170167
closeServer()
171168
}
172169

173-
const failBuild = arg.utils && arg.utils.build && arg.utils.build.failBuild || throwAnError
170+
const failBuild = arg.utils && arg.utils.build && arg.utils.build.failBuild
171+
la(is.fn(failBuild), 'expected failBuild function inside', arg.utils)
174172

175173
processCypressResults(results, failBuild)
176174
},
@@ -188,7 +186,8 @@ module.exports = function cypressPlugin (pluginConfig) {
188186

189187
const spec = pluginConfig.spec
190188

191-
const failBuild = arg.utils && arg.utils.build && arg.utils.build.failBuild || throwAnError
189+
const failBuild = arg.utils && arg.utils.build && arg.utils.build.failBuild
190+
la(is.fn(failBuild), 'expected failBuild function inside', arg.utils)
192191

193192
return postBuild({
194193
fullPublishFolder,

0 commit comments

Comments
 (0)