Skip to content

Commit 87678f2

Browse files
chore: Simplify xcodebuild lines monitoring (#916)
1 parent d0c518a commit 87678f2

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

lib/xcodebuild.js

+18-13
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
} from './utils';
1111
import _ from 'lodash';
1212
import path from 'path';
13-
import { EOL } from 'os';
1413
import { WDA_RUNNER_BUNDLE_ID } from './constants';
1514

1615

@@ -26,6 +25,13 @@ const IGNORED_ERRORS = [
2625
ERROR_COPYING_ATTACHMENT,
2726
'Failed to remove screenshot at path',
2827
];
28+
const IGNORED_ERRORS_PATTERN = new RegExp(
29+
'(' +
30+
IGNORED_ERRORS
31+
.map((errStr) => _.escapeRegExp(errStr))
32+
.join('|') +
33+
')'
34+
);
2935

3036
const RUNNER_SCHEME_TV = 'WebDriverAgentRunner_tvOS';
3137
const LIB_SCHEME_TV = 'WebDriverAgentLib_tvOS';
@@ -324,27 +330,26 @@ export class XcodeBuild {
324330
? `Output from xcodebuild ${this.showXcodeLog ? 'will' : 'will not'} be logged`
325331
: 'Output from xcodebuild will only be logged if any errors are present there';
326332
this.log.debug(`${logMsg}. To change this, use 'showXcodeLog' desired capability`);
327-
xcodebuild.on('output', (stdout, stderr) => {
328-
let out = stdout || stderr;
329333

334+
const onStreamLine = (/** @type {string} */ line) => {
335+
if (this.showXcodeLog === false || IGNORED_ERRORS_PATTERN.test(line)) {
336+
return;
337+
}
330338
// if we have an error we want to output the logs
331339
// otherwise the failure is inscrutible
332340
// 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=')) {
335342
logXcodeOutput = true;
336-
337343
// handle case where xcode returns 0 but is failing
338344
this._didBuildFail = true;
339345
}
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);
346348
}
347-
});
349+
};
350+
for (const streamName of ['stderr', 'stdout']) {
351+
xcodebuild.on(`line-${streamName}`, onStreamLine);
352+
}
348353

349354
return xcodebuild;
350355
}

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
},
4949
"homepage": "https://github.com/appium/WebDriverAgent#readme",
5050
"devDependencies": {
51-
"@appium/eslint-config-appium": "^8.0.4",
5251
"@appium/eslint-config-appium-ts": "^0.x",
5352
"@appium/test-support": "^3.0.0",
5453
"@appium/tsconfig": "^0.x",
@@ -86,7 +85,7 @@
8685
"bluebird": "^3.5.5",
8786
"lodash": "^4.17.11",
8887
"source-map-support": "^0.x",
89-
"teen_process": "^2.0.0"
88+
"teen_process": "^2.2.0"
9089
},
9190
"files": [
9291
"index.ts",

tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"extends": "@appium/tsconfig/tsconfig.json",
44
"compilerOptions": {
55
"strict": false, // TODO: make this flag true
6+
"esModuleInterop": true,
67
"outDir": "build",
78
"types": ["node"],
89
"checkJs": true

0 commit comments

Comments
 (0)