Skip to content

Commit aaff55c

Browse files
committed
fix(ios): trace what the simulator's log stream writes to stderr
With structured simulator logs only stdout was read, so an error from log stream, such as a rejected predicate, disappeared without a trace and the app's logs silently stayed empty.
1 parent 14ab2ed commit aaff55c

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

‎lib/common/mobile/ios/simulator/ios-simulator-log-provider.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ export class IOSSimulatorLogProvider
7676
readline
7777
.createInterface({ input: deviceLogChildProcess.stdout })
7878
.on("line", (line) => this.logStructuredLine(deviceId, line));
79+
deviceLogChildProcess.stderr?.on("data", (data: Buffer | string) => {
80+
this.$logger.trace(
81+
`log stream on simulator ${deviceId}: ${data.toString()}`,
82+
);
83+
});
7984
} else {
8085
if (deviceLogChildProcess.stdout) {
8186
deviceLogChildProcess.stdout.on("data", action.bind(this));
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { assert } from "chai";
2+
import { EventEmitter } from "events";
3+
import { PassThrough } from "stream";
4+
import { IOSSimulatorLogProvider } from "../../../mobile/ios/simulator/ios-simulator-log-provider";
5+
import { DevicePlatformsConstants } from "../../../mobile/device-platforms-constants";
6+
import { CommonLoggerStub } from "../stubs";
7+
8+
const deviceId = "simulator-id";
9+
10+
class LogProcessStub extends EventEmitter {
11+
public stdout = new PassThrough();
12+
public stderr = new PassThrough();
13+
public kill(): void {}
14+
}
15+
16+
const nextTick = () => new Promise((resolve) => setImmediate(resolve));
17+
18+
describe("IOSSimulatorLogProvider", () => {
19+
let logProcess: LogProcessStub;
20+
let logger: CommonLoggerStub;
21+
let entries: Mobile.IiOSLogEntry[];
22+
let provider: IOSSimulatorLogProvider;
23+
24+
beforeEach(() => {
25+
logProcess = new LogProcessStub();
26+
logger = new CommonLoggerStub();
27+
entries = [];
28+
provider = new IOSSimulatorLogProvider(
29+
<any>{},
30+
logger,
31+
new DevicePlatformsConstants(),
32+
<any>{
33+
getProjectNameForDevice: () => "app",
34+
logEntry: (entry: Mobile.IiOSLogEntry) => entries.push(entry),
35+
logData: () => assert.fail("structured logs never go through logData"),
36+
},
37+
<any>{ spawn: () => logProcess },
38+
);
39+
});
40+
41+
it("maps log stream ndjson events to log entries", async () => {
42+
await provider.startLogProcess(deviceId);
43+
logProcess.stdout.write(
44+
'Filtering the log data using "process == \\"app\\""\n' +
45+
JSON.stringify({
46+
eventType: "logEvent",
47+
processID: 42,
48+
threadID: 7,
49+
processImagePath: "/apps/app.app/app",
50+
senderImagePath:
51+
"/apps/app.app/Frameworks/NativeScript.framework/NativeScript",
52+
messageType: "Default",
53+
eventMessage: "CONSOLE LOG: hello",
54+
}) +
55+
"\n" +
56+
JSON.stringify({ eventType: "activityCreateEvent" }) +
57+
"\n",
58+
);
59+
await nextTick();
60+
61+
assert.deepEqual(entries, [
62+
{
63+
pid: 42,
64+
thread: 7,
65+
process: "/apps/app.app/app",
66+
image: "/apps/app.app/Frameworks/NativeScript.framework/NativeScript",
67+
level: "default",
68+
message: "CONSOLE LOG: hello",
69+
},
70+
]);
71+
});
72+
73+
it("traces what log stream writes to stderr", async () => {
74+
await provider.startLogProcess(deviceId);
75+
logProcess.stderr.write("log: Invalid predicate\n");
76+
await nextTick();
77+
78+
assert.isEmpty(entries);
79+
assert.include(logger.traceOutput, "log: Invalid predicate");
80+
});
81+
});

0 commit comments

Comments
 (0)