Skip to content

Fix iOS11 Simulator logs #3145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/services/ios-log-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ export class IOSLogFilter extends iOSLogFilterBase.IOSLogFilter implements Mobil
// This code removes unnecessary information from log messages. The output looks like:
// CONSOLE LOG file:///location:row:column: <actual message goes here>
if (pid) {
const searchString = "[" + pid + "]: ";
const pidIndex = line.indexOf(searchString);
if (pidIndex > 0) {
line = line.substring(pidIndex + searchString.length, line.length);
if (line.indexOf(`[${pid}]: `) !== -1) {
const pidRegex = new RegExp(`^.*\\[${pid}\\]:\\s(?:\\(NativeScript\\)\\s)?`);
line = line.replace(pidRegex, "").trim();
this.getOriginalFileLocation(line);
result += this.getOriginalFileLocation(line) + "\n";
continue;
}

continue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't match with neither pidIndex nor ios11PidIndex I do not believe we'd want to continue.
I think this continue statement should be returned in the previous block

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking continue outside the if statement prevents lines that don't contain the pid to be logged.

}
if (skipLastLine && i === lines.length - 1 && lines.length > 1) {
this.partialLine = line;
Expand Down
36 changes: 18 additions & 18 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"inquirer": "0.9.0",
"ios-device-lib": "0.4.10",
"ios-mobileprovision-finder": "1.0.10",
"ios-sim-portable": "3.1.3",
"ios-sim-portable": "3.2.0",
"lockfile": "1.0.3",
"lodash": "4.13.1",
"log4js": "1.0.1",
Expand Down
83 changes: 81 additions & 2 deletions test/services/ios-log-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function createTestInjector(): IInjector {
describe("iOSLogFilter", () => {
let testInjector: IInjector;
let logFilter: Mobile.IPlatformLogFilter;
const pid = "52946";
const testData = [
{
version: 9,
Expand All @@ -46,10 +47,72 @@ describe("iOSLogFilter", () => {
"CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:3472:32: EXCEPTION: Uncaught (in promise): Error: CUSTOM EXCEPTION",
"CONSOLE LOG file:///app/home/home-view-model.js:6:20: CUSTOM CONSOLE LOG",
""
],
simulator: [
"Aug 22 10:59:20 MCSOFAPPBLD TestApp[52946]: CONSOLE LOG file:///app/home/home-view-model.js:6:20: CUSTOM CONSOLE LOG",
"Aug 22 10:59:20 MCSOFAPPBLD TestApp[52946]: CONSOLE DEBUG file:///app/home/home-view-model.js:6:20: CUSTOM CONSOLE LOG",
"Aug 22 10:59:20 MCSOFAPPBLD TestApp[11111]: CONSOLE DEBUG file:///app/home/home-view-model.js:6:20: CUSTOM CONSOLE LOG"
],
simulatorExpectedArr: [
"CONSOLE LOG file:///app/home/home-view-model.js:6:20: CUSTOM CONSOLE LOG",
"CONSOLE DEBUG file:///app/home/home-view-model.js:6:20: CUSTOM CONSOLE LOG",
""
]
}, {
version: 10,
originalDataArr: [
"May 24 15:54:52 Dragons-iPhone apsd(PersistentConnection)[90] <Notice>: 2017-05-24 15:54:52 +0300 apsd[90]: <PCDispatchTimer: 0x156ad240> performing call back",
"May 24 15:54:52 Dragons-iPhone NativeScript250(NativeScript)[356] <Notice>: CONSOLE LOG file:///app/modules/homeView/homeView.component.js:13:24: CUSTOM CONSOLE LOG",
"May 24 15:54:52 Dragons-iPhone NativeScript250(NativeScript)[356] <Notice>: CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:3472:32: EXCEPTION: Uncaught (in promise): Error: CUSTOM EXCEPTION",
" May 24 15:54:52 Dragons-iPhone NativeScript250(NativeScript)[356] <Notice>: CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:3477:36: ORIGINAL STACKTRACE:",
" May 24 15:54:52 Dragons-iPhone NativeScript250(NativeScript)[356] <Notice>: CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:3478:36: resolvePromise@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:416:40",
"resolvePromise@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:401:31",
"file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:449:31",
"invokeTask@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:223:42",
"onInvokeTask@file:///app/tns_modules/@angular/core/bundles/core.umd.js:4382:51",
"invokeTask@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:222:54",
"runTask@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:123:57",
"drainMicroTaskQueue@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:355:42",
"promiseReactionJob@[native code]",
"UIApplicationMain@[native code]",
"start@file:///app/tns_modules/tns-core-modules/application/application.js:251:26",
"bootstrapApp@file:///app/tns_module",
"Aug 22 10:59:20 MCSOFAPPBLD TestApp[52946]: CONSOLE LOG file:///app/home/home-view-model.js:6:20: CUSTOM CONSOLE LOG",
""
],
infoExpectedArr: [
null,
"CONSOLE LOG file:///app/modules/homeView/homeView.component.js:13:24: CUSTOM CONSOLE LOG",
"CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:3472:32: EXCEPTION: Uncaught (in promise): Error: CUSTOM EXCEPTION",
"CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:3477:36: ORIGINAL STACKTRACE:",
"CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:3478:36: resolvePromise@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:416:40",
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
"CONSOLE LOG file:///app/home/home-view-model.js:6:20: CUSTOM CONSOLE LOG",
""
],
simulator: [
"Aug 22 10:59:20 MCSOFAPPBLD TestApp[52946]: CONSOLE LOG file:///app/home/home-view-model.js:6:20: CUSTOM CONSOLE LOG",
"Aug 22 10:59:20 MCSOFAPPBLD TestApp[52946]: CONSOLE DEBUG file:///app/home/home-view-model.js:6:20: CUSTOM CONSOLE LOG",
"Aug 22 10:59:20 MCSOFAPPBLD TestApp[11111]: CONSOLE DEBUG file:///app/home/home-view-model.js:6:20: CUSTOM CONSOLE LOG"
],
simulatorExpectedArr: [
"CONSOLE LOG file:///app/home/home-view-model.js:6:20: CUSTOM CONSOLE LOG",
"CONSOLE DEBUG file:///app/home/home-view-model.js:6:20: CUSTOM CONSOLE LOG",
""
]
},
{
version: 10,
version: 11,
originalDataArr: [
"May 24 15:54:52 Dragons-iPhone apsd(PersistentConnection)[90] <Notice>: 2017-05-24 15:54:52 +0300 apsd[90]: <PCDispatchTimer: 0x156ad240> performing call back",
"May 24 15:54:52 Dragons-iPhone NativeScript250(NativeScript)[356] <Notice>: CONSOLE LOG file:///app/modules/homeView/homeView.component.js:13:24: CUSTOM CONSOLE LOG",
Expand Down Expand Up @@ -89,6 +152,16 @@ describe("iOSLogFilter", () => {
null,
"CONSOLE LOG file:///app/home/home-view-model.js:6:20: CUSTOM CONSOLE LOG",
""
],
simulator: [
"2017-10-09 13:34:38.527844+0300 localhost cliapp[52946]: (NativeScript) CONSOLE LOG file:///app/main-view-model.js:18:20: Test Console",
"2017-10-09 13:34:38.527844+0300 localhost cliapp[52946]: (NativeScript) CONSOLE DEBUG file:///app/main-view-model.js:18:20: Test Console",
"Aug 22 10:59:20 MCSOFAPPBLD TestApp[11111]: CONSOLE DEBUG file:///app/home/home-view-model.js:6:20: CUSTOM CONSOLE LOG"
],
simulatorExpectedArr: [
"CONSOLE LOG file:///app/main-view-model.js:18:20: Test Console",
"CONSOLE DEBUG file:///app/main-view-model.js:18:20: Test Console",
""
]
}
];
Expand Down Expand Up @@ -116,7 +189,13 @@ describe("iOSLogFilter", () => {
});
});

it(`parses data incorrectly when logLevel is ${infoLogLevel} on iOS ${data.version} and all data is passed at once`, () => {
it(`parses data incorrectly when logLevel is ${infoLogLevel} on iOS ${data.version} and all data is passed at once with pid(simulator)`, () => {
const actualData = logFilter.filterData(data.simulator.join("\n"), infoLogLevel, pid);
const actualArr = actualData.split("\n").map(line => line.trim());
assert.deepEqual(actualArr, data.simulatorExpectedArr);
});

it(`parses data incorrectly when logLevel is ${infoLogLevel} on iOS ${data.version} and all data is passed at once and pid is available`, () => {
const actualData = logFilter.filterData(data.originalDataArr.join("\n"), infoLogLevel, null);
const actualArr = actualData.split("\n").map(line => line.trim());
const expectedArr = ["CONSOLE LOG file:///app/modules/homeView/homeView.component.js:13:24: CUSTOM CONSOLE LOG", ""];
Expand Down