@@ -10,7 +10,6 @@ import {
10
10
} from './utils' ;
11
11
import _ from 'lodash' ;
12
12
import path from 'path' ;
13
- import { EOL } from 'os' ;
14
13
import { WDA_RUNNER_BUNDLE_ID } from './constants' ;
15
14
16
15
@@ -26,6 +25,13 @@ const IGNORED_ERRORS = [
26
25
ERROR_COPYING_ATTACHMENT ,
27
26
'Failed to remove screenshot at path' ,
28
27
] ;
28
+ const IGNORED_ERRORS_PATTERN = new RegExp (
29
+ '(' +
30
+ IGNORED_ERRORS
31
+ . map ( ( errStr ) => _ . escapeRegExp ( errStr ) )
32
+ . join ( '|' ) +
33
+ ')'
34
+ ) ;
29
35
30
36
const RUNNER_SCHEME_TV = 'WebDriverAgentRunner_tvOS' ;
31
37
const LIB_SCHEME_TV = 'WebDriverAgentLib_tvOS' ;
@@ -324,27 +330,26 @@ export class XcodeBuild {
324
330
? `Output from xcodebuild ${ this . showXcodeLog ? 'will' : 'will not' } be logged`
325
331
: 'Output from xcodebuild will only be logged if any errors are present there' ;
326
332
this . log . debug ( `${ logMsg } . To change this, use 'showXcodeLog' desired capability` ) ;
327
- xcodebuild . on ( 'output' , ( stdout , stderr ) => {
328
- let out = stdout || stderr ;
329
333
334
+ const onStreamLine = ( /** @type {string } */ line ) => {
335
+ if ( this . showXcodeLog === false || IGNORED_ERRORS_PATTERN . test ( line ) ) {
336
+ return ;
337
+ }
330
338
// if we have an error we want to output the logs
331
339
// otherwise the failure is inscrutible
332
340
// but do not log permission errors from trying to write to attachments folder
333
- const ignoreError = IGNORED_ERRORS . some ( ( x ) => out . includes ( x ) ) ;
334
- if ( this . showXcodeLog !== false && out . includes ( 'Error Domain=' ) && ! ignoreError ) {
341
+ if ( line . includes ( 'Error Domain=' ) ) {
335
342
logXcodeOutput = true ;
336
-
337
343
// handle case where xcode returns 0 but is failing
338
344
this . _didBuildFail = true ;
339
345
}
340
-
341
- // do not log permission errors from trying to write to attachments folder
342
- if ( logXcodeOutput && ! ignoreError ) {
343
- for ( const line of out . split ( EOL ) ) {
344
- xcodeLog . error ( line ) ;
345
- }
346
+ if ( logXcodeOutput ) {
347
+ xcodeLog . info ( line ) ;
346
348
}
347
- } ) ;
349
+ } ;
350
+ for ( const streamName of [ 'stderr' , 'stdout' ] ) {
351
+ xcodebuild . on ( `line-${ streamName } ` , onStreamLine ) ;
352
+ }
348
353
349
354
return xcodebuild ;
350
355
}
0 commit comments