Skip to content

Commit

Permalink
fix: propagate close reason to api context
Browse files Browse the repository at this point in the history
  • Loading branch information
YusukeIwaki committed Jun 22, 2024
1 parent f64152b commit 957c48e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/playwright/channel_owners/api_request_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ module Playwright
@tracing = ChannelOwners::Tracing.from(@initializer['tracing'])
end

def dispose
def dispose(reason: nil)
@close_reason = reason
@channel.send_message_to_server('dispose')
rescue => e
require 'pry'
binding.pry
raise
end

def delete(url, **options)
Expand Down Expand Up @@ -92,6 +97,9 @@ def fetch(
multipart: nil,
params: nil,
timeout: nil)
if @close_reason
raise ::Playwright::Error.new(message: @close_reason)
end
if [data, form, multipart].compact.count > 1
raise ArgumentError.new("Only one of 'data', 'form' or 'multipart' can be specified")
end
Expand Down
2 changes: 1 addition & 1 deletion lib/playwright/channel_owners/browser_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ def close(reason: nil)
return if @close_was_called
@close_was_called = true
@close_reason = reason

@request.dispose(reason: reason)
inner_close
@channel.send_message_to_server('close', { reason: reason }.compact)
@closed_promise.value!
Expand Down
9 changes: 9 additions & 0 deletions spec/integration/browser_context/fetch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -402,4 +402,13 @@
expect(multipart['file'][:tempfile].read).to eq("var x = 10;\r\n;console.log(x);")
end
end

it 'should not work after context dispose', sinatra: true do
with_context do |context|
context.close(reason: 'Test ended.')
expect {
context.request.get(server_empty_page)
}.to raise_error(/Test ended/)
end
end
end

0 comments on commit 957c48e

Please sign in to comment.