@@ -3,8 +3,6 @@ const ecstatic = require('ecstatic')
33const http = require ( 'http' )
44const debug = require ( 'debug' ) ( 'netlify-plugin-cypress' )
55const debugVerbose = require ( 'debug' ) ( 'netlify-plugin-cypress:verbose' )
6- const la = require ( 'lazy-ass' )
7- const is = require ( 'check-more-types' )
86const { ping } = require ( './utils' )
97
108function serveFolder ( folder , port ) {
@@ -33,7 +31,7 @@ function startServerMaybe (run, options = {}) {
3331 }
3432}
3533
36- async function waitOnMaybe ( failPlugin , options = { } ) {
34+ async function waitOnMaybe ( buildUtils , options = { } ) {
3735 const waitOnUrl = options [ 'wait-on' ]
3836 if ( ! waitOnUrl ) {
3937 debug ( 'no wait-on defined' )
@@ -56,7 +54,7 @@ async function waitOnMaybe (failPlugin, options = {}) {
5654 } catch ( err ) {
5755 debug ( 'pinging %s for %d ms failed' , waitOnUrl , waitTimeoutMs )
5856 debug ( err )
59- failPlugin ( `Pinging ${ waitOnUrl } for ${ waitTimeoutMs } failed` , { error : err } )
57+ return buildUtils . failBuild ( `Pinging ${ waitOnUrl } for ${ waitTimeoutMs } failed` , { error : err } )
6058 }
6159}
6260
@@ -95,13 +93,13 @@ async function onInit(arg) {
9593 await arg . utils . run ( 'cypress' , [ 'install' ] , runOptions )
9694}
9795
98- const processCypressResults = ( results , failPlugin ) => {
96+ const processCypressResults = ( results , buildUtils ) => {
9997 if ( results . failures ) {
10098 // Cypress failed without even running the tests
10199 console . error ( 'Problem running Cypress' )
102100 console . error ( results . message )
103101
104- return failPlugin ( 'Problem running Cypress' , {
102+ return buildUtils . failPlugin ( 'Problem running Cypress' , {
105103 error : new Error ( results . message )
106104 } )
107105 }
@@ -115,13 +113,13 @@ const processCypressResults = (results, failPlugin) => {
115113
116114 // results.totalFailed gives total number of failed tests
117115 if ( results . totalFailed ) {
118- return failPlugin ( 'Failed Cypress tests' , {
116+ return buildUtils . failBuild ( 'Failed Cypress tests' , {
119117 error : new Error ( `${ results . totalFailed } test(s) failed` )
120118 } )
121119 }
122120}
123121
124- async function postBuild ( { fullPublishFolder, record, spec, group, tag, failPlugin } ) {
122+ async function postBuild ( { fullPublishFolder, record, spec, group, tag, buildUtils } ) {
125123 const port = 8080
126124 const server = serveFolder ( fullPublishFolder , port )
127125 debug ( 'local server listening on port %d' , port )
@@ -140,7 +138,7 @@ async function postBuild({ fullPublishFolder, record, spec, group, tag, failPlug
140138 } )
141139 } )
142140
143- processCypressResults ( results , failPlugin )
141+ processCypressResults ( results , buildUtils )
144142}
145143
146144const hasRecordKey = ( ) => typeof process . env . CYPRESS_RECORD_KEY === 'string'
@@ -155,11 +153,8 @@ module.exports = {
155153 return
156154 }
157155
158- const failPlugin = arg . utils && arg . utils . build && arg . utils . build . failPlugin
159- la ( is . fn ( failPlugin ) , 'expected failPlugin function inside' , arg . utils )
160-
161156 const closeServer = startServerMaybe ( arg . utils . run , preBuildInputs )
162- await waitOnMaybe ( failPlugin , preBuildInputs )
157+ await waitOnMaybe ( arg . utils . build , preBuildInputs )
163158
164159 const baseUrl = preBuildInputs [ 'wait-on' ]
165160 const record = hasRecordKey ( ) && Boolean ( preBuildInputs . record )
@@ -183,7 +178,7 @@ module.exports = {
183178 closeServer ( )
184179 }
185180
186- processCypressResults ( results , failPlugin )
181+ processCypressResults ( results , arg . utils . build )
187182 } ,
188183
189184 onPostBuild : async ( arg ) => {
@@ -210,16 +205,15 @@ module.exports = {
210205 }
211206 }
212207
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
215209
216210 await postBuild ( {
217211 fullPublishFolder,
218212 record,
219213 spec,
220214 group,
221215 tag,
222- failPlugin
216+ buildUtils ,
223217 } )
224218 }
225219}
0 commit comments