-
Notifications
You must be signed in to change notification settings - Fork 33
/
tracing.rb
96 lines (81 loc) · 2.71 KB
/
tracing.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
module Playwright
define_channel_owner :Tracing do
def start(name: nil, title: nil, screenshots: nil, snapshots: nil, sources: nil)
params = {
name: name,
screenshots: screenshots,
snapshots: snapshots,
sources: sources,
}.compact
@include_sources = params[:sources] || false
@channel.send_message_to_server('tracingStart', params)
trace_name = @channel.send_message_to_server('tracingStartChunk', { title: title, name: name }.compact)
start_collecting_stacks(trace_name)
end
def start_chunk(title: nil, name: nil)
trace_name = @channel.send_message_to_server('tracingStartChunk', { title: title, name: name }.compact)
start_collecting_stacks(trace_name)
end
private def start_collecting_stacks(trace_name)
unless @is_tracing
@is_tracing = true
@connection.set_in_tracing(true)
end
@stacks_id = @connection.local_utils.tracing_started(@traces_dir, trace_name)
end
def stop_chunk(path: nil)
do_stop_chunk(file_path: path)
end
def stop(path: nil)
do_stop_chunk(file_path: path)
@channel.send_message_to_server('tracingStop')
end
private def do_stop_chunk(file_path:)
if @is_tracing
@is_tracing = false
@connection.set_in_tracing(false)
end
unless file_path
# Not interested in any artifacts
@channel.send_message_to_server('tracingStopChunk', mode: 'discard')
if @stacks_id
@connection.local_utils.trace_discarded(@stacks_id)
end
return
end
unless @connection.remote?
result = @channel.send_message_to_server_result('tracingStopChunk', mode: 'entries')
@connection.local_utils.zip(
zipFile: file_path,
entries: result['entries'],
stacksId: @stacks_id,
mode: 'write',
includeSources: @include_sources,
)
return
end
result = @channel.send_message_to_server_result('tracingStopChunk', mode: 'archive')
# The artifact may be missing if the browser closed while stopping tracing.
unless result['artifact']
if @stacks_id
@connection.local_utils.trace_discarded(@stacks_id)
end
return
end
# Save trace to the final local file.
artifact = ChannelOwners::Artifact.from(result['artifact'])
artifact.save_as(file_path)
artifact.delete
@connection.local_utils.zip(
zipFile: file_path,
entries: [],
stacksId: @stacks_id,
mode: 'append',
includeSources: @include_sources,
)
end
private def update_traces_dir(traces_dir)
@traces_dir = traces_dir
end
end
end