|
| 1 | +import { IOSLogFilter } from "../../lib/services/ios-log-filter"; |
| 2 | +import { Yok } from "../../lib/common/yok"; |
| 3 | +import { LoggingLevels } from "../../lib/common/mobile/logging-levels"; |
| 4 | +import * as assert from "assert"; |
| 5 | + |
| 6 | +function createTestInjector(): IInjector { |
| 7 | + const testInjector = new Yok(); |
| 8 | + testInjector.register("loggingLevels", LoggingLevels); |
| 9 | + testInjector.register("fs", { |
| 10 | + exists: () => false |
| 11 | + }); |
| 12 | + testInjector.register("projectData", { |
| 13 | + initializeProjectData: () => { /* empty */ }, |
| 14 | + projectDir: "test" |
| 15 | + }); |
| 16 | + |
| 17 | + return testInjector; |
| 18 | +} |
| 19 | + |
| 20 | +describe("iOSLogFilter", () => { |
| 21 | + let testInjector: IInjector; |
| 22 | + let logFilter: Mobile.IPlatformLogFilter; |
| 23 | + const testData = [ |
| 24 | + { |
| 25 | + version: 9, |
| 26 | + originalDataArr: [ |
| 27 | + "May 24 15:54:38 Dragons-iPhone backboardd(BaseBoard)[62] <Error>: Unable to bootstrap_look_up port with name .gsEvents: unknown error code (1102)", |
| 28 | + "May 24 15:54:51 Dragons-iPhone locationd[67] <Notice>: Client com.apple.springboard disconnected", |
| 29 | + "May 24 14:44:59 iPad-90 NativeScript250[790] <Notice>: CONSOLE LOG file:///app/modules/homeView/homeView.component.js:13:24: CUSTOM CONSOLE LOG", |
| 30 | + "May 24 14:44:59 iPad-90 NativeScript250[790] <Notice>: CONSOLE LOG file:///app/modules/homeView/homeView.component.js:13:24: CUSTOM CONSOLE LOG", |
| 31 | + "May 24 14:44:59 iPad-90 mobile_installation_proxy[355] <Error>: 0x1f197000 LoadInfoPlist: Failed to create CFBundle from URL file:///private/var/mobile/Containers/Bundle/Application/EB4866CC-25D2-4A3B-AA6C-70FFA08B908E/NativeScript143.app", |
| 32 | + "May 24 14:44:59 iPad-90 mobile_installation_proxy[355] <Error>: 0x1f197000 LoadInfoPlist: Failed to create CFBundle from URL file:///private/var/mobile/Containers/Bundle/Application/0DA02818-DCAE-407C-979D-D55F4F36F8D2/NativeScript300.app", |
| 33 | + " May 24 14:44:59 iPad-90 mobile_installation_proxy[355] <Error>: 0x1f197000 LoadInfoPlist: Failed to create CFBundle from URL file:///private/var/mobile/Containers/Bundle/Application/B0EE9362-7BDD-4FF2-868F-857B76D9D8D3/Cordova370.app", |
| 34 | + " May 24 14:44:59 iPad-90 NativeScript250[790] <Notice>: CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:3472:32: EXCEPTION: Uncaught (in promise): Error: CUSTOM EXCEPTION", |
| 35 | + "" |
| 36 | + ], |
| 37 | + infoExpectedArr: [ |
| 38 | + null, |
| 39 | + null, |
| 40 | + "CONSOLE LOG file:///app/modules/homeView/homeView.component.js:13:24: CUSTOM CONSOLE LOG", |
| 41 | + "CONSOLE LOG file:///app/modules/homeView/homeView.component.js:13:24: CUSTOM CONSOLE LOG", |
| 42 | + null, |
| 43 | + null, |
| 44 | + null, |
| 45 | + "CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:3472:32: EXCEPTION: Uncaught (in promise): Error: CUSTOM EXCEPTION", |
| 46 | + null |
| 47 | + ] |
| 48 | + }, |
| 49 | + { |
| 50 | + version: 10, |
| 51 | + originalDataArr: [ |
| 52 | + "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", |
| 53 | + "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", |
| 54 | + "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", |
| 55 | + " 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:", |
| 56 | + " 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", |
| 57 | + "resolvePromise@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:401:31", |
| 58 | + "file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:449:31", |
| 59 | + "invokeTask@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:223:42", |
| 60 | + "onInvokeTask@file:///app/tns_modules/@angular/core/bundles/core.umd.js:4382:51", |
| 61 | + "invokeTask@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:222:54", |
| 62 | + "runTask@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:123:57", |
| 63 | + "drainMicroTaskQueue@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:355:42", |
| 64 | + "promiseReactionJob@[native code]", |
| 65 | + "UIApplicationMain@[native code]", |
| 66 | + "start@file:///app/tns_modules/tns-core-modules/application/application.js:251:26", |
| 67 | + "bootstrapApp@file:///app/tns_module", |
| 68 | + "" |
| 69 | + ], |
| 70 | + infoExpectedArr: [ |
| 71 | + null, |
| 72 | + "CONSOLE LOG file:///app/modules/homeView/homeView.component.js:13:24: CUSTOM CONSOLE LOG", |
| 73 | + "CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:3472:32: EXCEPTION: Uncaught (in promise): Error: CUSTOM EXCEPTION", |
| 74 | + "CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:3477:36: ORIGINAL STACKTRACE:", |
| 75 | + "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", |
| 76 | + null, |
| 77 | + null, |
| 78 | + null, |
| 79 | + null, |
| 80 | + null, |
| 81 | + null, |
| 82 | + null, |
| 83 | + null, |
| 84 | + null, |
| 85 | + null, |
| 86 | + null, |
| 87 | + null |
| 88 | + ] |
| 89 | + } |
| 90 | + ]; |
| 91 | + const infoLogLevel = "INFO"; |
| 92 | + const fullLogLevel = "FULL"; |
| 93 | + |
| 94 | + beforeEach(() => { |
| 95 | + testInjector = createTestInjector(); |
| 96 | + logFilter = testInjector.resolve(IOSLogFilter); |
| 97 | + }); |
| 98 | + |
| 99 | + describe("filterData", () => { |
| 100 | + testData.forEach(data => { |
| 101 | + it(`returns correct data when logLevel is ${fullLogLevel} on iOS ${data.version} and all data is passed at once`, () => { |
| 102 | + const actualData = logFilter.filterData(data.originalDataArr.join("\n"), fullLogLevel, null); |
| 103 | + const actualArr = actualData.split("\n").map(line => line.trim()); |
| 104 | + const expectedArr = data.originalDataArr.map(line => line.trim()); |
| 105 | + assert.deepEqual(actualArr, expectedArr); |
| 106 | + }); |
| 107 | + |
| 108 | + it(`returns correct data when logLevel is ${fullLogLevel} on iOS ${data.version} and data is passed one line at a time`, () => { |
| 109 | + data.originalDataArr.forEach(line => { |
| 110 | + const actualData = logFilter.filterData(line, fullLogLevel, null); |
| 111 | + assert.deepEqual(actualData.trim(), line.trim()); |
| 112 | + }); |
| 113 | + }); |
| 114 | + |
| 115 | + it(`parses data incorrectly when logLevel is ${infoLogLevel} on iOS ${data.version} and all data is passed at once`, () => { |
| 116 | + const actualData = logFilter.filterData(data.originalDataArr.join("\n"), infoLogLevel, null); |
| 117 | + const actualArr = actualData.split("\n").map(line => line.trim()); |
| 118 | + const expectedArr = ["CONSOLE LOG file:///app/modules/homeView/homeView.component.js:13:24: CUSTOM CONSOLE LOG", ""]; |
| 119 | + assert.deepEqual(actualArr, expectedArr); |
| 120 | + }); |
| 121 | + |
| 122 | + it(`returns correct data when logLevel is ${infoLogLevel} on iOS ${data.version} and data is passed one line at a time`, () => { |
| 123 | + data.originalDataArr.forEach((line, index) => { |
| 124 | + const actualData = logFilter.filterData(line, infoLogLevel, null); |
| 125 | + const expectedData = data.infoExpectedArr[index]; |
| 126 | + assert.deepEqual(actualData && actualData.trim(), expectedData && expectedData); |
| 127 | + }); |
| 128 | + }); |
| 129 | + }); |
| 130 | + }); |
| 131 | +}); |
0 commit comments