@@ -206,7 +206,7 @@ def req_terminate_debuggee
206
206
close_reader
207
207
end
208
208
209
- def assert_locals_result expected , frame_idx : 0
209
+ def gather_variables ( frame_idx : 0 , type : "locals" )
210
210
case get_target_ui
211
211
when 'vscode'
212
212
# get frameId
@@ -219,32 +219,40 @@ def assert_locals_result expected, frame_idx: 0
219
219
# get variablesReference
220
220
res = send_dap_request 'scopes' , frameId : f_id
221
221
222
- locals_scope = res . dig ( :body , :scopes ) . find { |d | d [ :presentationHint ] == "locals" }
222
+ locals_scope = res . dig ( :body , :scopes ) . find { |d | d [ :presentationHint ] == type }
223
223
locals_reference = locals_scope [ :variablesReference ]
224
224
225
225
# get variables
226
226
res = send_dap_request 'variables' , variablesReference : locals_reference
227
-
228
- expected . each do |exp |
229
- if exp [ :type ] == "String"
230
- exp [ :value ] = exp [ :value ] . inspect
231
- end
232
- end
233
-
234
- actual_locals = res . dig ( :body , :variables ) . map { |loc | { name : loc [ :name ] , value : loc [ :value ] , type : loc [ :type ] } }
227
+ res . dig ( :body , :variables ) . map { |loc | { name : loc [ :name ] , value : loc [ :value ] , type : loc [ :type ] } }
235
228
when 'chrome'
236
229
current_frame = @crt_frames . first
237
- locals_scope = current_frame [ :scopeChain ] . find { |f | f [ :type ] == "local" }
230
+ locals_scope = current_frame [ :scopeChain ] . find { |f | f [ :type ] == type }
238
231
object_id = locals_scope . dig ( :object , :objectId )
239
232
240
233
res = send_cdp_request "Runtime.getProperties" , objectId : object_id
241
234
242
- actual_locals = res . dig ( :result , :result ) . map do |loc |
235
+ res . dig ( :result , :result ) . map do |loc |
243
236
type = loc . dig ( :value , :className ) || loc . dig ( :value , :type ) . capitalize # TODO: sync this with get_ruby_type
244
237
245
238
{ name : loc [ :name ] , value : loc . dig ( :value , :description ) , type : type }
246
239
end
247
240
end
241
+ end
242
+
243
+ def assert_locals_result expected , frame_idx : 0
244
+ case get_target_ui
245
+ when 'vscode'
246
+ actual_locals = gather_dap_variables ( frame_idx : frame_idx , type : "locals" )
247
+
248
+ expected . each do |exp |
249
+ if exp [ :type ] == "String"
250
+ exp [ :value ] = exp [ :value ] . inspect
251
+ end
252
+ end
253
+ when 'chrome'
254
+ actual_locals = gather_variables ( type : "local" )
255
+ end
248
256
249
257
failure_msg = FailureMessage . new { create_protocol_message "result:\n #{ JSON . pretty_generate res } " }
250
258
0 commit comments