1
1
// @ts -check
2
+ const { stripIndent } = require ( 'common-tags' )
2
3
const debug = require ( 'debug' ) ( 'netlify-plugin-cypress' )
3
4
const debugVerbose = require ( 'debug' ) ( 'netlify-plugin-cypress:verbose' )
4
5
const { ping, getBrowserPath, serveFolder } = require ( './utils' )
5
6
7
+ const PLUGIN_NAME = 'netlify-plugin-cypress'
6
8
const DEFAULT_BROWSER = 'electron'
7
9
8
10
function startServerMaybe ( run , options = { } ) {
@@ -153,13 +155,28 @@ async function cypressInfo(arg) {
153
155
}
154
156
}
155
157
156
- const processCypressResults = ( results , errorCallback ) => {
158
+ /**
159
+ * Reports the number of successful and failed tests.
160
+ * If there are failed tests, uses the `errorCallback` to
161
+ * fail the build step.
162
+ * @param {* } results
163
+ * @param {function } errorCallback
164
+ * @param {function } summaryCallback
165
+ */
166
+ const processCypressResults = ( results , errorCallback , summaryCallback ) => {
157
167
if ( typeof errorCallback !== 'function' ) {
158
168
debug ( 'Typeof of error callback %s' , errorCallback )
159
169
throw new Error (
160
170
`Expected error callback to be a function, it was ${ typeof errorCallback } ` ,
161
171
)
162
172
}
173
+ if ( typeof summaryCallback !== 'function' ) {
174
+ debug ( 'Typeof of summary callback %s' , summaryCallback )
175
+ throw new Error (
176
+ `Expected summary callback to be a function, it was ${ typeof summaryCallback } ` ,
177
+ )
178
+ }
179
+
163
180
if ( results . failures ) {
164
181
// Cypress failed without even running the tests
165
182
console . error ( 'Problem running Cypress' )
@@ -177,6 +194,27 @@ const processCypressResults = (results, errorCallback) => {
177
194
}
178
195
} )
179
196
197
+ let text = stripIndent `
198
+ ✅ Passed tests: ${ results . totalPassed }
199
+ 🔥 Failed tests: ${ results . totalFailed }
200
+ ⭕️ Pending tests: ${ results . totalPending }
201
+ 🚫 Skipped tests: ${ results . totalSkipped }
202
+ `
203
+ if ( results . runUrl ) {
204
+ text += `\n🔗 Dashboard url: ${ results . runUrl } `
205
+ }
206
+ summaryCallback ( {
207
+ title : PLUGIN_NAME ,
208
+ summary : [
209
+ 'tests:' ,
210
+ `✅ ${ results . totalPassed } ` ,
211
+ `🔥 ${ results . totalFailed } ` ,
212
+ `⭕️ ${ results . totalPending } ` ,
213
+ `🚫 ${ results . totalSkipped } ` ,
214
+ ] . join ( ' ' ) ,
215
+ text,
216
+ } )
217
+
180
218
// results.totalFailed gives total number of failed tests
181
219
if ( results . totalFailed ) {
182
220
return errorCallback ( 'Failed Cypress tests' , {
@@ -194,6 +232,7 @@ async function postBuild({
194
232
spa,
195
233
browser,
196
234
errorCallback,
235
+ summaryCallback,
197
236
} ) {
198
237
const port = 8080
199
238
let server
@@ -228,7 +267,7 @@ async function postBuild({
228
267
} )
229
268
} )
230
269
231
- processCypressResults ( results , errorCallback )
270
+ processCypressResults ( results , errorCallback , summaryCallback )
232
271
}
233
272
234
273
const hasRecordKey = ( ) => typeof process . env . CYPRESS_RECORD_KEY === 'string'
@@ -281,8 +320,9 @@ module.exports = {
281
320
}
282
321
283
322
const errorCallback = arg . utils . build . failBuild . bind ( arg . utils . build )
323
+ const summaryCallback = arg . utils . status . show . bind ( arg . utils . status )
284
324
285
- processCypressResults ( results , errorCallback )
325
+ processCypressResults ( results , errorCallback , summaryCallback )
286
326
} ,
287
327
288
328
onPostBuild : async ( arg ) => {
@@ -319,6 +359,7 @@ module.exports = {
319
359
const spa = arg . inputs . spa
320
360
321
361
const errorCallback = arg . utils . build . failBuild . bind ( arg . utils . build )
362
+ const summaryCallback = arg . utils . status . show . bind ( arg . utils . status )
322
363
323
364
await postBuild ( {
324
365
fullPublishFolder,
@@ -329,9 +370,14 @@ module.exports = {
329
370
spa,
330
371
browser,
331
372
errorCallback,
373
+ summaryCallback,
332
374
} )
333
375
} ,
334
376
377
+ /**
378
+ * Executes after successful Netlify deployment.
379
+ * @param {any } arg
380
+ */
335
381
onSuccess : async ( arg ) => {
336
382
debugVerbose ( 'onSuccess arg %o' , arg )
337
383
@@ -363,6 +409,7 @@ module.exports = {
363
409
debug ( 'onSuccessInputs %s %o' , typeof onSuccessInputs , onSuccessInputs )
364
410
365
411
const errorCallback = utils . build . failPlugin . bind ( utils . build )
412
+ const summaryCallback = utils . status . show . bind ( utils . status )
366
413
367
414
if ( ! deployPrimeUrl ) {
368
415
return errorCallback ( 'Missing DEPLOY_PRIME_URL' )
@@ -404,6 +451,6 @@ module.exports = {
404
451
tag ,
405
452
browser ,
406
453
)
407
- processCypressResults ( results , errorCallback )
454
+ processCypressResults ( results , errorCallback , summaryCallback )
408
455
} ,
409
456
}
0 commit comments