@@ -3,15 +3,16 @@ import { Yok } from "../../lib/common/yok";
33import { LoggingLevels } from "../../lib/common/mobile/logging-levels" ;
44import * as assert from "assert" ;
55
6- function createTestInjector ( ) : IInjector {
6+ function createTestInjector ( projectName : string ) : IInjector {
77 const testInjector = new Yok ( ) ;
88 testInjector . register ( "loggingLevels" , LoggingLevels ) ;
99 testInjector . register ( "fs" , {
1010 exists : ( ) => false
1111 } ) ;
1212 testInjector . register ( "projectData" , {
1313 initializeProjectData : ( ) => { /* empty */ } ,
14- projectDir : "test"
14+ projectDir : "test" ,
15+ projectName : projectName
1516 } ) ;
1617
1718 return testInjector ;
@@ -24,6 +25,7 @@ describe("iOSLogFilter", () => {
2425 const testData = [
2526 {
2627 version : 9 ,
28+ projectName : "NativeScript250" ,
2729 originalDataArr : [
2830 "May 24 15:54:38 Dragons-iPhone backboardd(BaseBoard)[62] <Error>: Unable to bootstrap_look_up port with name .gsEvents: unknown error code (1102)" ,
2931 "May 24 15:54:51 Dragons-iPhone locationd[67] <Notice>: Client com.apple.springboard disconnected" ,
@@ -45,9 +47,10 @@ describe("iOSLogFilter", () => {
4547 null ,
4648 null ,
4749 "CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:3472:32: EXCEPTION: Uncaught (in promise): Error: CUSTOM EXCEPTION" ,
48- "CONSOLE LOG file:///app/home/home-view-model.js:6:20: CUSTOM CONSOLE LOG" ,
50+ null ,
4951 ""
5052 ] ,
53+ simProjectName : "TestApp" ,
5154 simulator : [
5255 "Aug 22 10:59:20 MCSOFAPPBLD TestApp[52946]: CONSOLE LOG file:///app/home/home-view-model.js:6:20: CUSTOM CONSOLE LOG" ,
5356 "Aug 22 10:59:20 MCSOFAPPBLD TestApp[52946]: CONSOLE DEBUG file:///app/home/home-view-model.js:6:20: CUSTOM CONSOLE LOG" ,
@@ -60,6 +63,7 @@ describe("iOSLogFilter", () => {
6063 ]
6164 } , {
6265 version : 10 ,
66+ projectName : "NativeScript250" ,
6367 originalDataArr : [
6468 "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" ,
6569 "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" ,
@@ -86,20 +90,21 @@ describe("iOSLogFilter", () => {
8690 "CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:3472:32: EXCEPTION: Uncaught (in promise): Error: CUSTOM EXCEPTION" ,
8791 "CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:3477:36: ORIGINAL STACKTRACE:" ,
8892 "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" ,
93+ "resolvePromise@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:401:31" ,
94+ "file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:449:31" ,
95+ "invokeTask@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:223:42" ,
96+ "onInvokeTask@file:///app/tns_modules/@angular/core/bundles/core.umd.js:4382:51" ,
97+ "invokeTask@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:222:54" ,
98+ "runTask@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:123:57" ,
99+ "drainMicroTaskQueue@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:355:42" ,
100+ "promiseReactionJob@[native code]" ,
101+ "UIApplicationMain@[native code]" ,
102+ "start@file:///app/tns_modules/tns-core-modules/application/application.js:251:26" ,
103+ "bootstrapApp@file:///app/tns_module" ,
89104 null ,
90- null ,
91- null ,
92- null ,
93- null ,
94- null ,
95- null ,
96- null ,
97- null ,
98- null ,
99- null ,
100- "CONSOLE LOG file:///app/home/home-view-model.js:6:20: CUSTOM CONSOLE LOG" ,
101105 ""
102106 ] ,
107+ simProjectName : "TestApp" ,
103108 simulator : [
104109 "Aug 22 10:59:20 MCSOFAPPBLD TestApp[52946]: CONSOLE LOG file:///app/home/home-view-model.js:6:20: CUSTOM CONSOLE LOG" ,
105110 "Aug 22 10:59:20 MCSOFAPPBLD TestApp[52946]: CONSOLE DEBUG file:///app/home/home-view-model.js:6:20: CUSTOM CONSOLE LOG" ,
@@ -113,6 +118,7 @@ describe("iOSLogFilter", () => {
113118 } ,
114119 {
115120 version : 11 ,
121+ projectName : "NativeScript250" ,
116122 originalDataArr : [
117123 "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" ,
118124 "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" ,
@@ -139,20 +145,21 @@ describe("iOSLogFilter", () => {
139145 "CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:3472:32: EXCEPTION: Uncaught (in promise): Error: CUSTOM EXCEPTION" ,
140146 "CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:3477:36: ORIGINAL STACKTRACE:" ,
141147 "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" ,
148+ "resolvePromise@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:401:31" ,
149+ "file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:449:31" ,
150+ "invokeTask@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:223:42" ,
151+ "onInvokeTask@file:///app/tns_modules/@angular/core/bundles/core.umd.js:4382:51" ,
152+ "invokeTask@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:222:54" ,
153+ "runTask@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:123:57" ,
154+ "drainMicroTaskQueue@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:355:42" ,
155+ "promiseReactionJob@[native code]" ,
156+ "UIApplicationMain@[native code]" ,
157+ "start@file:///app/tns_modules/tns-core-modules/application/application.js:251:26" ,
158+ "bootstrapApp@file:///app/tns_module" ,
142159 null ,
143- null ,
144- null ,
145- null ,
146- null ,
147- null ,
148- null ,
149- null ,
150- null ,
151- null ,
152- null ,
153- "CONSOLE LOG file:///app/home/home-view-model.js:6:20: CUSTOM CONSOLE LOG" ,
154160 ""
155161 ] ,
162+ simProjectName : "cliapp" ,
156163 simulator : [
157164 "2017-10-09 13:34:38.527844+0300 localhost cliapp[52946]: (NativeScript) CONSOLE LOG file:///app/main-view-model.js:18:20: Test Console" ,
158165 "2017-10-09 13:34:38.527844+0300 localhost cliapp[52946]: (NativeScript) CONSOLE DEBUG file:///app/main-view-model.js:18:20: Test Console" ,
@@ -168,45 +175,79 @@ describe("iOSLogFilter", () => {
168175 const infoLogLevel = "INFO" ;
169176 const fullLogLevel = "FULL" ;
170177
171- beforeEach ( ( ) => {
172- testInjector = createTestInjector ( ) ;
173- logFilter = testInjector . resolve ( IOSLogFilter ) ;
174- } ) ;
175-
176178 describe ( "filterData" , ( ) => {
177179 testData . forEach ( data => {
180+
181+ it ( `returns correct data on iOS ${ data . version } when data comes in chunks` , ( ) => {
182+ testInjector = createTestInjector ( data . projectName ) ;
183+ logFilter = testInjector . resolve ( IOSLogFilter ) ;
184+
185+ let currentStart = 0 ;
186+ let maxRange = 50 ;
187+ let output = ""
188+ let input = data . originalDataArr . join ( "\n" ) ;
189+ while ( true ) {
190+ let currentRange = Math . floor ( Math . random ( ) * maxRange ) ;
191+ let currentFilterInput = input . substr ( currentStart , currentRange ) ;
192+ let tempOutput = logFilter . filterData ( currentFilterInput , infoLogLevel , null ) ;
193+ if ( tempOutput !== null ) {
194+ output += tempOutput ;
195+ }
196+ currentStart += currentRange ;
197+ if ( currentStart == input . length ) {
198+ break ;
199+ }
200+ currentStart = Math . min ( currentStart , input . length ) ;
201+ }
202+
203+ assert . deepEqual ( output , data . infoExpectedArr . filter ( item => item !== null ) . join ( "\n" ) ) ;
204+ } ) ;
205+
178206 it ( `returns correct data when logLevel is ${ fullLogLevel } on iOS ${ data . version } and all data is passed at once` , ( ) => {
207+ testInjector = createTestInjector ( data . projectName ) ;
208+ logFilter = testInjector . resolve ( IOSLogFilter ) ;
179209 const actualData = logFilter . filterData ( data . originalDataArr . join ( "\n" ) , fullLogLevel , null ) ;
180210 const actualArr = actualData . split ( "\n" ) . map ( line => line . trim ( ) ) ;
181- const expectedArr = data . originalDataArr . map ( line => line . trim ( ) ) ;
211+ const expectedArr = data . originalDataArr . map ( line => line . trim ( ) ) . filter ( item => item !== null ) ;
182212 assert . deepEqual ( actualArr , expectedArr ) ;
183213 } ) ;
184214
185215 it ( `returns correct data when logLevel is ${ fullLogLevel } on iOS ${ data . version } and data is passed one line at a time` , ( ) => {
186216 data . originalDataArr . forEach ( line => {
217+ testInjector = createTestInjector ( data . projectName ) ;
218+ logFilter = testInjector . resolve ( IOSLogFilter ) ;
187219 const actualData = logFilter . filterData ( line , fullLogLevel , null ) ;
188220 assert . deepEqual ( actualData . trim ( ) , line . trim ( ) ) ;
189221 } ) ;
190222 } ) ;
191223
192224 it ( `parses data incorrectly when logLevel is ${ infoLogLevel } on iOS ${ data . version } and all data is passed at once with pid(simulator)` , ( ) => {
225+ testInjector = createTestInjector ( data . simProjectName ) ;
226+ logFilter = testInjector . resolve ( IOSLogFilter ) ;
193227 const actualData = logFilter . filterData ( data . simulator . join ( "\n" ) , infoLogLevel , pid ) ;
194228 const actualArr = actualData . split ( "\n" ) . map ( line => line . trim ( ) ) ;
195- assert . deepEqual ( actualArr , data . simulatorExpectedArr ) ;
229+ assert . deepEqual ( actualArr , data . simulatorExpectedArr . filter ( item => item !== null ) ) ;
196230 } ) ;
197231
198232 it ( `parses data incorrectly when logLevel is ${ infoLogLevel } on iOS ${ data . version } and all data is passed at once and pid is available` , ( ) => {
233+ testInjector = createTestInjector ( data . projectName ) ;
234+ logFilter = testInjector . resolve ( IOSLogFilter ) ;
199235 const actualData = logFilter . filterData ( data . originalDataArr . join ( "\n" ) , infoLogLevel , null ) ;
200236 const actualArr = actualData . split ( "\n" ) . map ( line => line . trim ( ) ) ;
201- const expectedArr = [ "CONSOLE LOG file:///app/modules/homeView/homeView.component.js:13:24: CUSTOM CONSOLE LOG" , "" ] ;
237+ const expectedArr = data . infoExpectedArr . filter ( item => item !== null ) ;
202238 assert . deepEqual ( actualArr , expectedArr ) ;
203239 } ) ;
204240
205241 it ( `returns correct data when logLevel is ${ infoLogLevel } on iOS ${ data . version } and data is passed one line at a time` , ( ) => {
242+ testInjector = createTestInjector ( data . projectName ) ;
243+ logFilter = testInjector . resolve ( IOSLogFilter ) ;
206244 data . originalDataArr . forEach ( ( line , index ) => {
245+ if ( line . length > 0 ) {
246+ line += "\n"
247+ }
207248 const actualData = logFilter . filterData ( line , infoLogLevel , null ) ;
208249 const expectedData = data . infoExpectedArr [ index ] ;
209- assert . deepEqual ( actualData && actualData . trim ( ) , expectedData && expectedData ) ;
250+ assert . equal ( actualData && actualData . trim ( ) , expectedData ) ;
210251 } ) ;
211252 } ) ;
212253 } ) ;
0 commit comments