@@ -3,8 +3,6 @@ const ecstatic = require('ecstatic')
3
3
const http = require ( 'http' )
4
4
const debug = require ( 'debug' ) ( 'netlify-plugin-cypress' )
5
5
const debugVerbose = require ( 'debug' ) ( 'netlify-plugin-cypress:verbose' )
6
- const la = require ( 'lazy-ass' )
7
- const is = require ( 'check-more-types' )
8
6
const { ping } = require ( './utils' )
9
7
10
8
function serveFolder ( folder , port ) {
@@ -33,7 +31,7 @@ function startServerMaybe (run, options = {}) {
33
31
}
34
32
}
35
33
36
- async function waitOnMaybe ( failPlugin , options = { } ) {
34
+ async function waitOnMaybe ( buildUtils , options = { } ) {
37
35
const waitOnUrl = options [ 'wait-on' ]
38
36
if ( ! waitOnUrl ) {
39
37
debug ( 'no wait-on defined' )
@@ -56,7 +54,7 @@ async function waitOnMaybe (failPlugin, options = {}) {
56
54
} catch ( err ) {
57
55
debug ( 'pinging %s for %d ms failed' , waitOnUrl , waitTimeoutMs )
58
56
debug ( err )
59
- failPlugin ( `Pinging ${ waitOnUrl } for ${ waitTimeoutMs } failed` , { error : err } )
57
+ return buildUtils . failBuild ( `Pinging ${ waitOnUrl } for ${ waitTimeoutMs } failed` , { error : err } )
60
58
}
61
59
}
62
60
@@ -95,13 +93,13 @@ async function onInit(arg) {
95
93
await arg . utils . run ( 'cypress' , [ 'install' ] , runOptions )
96
94
}
97
95
98
- const processCypressResults = ( results , failPlugin ) => {
96
+ const processCypressResults = ( results , buildUtils ) => {
99
97
if ( results . failures ) {
100
98
// Cypress failed without even running the tests
101
99
console . error ( 'Problem running Cypress' )
102
100
console . error ( results . message )
103
101
104
- return failPlugin ( 'Problem running Cypress' , {
102
+ return buildUtils . failPlugin ( 'Problem running Cypress' , {
105
103
error : new Error ( results . message )
106
104
} )
107
105
}
@@ -115,13 +113,13 @@ const processCypressResults = (results, failPlugin) => {
115
113
116
114
// results.totalFailed gives total number of failed tests
117
115
if ( results . totalFailed ) {
118
- return failPlugin ( 'Failed Cypress tests' , {
116
+ return buildUtils . failBuild ( 'Failed Cypress tests' , {
119
117
error : new Error ( `${ results . totalFailed } test(s) failed` )
120
118
} )
121
119
}
122
120
}
123
121
124
- async function postBuild ( { fullPublishFolder, record, spec, group, tag, failPlugin } ) {
122
+ async function postBuild ( { fullPublishFolder, record, spec, group, tag, buildUtils } ) {
125
123
const port = 8080
126
124
const server = serveFolder ( fullPublishFolder , port )
127
125
debug ( 'local server listening on port %d' , port )
@@ -140,7 +138,7 @@ async function postBuild({ fullPublishFolder, record, spec, group, tag, failPlug
140
138
} )
141
139
} )
142
140
143
- processCypressResults ( results , failPlugin )
141
+ processCypressResults ( results , buildUtils )
144
142
}
145
143
146
144
const hasRecordKey = ( ) => typeof process . env . CYPRESS_RECORD_KEY === 'string'
@@ -155,11 +153,8 @@ module.exports = {
155
153
return
156
154
}
157
155
158
- const failPlugin = arg . utils && arg . utils . build && arg . utils . build . failPlugin
159
- la ( is . fn ( failPlugin ) , 'expected failPlugin function inside' , arg . utils )
160
-
161
156
const closeServer = startServerMaybe ( arg . utils . run , preBuildInputs )
162
- await waitOnMaybe ( failPlugin , preBuildInputs )
157
+ await waitOnMaybe ( arg . utils . build , preBuildInputs )
163
158
164
159
const baseUrl = preBuildInputs [ 'wait-on' ]
165
160
const record = hasRecordKey ( ) && Boolean ( preBuildInputs . record )
@@ -183,7 +178,7 @@ module.exports = {
183
178
closeServer ( )
184
179
}
185
180
186
- processCypressResults ( results , failPlugin )
181
+ processCypressResults ( results , arg . utils . build )
187
182
} ,
188
183
189
184
onPostBuild : async ( arg ) => {
@@ -210,16 +205,15 @@ module.exports = {
210
205
}
211
206
}
212
207
213
- const failPlugin = arg . utils && arg . utils . build && arg . utils . build . failPlugin
214
- la ( is . fn ( failPlugin ) , 'expected failPlugin function inside' , arg . utils )
208
+ const buildUtils = arg . utils . build
215
209
216
210
await postBuild ( {
217
211
fullPublishFolder,
218
212
record,
219
213
spec,
220
214
group,
221
215
tag,
222
- failPlugin
216
+ buildUtils ,
223
217
} )
224
218
}
225
219
}
0 commit comments