-
-
Notifications
You must be signed in to change notification settings - Fork 410
/
ios-crash-log.js
56 lines (52 loc) · 1.73 KB
/
ios-crash-log.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { IOSCrashLog as IOSDriverIOSCrashLog } from 'appium-ios-driver';
import { fs } from 'appium-support';
import B from 'bluebird';
import log from '../logger';
import { utilities } from 'appium-ios-device';
import path from 'path';
class IOSCrashLog extends IOSDriverIOSCrashLog {
constructor (opts = {}) {
super(opts.udid ?
path.resolve(process.env.HOME, 'Library', 'Logs', 'CrashReporter', 'MobileDevice') :
path.resolve(process.env.HOME, 'Library', 'Logs', 'DiagnosticReports'));
this.udid = opts.udid;
this.phoneName = null;
this.sim = opts.sim;
}
async getCrashes () {
let crashLogsRoot = this.logDir;
if (this.udid) {
this.phoneName = this.phoneName || await utilities.getDeviceName(this.udid);
crashLogsRoot = path.resolve(crashLogsRoot, this.phoneName);
}
if (!await fs.exists(crashLogsRoot)) {
log.debug(`Crash reports root '${crashLogsRoot}' does not exist. Got nothing to gather.`);
return [];
}
const foundFiles = await fs.glob(`${crashLogsRoot}/**/*.crash`);
if (this.udid) {
return foundFiles;
}
// For Simulator only include files, that contain current UDID
return await B.filter(foundFiles, async (x) => {
try {
const content = await fs.readFile(x, 'utf8');
return content.toUpperCase().includes(this.sim.udid.toUpperCase());
} catch (err) {
return false;
}
});
}
async filesToJSON (paths) {
return await B.map(paths, async (fullPath) => {
const stat = await fs.stat(fullPath);
return {
timestamp: stat.ctime.getTime(),
level: 'ALL',
message: await fs.readFile(fullPath, 'utf8')
};
});
}
}
export { IOSCrashLog };
export default IOSCrashLog;