Skip to content

Commit

Permalink
chore: Simplify xcodebuild lines monitoring (#916)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Jul 2, 2024
1 parent d0c518a commit 87678f2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
31 changes: 18 additions & 13 deletions lib/xcodebuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
} from './utils';
import _ from 'lodash';
import path from 'path';
import { EOL } from 'os';
import { WDA_RUNNER_BUNDLE_ID } from './constants';


Expand All @@ -26,6 +25,13 @@ const IGNORED_ERRORS = [
ERROR_COPYING_ATTACHMENT,
'Failed to remove screenshot at path',
];
const IGNORED_ERRORS_PATTERN = new RegExp(
'(' +
IGNORED_ERRORS
.map((errStr) => _.escapeRegExp(errStr))
.join('|') +
')'
);

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

const onStreamLine = (/** @type {string} */ line) => {
if (this.showXcodeLog === false || IGNORED_ERRORS_PATTERN.test(line)) {
return;
}
// if we have an error we want to output the logs
// otherwise the failure is inscrutible
// but do not log permission errors from trying to write to attachments folder
const ignoreError = IGNORED_ERRORS.some((x) => out.includes(x));
if (this.showXcodeLog !== false && out.includes('Error Domain=') && !ignoreError) {
if (line.includes('Error Domain=')) {
logXcodeOutput = true;

// handle case where xcode returns 0 but is failing
this._didBuildFail = true;
}

// do not log permission errors from trying to write to attachments folder
if (logXcodeOutput && !ignoreError) {
for (const line of out.split(EOL)) {
xcodeLog.error(line);
}
if (logXcodeOutput) {
xcodeLog.info(line);
}
});
};
for (const streamName of ['stderr', 'stdout']) {
xcodebuild.on(`line-${streamName}`, onStreamLine);
}

return xcodebuild;
}
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
},
"homepage": "https://github.com/appium/WebDriverAgent#readme",
"devDependencies": {
"@appium/eslint-config-appium": "^8.0.4",
"@appium/eslint-config-appium-ts": "^0.x",
"@appium/test-support": "^3.0.0",
"@appium/tsconfig": "^0.x",
Expand Down Expand Up @@ -86,7 +85,7 @@
"bluebird": "^3.5.5",
"lodash": "^4.17.11",
"source-map-support": "^0.x",
"teen_process": "^2.0.0"
"teen_process": "^2.2.0"
},
"files": [
"index.ts",
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"extends": "@appium/tsconfig/tsconfig.json",
"compilerOptions": {
"strict": false, // TODO: make this flag true
"esModuleInterop": true,
"outDir": "build",
"types": ["node"],
"checkJs": true
Expand Down

0 comments on commit 87678f2

Please sign in to comment.