Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update puppeteer test versions #241

Merged
merged 3 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,27 @@ jobs:
'19.11.1',
'20.9.0',
'21.9.0',
'22.4.1'
'22.12.0'
]
include:
- ruby-version: '2.7'
node-version: '18'
puppeteer-version: '22.4.1'
puppeteer-version: '22.12.0'
- ruby-version: '3.0'
node-version: '18'
puppeteer-version: '22.4.1'
puppeteer-version: '22.12.0'
- ruby-version: '3.1'
node-version: '18'
puppeteer-version: '22.4.1'
puppeteer-version: '22.12.0'
- ruby-version: '3.2'
node-version: '18'
puppeteer-version: '22.4.1'
puppeteer-version: '22.12.0'
- ruby-version: '3.3'
node-version: '20'
puppeteer-version: '22.4.1'
puppeteer-version: '22.12.0'
- ruby-version: '3.3'
node-version: '22'
puppeteer-version: '22.12.0'

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
},
"homepage": "https://github.com/Studiosity/grover#readme",
"devDependencies": {
"puppeteer": "^22.4.1"
"puppeteer": "^22.12.0"
}
}
48 changes: 38 additions & 10 deletions spec/grover/middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@
it 'returns PDF content type' do
get 'http://www.example.org/test.pdf'
expect(last_response.headers['Content-Type']).to eq 'application/pdf'
response_size = Grover.new('Grover McGroveryface').to_pdf.bytesize
response_size = Grover.new('Grover McGroveryface', display_url: 'http://www.example.org/test').to_pdf.bytesize
expect(last_response.body.bytesize).to eq response_size
expect(last_response.headers['Content-Length']).to eq response_size.to_s
end

it 'matches PDF case insensitive' do
get 'http://www.example.org/test.PDF'
expect(last_response.headers['Content-Type']).to eq 'application/pdf'
response_size = Grover.new('Grover McGroveryface').to_pdf.bytesize
response_size = Grover.new('Grover McGroveryface', display_url: 'http://www.example.org/test').to_pdf.bytesize
expect(last_response.body.bytesize).to eq response_size
expect(last_response.headers['Content-Length']).to eq response_size.to_s
end
Expand Down Expand Up @@ -352,7 +352,9 @@
it 'returns response as PDF' do
get 'http://www.example.org/test.pdf'
expect(last_response.headers['Content-Type']).to eq 'application/pdf'
expect(last_response.body.bytesize).to eq Grover.new('Rackalicious').to_pdf.bytesize
expect(last_response.body.bytesize).to(
eq(Grover.new('Rackalicious', display_url: 'http://www.example.org/test').to_pdf.bytesize)
)
end

context 'when app configuration has PDF middleware disabled' do
Expand Down Expand Up @@ -416,7 +418,9 @@
it 'returns response as PDF' do
get 'http://www.example.org/test.pdf'
expect(last_response.headers['Content-Type']).to eq 'application/pdf'
expect(last_response.body.bytesize).to eq Grover.new('Part 1Part 2').to_pdf.bytesize
expect(last_response.body.bytesize).to(
eq(Grover.new('Part 1Part 2', display_url: 'http://www.example.org/test').to_pdf.bytesize)
)
end
end
end
Expand All @@ -433,7 +437,9 @@
with('Grover McGroveryface', 'http://www.example.org/', 'http')
)
get 'http://www.example.org/test.pdf'
expect(last_response.body.bytesize).to eq Grover.new('Processed McProcessyface').to_pdf.bytesize
expect(last_response.body.bytesize).to(
eq(Grover.new('Processed McProcessyface', display_url: 'http://www.example.org/test').to_pdf.bytesize)
)
end

context 'with root_url specified as an argument' do
Expand All @@ -455,7 +461,9 @@
with('Grover McGroveryface', 'http://example.com/', 'http')
)
get 'http://www.example.org/test.pdf'
expect(last_response.body.bytesize).to eq Grover.new('Processed McProcessyface').to_pdf.bytesize
expect(last_response.body.bytesize).to(
eq(Grover.new('Processed McProcessyface', display_url: 'http://www.example.org/test').to_pdf.bytesize)
)
end
end

Expand All @@ -472,15 +480,25 @@

it 'uses the specified root_url' do
get 'http://www.example.org/test.pdf'
expect(last_response.body.bytesize).to eq Grover.new('src="http://example.com/asdf"').to_pdf.bytesize
expect(last_response.body.bytesize).to(
eq(
Grover.new('src="http://example.com/asdf"', display_url: 'http://www.example.org/test').to_pdf.bytesize
)
)
end

context 'when the root_url is also set in configuration' do
before { allow(Grover.configuration).to receive(:root_url).and_return 'http://other.domain/' }

it 'uses the specified root_url in the middleware initializer' do
get 'http://www.example.org/test.pdf'
expect(last_response.body.bytesize).to eq Grover.new('src="http://example.com/asdf"').to_pdf.bytesize
expect(last_response.body.bytesize).to(
eq(
Grover.
new('src="http://example.com/asdf"', display_url: 'http://www.example.org/test').
to_pdf.bytesize
)
)
end
end
end
Expand All @@ -490,14 +508,24 @@

it 'uses the specified root_url' do
get 'http://www.example.org/test.pdf'
expect(last_response.body.bytesize).to eq Grover.new('src="http://example.com/asdf"').to_pdf.bytesize
expect(last_response.body.bytesize).to(
eq(
Grover.new('src="http://example.com/asdf"', display_url: 'http://www.example.org/test').to_pdf.bytesize
)
)
end
end

context 'without root_url specified' do
it 'uses the detected root_url (request url)' do
get 'http://www.example.org/test.pdf'
expect(last_response.body.bytesize).to eq Grover.new('src="http://www.example.org/asdf"').to_pdf.bytesize
expect(last_response.body.bytesize).to(
eq(
Grover.
new('src="http://www.example.org/asdf"', display_url: 'http://www.example.org/test').
to_pdf.bytesize
)
)
end
end
end
Expand Down
26 changes: 20 additions & 6 deletions spec/grover/processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -384,12 +384,18 @@

context 'when options include executablePath' do
let(:options) { { 'executablePath' => '/totes/invalid/path' } }
let(:error_message) do
if puppeteer_version_on_or_after? '22.6.3'
'Browser was not found at the configured executablePath (/totes/invalid/path)'
else
%r{Failed to launch (chrome|the browser process)! spawn /totes/invalid/path}
end
end

it do
expect do
convert
end.to raise_error Grover::JavaScript::Error,
%r{Failed to launch (chrome|the browser process)! spawn /totes/invalid/path}
end.to raise_error Grover::JavaScript::Error, error_message
end
end

Expand Down Expand Up @@ -448,7 +454,7 @@

it { expect(pdf_text_content).to match(/Request contained \d+ headers/) }
it { expect(pdf_text_content).to include '1. host localhost:4567' }
it { expect(pdf_text_content).to include '4. user-agent Grover user agent' }
it { expect(pdf_text_content).to match(/[45]\. user-agent Grover user agent/) }
end
end

Expand Down Expand Up @@ -680,11 +686,18 @@
</html>
HTML
end
let(:error_message) do
if puppeteer_version_on_or_after? '22.6.0'
'net::ERR_BLOCKED_BY_ORB at https://google.com/404.jpg'
else
'404 https://google.com/404.jpg'
end
end

it do
expect do
convert
end.to raise_error Grover::JavaScript::RequestFailedError, '404 https://google.com/404.jpg'
end.to raise_error Grover::JavaScript::RequestFailedError, error_message
end
end

Expand Down Expand Up @@ -960,9 +973,10 @@
# don't really want to rely on pixel testing the website screenshot
# so we'll check it's mean colour is roughly what we expect
it do
pixel_mean = puppeteer_version_on_or_after?('22.9.0') ? 140.925 : 161.497

expect(image.data.dig('imageStatistics', MiniMagick.imagemagick7? ? 'Overall' : 'all', 'mean').to_f).
to be_within(10).of(97.7473). # ImageMagick 6.9.3-1 (version used by Travis CI)
or be_within(10).of(161.497) # ImageMagick 6.9.10-84
to be_within(10).of(pixel_mean)
end
end

Expand Down
Loading