Skip to content

Commit

Permalink
feat: Rewrite py-ios-device client and crash reports logger into type…
Browse files Browse the repository at this point in the history
…script (#2423)
  • Loading branch information
mykola-mokhnach authored Jul 4, 2024
1 parent 953055b commit 8d405e8
Show file tree
Hide file tree
Showing 15 changed files with 434 additions and 323 deletions.
2 changes: 1 addition & 1 deletion lib/commands/certificate.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import path from 'path';
import http from 'http';
import {exec} from 'teen_process';
import {findAPortNotInUse, checkPortStatus} from 'portscanner';
import Pyidevice from '../py-ios-device-client';
import {Pyidevice} from '../real-device-clients/py-ios-device-client';
import {errors} from 'appium/driver';

const CONFIG_EXTENSION = 'mobileconfig';
Expand Down
3 changes: 2 additions & 1 deletion lib/commands/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ export default {
}
if (_.isUndefined(this.logs.syslog)) {
this.logs.crashlog = new IOSCrashLog({
sim: this.device,
sim: /** @type {import('appium-ios-simulator').Simulator} */ (this.device),
udid: this.isRealDevice() ? this.opts.udid : undefined,
log: this.log,
});
this.logs.syslog = this.isRealDevice()
? new IOSDeviceLog({
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default {

const device = /** @type {import('../real-device').RealDevice} */ (this.device);

/** @type {import('../devicectl').AppInfo[]} */
/** @type {import('../real-device-clients/devicectl').AppInfo[]} */
const appInfos = await device.devicectl.listApps(bundleId);
if (_.isEmpty(appInfos)) {
throw new errors.InvalidArgumentError(
Expand Down
7 changes: 3 additions & 4 deletions lib/commands/pcap.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import Pyidevice from '../py-ios-device-client';
import {fs, tempDir, logger, util} from 'appium/support';
import { Pyidevice } from '../real-device-clients/py-ios-device-client';
import {fs, tempDir, util} from 'appium/support';
import {encodeBase64OrUpload} from '../utils';
import {errors} from 'appium/driver';

const MAX_CAPTURE_TIME_SEC = 60 * 60 * 12;
const DEFAULT_EXT = '.pcap';
const pcapLogger = logger.getLogger('pcapd');

export class TrafficCapture {
/** @type {import('teen_process').SubProcess|null} */
Expand All @@ -21,7 +20,7 @@ export class TrafficCapture {
this.mainProcess = /** @type {import('teen_process').SubProcess} */ (
await new Pyidevice(this.udid).collectPcap(this.resultPath)
);
this.mainProcess.on('line-stderr', (line) => pcapLogger.info(line));
this.mainProcess.on('line-stderr', (line) => this.log.info(`[Pcap] ${line}`));
this.log.info(
`Starting network traffic capture session on the device '${this.udid}'. ` +
`Will timeout in ${timeoutSeconds}s`,
Expand Down
27 changes: 27 additions & 0 deletions lib/device-log/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { LogEntry } from '../commands/types';
import { fs } from 'appium/support';
import { createInterface } from 'node:readline';
import _ from 'lodash';

export const DEFAULT_LOG_LEVEL = 'ALL';
export const MAX_JSON_LOG_LENGTH = 200;
Expand All @@ -11,3 +14,27 @@ export function toLogEntry(message: string, timestamp: number, level: string = D
message,
};
}

export interface GrepOptions {
caseInsensitive?: boolean;
}

export async function grepFile(
fullPath: string,
str: string,
opts: GrepOptions = {}
): Promise<boolean> {
const input = fs.createReadStream(fullPath);
const rl = createInterface({input});
return await new Promise((resolve, reject) => {
input.once('error', reject);
rl.on('line', (line) => {
if (opts.caseInsensitive && _.toLower(line).includes(_.toLower(str))
|| !opts.caseInsensitive && line.includes(str)) {
resolve(true);
input.close();
}
});
input.once('end', () => resolve(false));
});
}
146 changes: 0 additions & 146 deletions lib/device-log/ios-crash-log.js

This file was deleted.

Loading

0 comments on commit 8d405e8

Please sign in to comment.