@@ -20,7 +20,6 @@ const fs = require('fs');
2020const log = require ( 'fancy-log' ) ;
2121const opn = require ( 'opn' ) ;
2222const path = require ( 'path' ) ;
23-
2423const {
2524 reportTestErrored,
2625 reportTestFinished,
@@ -195,18 +194,20 @@ function karmaBrowserStart_(browser) {
195194 * @param {Object } browser
196195 * @private
197196 */
198- function karmaBrowserComplete_ ( browser ) {
197+ async function karmaBrowserComplete_ ( browser ) {
199198 const result = browser . lastResult ;
200199 result . total = result . success + result . failed + result . skipped ;
201- // Prevent cases where Karma detects zero tests and still passes. #16851.
200+ // Set test status to "error" if browser_complete shows zero tests (#16851).
201+ // Sometimes, Sauce labs can follow this up with another successful status, in
202+ // which case the error status will be replaced by a pass / fail status.
202203 if ( result . total == 0 ) {
203- log ( red ( 'ERROR: Zero tests detected by Karma.' ) ) ;
204- log ( red ( JSON . stringify ( result ) ) ) ;
205- reportTestErrored ( ) . finally ( ( ) => {
206- if ( ! argv . watch ) {
207- process . exit ( 1 ) ;
208- }
209- } ) ;
204+ log (
205+ yellow ( 'WARNING:' ) ,
206+ 'Received a status with zero tests:' ,
207+ cyan ( JSON . stringify ( result ) )
208+ ) ;
209+ await reportTestErrored ( ) ;
210+ return ;
210211 }
211212 // Print a summary for each browser as soon as tests complete.
212213 let message =
@@ -265,7 +266,7 @@ async function runTestInSauceLabs(config) {
265266
266267 if ( argv . beta ) {
267268 config . browsers = browsers . beta ;
268- const betaExitCode = await createKarmaServer ( config , ( ) => { } ) ;
269+ const betaExitCode = await createKarmaServer ( config , reportTestRunComplete ) ;
269270 if ( betaExitCode != 0 ) {
270271 log (
271272 yellow ( 'Some tests have failed on' ) ,
@@ -300,14 +301,22 @@ async function runTestInSauceLabs(config) {
300301 */
301302async function runTestInBatches_ ( config , browsers ) {
302303 let errored = false ;
303- let totalStableSuccess = 0 ;
304- let totalStableFailed = 0 ;
304+ let totalSuccess = 0 ;
305+ let totalFailed = 0 ;
305306 const partialTestRunCompleteFn = async ( browsers , results ) => {
306307 if ( results . error ) {
307308 errored = true ;
308309 } else {
309- totalStableSuccess += results . success ;
310- totalStableFailed += results . failed ;
310+ totalSuccess += results . success ;
311+ totalFailed += results . failed ;
312+ }
313+ } ;
314+
315+ const reportResults = async ( ) => {
316+ if ( errored ) {
317+ await reportTestErrored ( ) ;
318+ } else {
319+ await reportTestFinished ( totalSuccess , totalFailed ) ;
311320 }
312321 } ;
313322
@@ -318,12 +327,8 @@ async function runTestInBatches_(config, browsers) {
318327 config ,
319328 partialTestRunCompleteFn
320329 ) ;
321- if ( errored ) {
322- await reportTestErrored ( ) ;
323- } else {
324- await reportTestFinished ( totalStableSuccess , totalStableFailed ) ;
325- }
326330 if ( allBatchesExitCodes || errored ) {
331+ await reportResults ( ) ;
327332 log (
328333 yellow ( 'Some tests have failed on' ) ,
329334 cyan ( 'stable' ) ,
@@ -340,7 +345,7 @@ async function runTestInBatches_(config, browsers) {
340345 'beta' ,
341346 browsers . beta ,
342347 config ,
343- /* runCompleteFn */ ( ) => { }
348+ partialTestRunCompleteFn
344349 ) ;
345350 if ( allBatchesExitCodes ) {
346351 log (
@@ -356,6 +361,7 @@ async function runTestInBatches_(config, browsers) {
356361 }
357362 }
358363
364+ await reportResults ( ) ;
359365 return 0 ;
360366}
361367
0 commit comments