@@ -3,15 +3,16 @@ import { Yok } from "../../lib/common/yok";
3
3
import { LoggingLevels } from "../../lib/common/mobile/logging-levels" ;
4
4
import * as assert from "assert" ;
5
5
6
- function createTestInjector ( ) : IInjector {
6
+ function createTestInjector ( projectName : string ) : IInjector {
7
7
const testInjector = new Yok ( ) ;
8
8
testInjector . register ( "loggingLevels" , LoggingLevels ) ;
9
9
testInjector . register ( "fs" , {
10
10
exists : ( ) => false
11
11
} ) ;
12
12
testInjector . register ( "projectData" , {
13
13
initializeProjectData : ( ) => { /* empty */ } ,
14
- projectDir : "test"
14
+ projectDir : "test" ,
15
+ projectName : projectName
15
16
} ) ;
16
17
17
18
return testInjector ;
@@ -24,6 +25,7 @@ describe("iOSLogFilter", () => {
24
25
const testData = [
25
26
{
26
27
version : 9 ,
28
+ projectName : "NativeScript250" ,
27
29
originalDataArr : [
28
30
"May 24 15:54:38 Dragons-iPhone backboardd(BaseBoard)[62] <Error>: Unable to bootstrap_look_up port with name .gsEvents: unknown error code (1102)" ,
29
31
"May 24 15:54:51 Dragons-iPhone locationd[67] <Notice>: Client com.apple.springboard disconnected" ,
@@ -45,9 +47,10 @@ describe("iOSLogFilter", () => {
45
47
null ,
46
48
null ,
47
49
"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 ,
49
51
""
50
52
] ,
53
+ simProjectName : "TestApp" ,
51
54
simulator : [
52
55
"Aug 22 10:59:20 MCSOFAPPBLD TestApp[52946]: CONSOLE LOG file:///app/home/home-view-model.js:6:20: CUSTOM CONSOLE LOG" ,
53
56
"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", () => {
60
63
]
61
64
} , {
62
65
version : 10 ,
66
+ projectName : "NativeScript250" ,
63
67
originalDataArr : [
64
68
"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" ,
65
69
"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", () => {
86
90
"CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:3472:32: EXCEPTION: Uncaught (in promise): Error: CUSTOM EXCEPTION" ,
87
91
"CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:3477:36: ORIGINAL STACKTRACE:" ,
88
92
"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" ,
89
104
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" ,
101
105
""
102
106
] ,
107
+ simProjectName : "TestApp" ,
103
108
simulator : [
104
109
"Aug 22 10:59:20 MCSOFAPPBLD TestApp[52946]: CONSOLE LOG file:///app/home/home-view-model.js:6:20: CUSTOM CONSOLE LOG" ,
105
110
"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", () => {
113
118
} ,
114
119
{
115
120
version : 11 ,
121
+ projectName : "NativeScript250" ,
116
122
originalDataArr : [
117
123
"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" ,
118
124
"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", () => {
139
145
"CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:3472:32: EXCEPTION: Uncaught (in promise): Error: CUSTOM EXCEPTION" ,
140
146
"CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:3477:36: ORIGINAL STACKTRACE:" ,
141
147
"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" ,
142
159
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" ,
154
160
""
155
161
] ,
162
+ simProjectName : "cliapp" ,
156
163
simulator : [
157
164
"2017-10-09 13:34:38.527844+0300 localhost cliapp[52946]: (NativeScript) CONSOLE LOG file:///app/main-view-model.js:18:20: Test Console" ,
158
165
"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", () => {
168
175
const infoLogLevel = "INFO" ;
169
176
const fullLogLevel = "FULL" ;
170
177
171
- beforeEach ( ( ) => {
172
- testInjector = createTestInjector ( ) ;
173
- logFilter = testInjector . resolve ( IOSLogFilter ) ;
174
- } ) ;
175
-
176
178
describe ( "filterData" , ( ) => {
177
179
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
+
178
206
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 ) ;
179
209
const actualData = logFilter . filterData ( data . originalDataArr . join ( "\n" ) , fullLogLevel , null ) ;
180
210
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 ) ;
182
212
assert . deepEqual ( actualArr , expectedArr ) ;
183
213
} ) ;
184
214
185
215
it ( `returns correct data when logLevel is ${ fullLogLevel } on iOS ${ data . version } and data is passed one line at a time` , ( ) => {
186
216
data . originalDataArr . forEach ( line => {
217
+ testInjector = createTestInjector ( data . projectName ) ;
218
+ logFilter = testInjector . resolve ( IOSLogFilter ) ;
187
219
const actualData = logFilter . filterData ( line , fullLogLevel , null ) ;
188
220
assert . deepEqual ( actualData . trim ( ) , line . trim ( ) ) ;
189
221
} ) ;
190
222
} ) ;
191
223
192
224
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 ) ;
193
227
const actualData = logFilter . filterData ( data . simulator . join ( "\n" ) , infoLogLevel , pid ) ;
194
228
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 ) ) ;
196
230
} ) ;
197
231
198
232
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 ) ;
199
235
const actualData = logFilter . filterData ( data . originalDataArr . join ( "\n" ) , infoLogLevel , null ) ;
200
236
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 ) ;
202
238
assert . deepEqual ( actualArr , expectedArr ) ;
203
239
} ) ;
204
240
205
241
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 ) ;
206
244
data . originalDataArr . forEach ( ( line , index ) => {
245
+ if ( line . length > 0 ) {
246
+ line += "\n"
247
+ }
207
248
const actualData = logFilter . filterData ( line , infoLogLevel , null ) ;
208
249
const expectedData = data . infoExpectedArr [ index ] ;
209
- assert . deepEqual ( actualData && actualData . trim ( ) , expectedData && expectedData ) ;
250
+ assert . equal ( actualData && actualData . trim ( ) , expectedData ) ;
210
251
} ) ;
211
252
} ) ;
212
253
} ) ;
0 commit comments