@@ -90,6 +90,48 @@ function getMultilineDebuggerPortMessage(port: number) {
90
90
2018-04-20 09:45:51.260951+0300 localhost nglog[17917]: NativeScript debugger has opened inspector socket on port ${ port } for ${ appId } .` ;
91
91
}
92
92
93
+ function getAppCrashMessage ( ) {
94
+ return `***** Fatal JavaScript exception - application has been terminated. *****` ;
95
+ }
96
+
97
+ function getMultilineAppCrashMessage ( ) {
98
+ return `Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: ***** Fatal JavaScript exception - application has been terminated. *****
99
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: Native stack trace:
100
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: 1 0x1013ef370 NativeScript::reportFatalErrorBeforeShutdown(JSC::ExecState*, JSC::Exception*, bool)
101
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: 2 0x10141fdec NativeScript::FFICallback<NativeScript::ObjCMethodCallback>::ffiClosureCallback(ffi_cif*, void*, void**, void*)
102
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: 3 0x101e84494 ffi_closure_SYSV_inner
103
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: 4 0x101e881b4 .Ldo_closure
104
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: 5 0x183760c3c <redacted>
105
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: 6 0x1837601b8 <redacted>
106
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: 7 0x18375ff14 <redacted>
107
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: 8 0x1837dd84c <redacted>
108
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: 9 0x183696f38 _CFXNotificationPost
109
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: 10 0x184107bbc <redacted>
110
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: 11 0x18d3da2f0 <redacted>
111
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: 12 0x18d3a75e0 <redacted>
112
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: 13 0x18d9d7b1c <redacted>
113
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: 14 0x18d3a6dd0 <redacted>
114
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: 15 0x18d3a6c6c <redacted>
115
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: 16 0x18d3a5afc <redacted>
116
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: 17 0x18e03b84c <redacted>
117
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: 18 0x18d3a51ec <redacted>
118
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: 19 0x18de20ac8 <redacted>
119
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: 20 0x18df6ebf8 _performActionsWithDelayForTransitionContext
120
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: 21 0x18d3a4c0c <redacted>
121
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: 22 0x18d3a45a8 <redacted>
122
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: 23 0x18d3a15e0 <redacted>
123
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: 24 0x18d3a1330 <redacted>
124
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: 25 0x185fcf470 <redacted>
125
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: 26 0x185fd7d6c <redacted>
126
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: 27 0x1830c0a60 <redacted>
127
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: 28 0x1830c8170 <redacted>
128
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: 29 0x186003878 <redacted>
129
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: 30 0x18600351c <redacted>
130
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: 31 0x186003ab8 <redacted>
131
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: JavaScript stack trace:
132
+ Mar 20 15:13:23 iOS-Team-iPad-2-Mini-Black hwJs(NativeScript)[3946] <Notice>: 1 @file:///app/vendor.js:12552:56` ;
133
+ }
134
+
93
135
describe ( "iOSDebuggerPortService" , ( ) => {
94
136
let injector : IInjector , iOSDebuggerPortService : IIOSDebuggerPortService , deviceLogProvider : Mobile . IDeviceLogProvider ;
95
137
let clock : sinon . SinonFakeTimers = null ;
@@ -108,71 +150,63 @@ describe("iOSDebuggerPortService", () => {
108
150
function emitDeviceLog ( message : string ) {
109
151
deviceLogProvider . emit ( DEVICE_LOG_EVENT_NAME , message , device . deviceInfo . identifier ) ;
110
152
}
111
-
112
- function emitStartingIOSApplicationEvent ( ) {
113
- device . applicationManager . emit ( "STARTING_IOS_APPLICATION" , {
114
- appId : appId ,
115
- deviceId : device . deviceInfo . identifier
116
- } ) ;
117
- }
118
-
119
153
describe ( "getPort" , ( ) => {
120
- const testCases = [
154
+ const testCases : { name : string , emittedPort ?: number , crashApp ?: boolean , expectedError ?: string } [ ] = [
121
155
{
122
156
name : `should return null when ${ DEBUGGER_PORT_FOUND_EVENT_NAME } event is not emitted` ,
123
- emittedPort : null ,
124
- emitStartingIOSApplicationEvent : false
157
+ emittedPort : null
125
158
} ,
126
159
{
127
160
name : `should return default port when ${ DEBUGGER_PORT_FOUND_EVENT_NAME } event is emitted` ,
128
- emittedPort : 18181 ,
129
- emitStartingIOSApplicationEvent : false
161
+ emittedPort : 18181
130
162
} ,
131
163
{
132
164
name : `should return random port when ${ DEBUGGER_PORT_FOUND_EVENT_NAME } event is emitted` ,
133
- emittedPort : 65432 ,
134
- emitStartingIOSApplicationEvent : false
135
- } ,
136
- {
137
- name : `should return default port when ${ DEBUGGER_PORT_FOUND_EVENT_NAME } and STARTING_IOS_APPLICATION events are emitted` ,
138
- emittedPort : 18181 ,
139
- emitStartingIOSApplicationEvent : true
165
+ emittedPort : 65432
140
166
} ,
141
167
{
142
- name : `should return random port when ${ DEBUGGER_PORT_FOUND_EVENT_NAME } and STARTING_IOS_APPLICATION events are emitted ` ,
143
- emittedPort : 12345 ,
144
- emitStartingIOSApplicationEvent : true
168
+ name : `should reject when the app crashes ` ,
169
+ expectedError : "The application has been terminated." ,
170
+ crashApp : true
145
171
}
146
172
] ;
147
173
148
174
_ . each ( testCases , testCase => {
149
175
it ( testCase . name , async ( ) => {
150
- await iOSDebuggerPortService . attachToDebuggerPortFoundEvent ( ) ;
151
- if ( testCase . emitStartingIOSApplicationEvent ) {
152
- emitStartingIOSApplicationEvent ( ) ;
153
- }
176
+ await iOSDebuggerPortService . attachToDebuggerPortFoundEvent ( appId ) ;
154
177
if ( testCase . emittedPort ) {
155
178
emitDeviceLog ( getDebuggerPortMessage ( testCase . emittedPort ) ) ;
179
+ } else if ( testCase . crashApp ) {
180
+ emitDeviceLog ( getAppCrashMessage ( ) ) ;
156
181
}
157
182
158
183
const promise = iOSDebuggerPortService . getPort ( { deviceId : deviceId , appId : appId } ) ;
159
184
clock . tick ( 70000 ) ;
160
- const port = await promise ;
161
- assert . deepEqual ( port , testCase . emittedPort ) ;
185
+ let port = 0 ;
186
+ try {
187
+ port = await promise ;
188
+ assert . deepEqual ( port , testCase . emittedPort ) ;
189
+ } catch ( err ) {
190
+ assert . deepEqual ( err . message , testCase . expectedError ) ;
191
+ }
162
192
} ) ;
163
193
it ( `${ testCase . name } for multiline debugger port message.` , async ( ) => {
164
- await iOSDebuggerPortService . attachToDebuggerPortFoundEvent ( ) ;
165
- if ( testCase . emitStartingIOSApplicationEvent ) {
166
- emitStartingIOSApplicationEvent ( ) ;
167
- }
194
+ await iOSDebuggerPortService . attachToDebuggerPortFoundEvent ( appId ) ;
168
195
if ( testCase . emittedPort ) {
169
196
emitDeviceLog ( getMultilineDebuggerPortMessage ( testCase . emittedPort ) ) ;
197
+ } else if ( testCase . crashApp ) {
198
+ emitDeviceLog ( getMultilineAppCrashMessage ( ) ) ;
170
199
}
171
200
172
201
const promise = iOSDebuggerPortService . getPort ( { deviceId : deviceId , appId : appId } ) ;
173
202
clock . tick ( 70000 ) ;
174
- const port = await promise ;
175
- assert . deepEqual ( port , testCase . emittedPort ) ;
203
+ let port = 0 ;
204
+ try {
205
+ port = await promise ;
206
+ assert . deepEqual ( port , testCase . emittedPort ) ;
207
+ } catch ( err ) {
208
+ assert . deepEqual ( err . message , testCase . expectedError ) ;
209
+ }
176
210
} ) ;
177
211
} ) ;
178
212
} ) ;
0 commit comments