From bf8dc394bdb0306555f169d57ad84b635e50725c Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Sat, 19 Mar 2022 11:00:06 +0100 Subject: [PATCH] DEV: Add chromium to ChromeInstalledChecker (#16224) --- lib/chrome_installed_checker.rb | 16 +++++++++++++--- lib/tasks/qunit.rake | 2 +- lib/tasks/smoke_test.rake | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/chrome_installed_checker.rb b/lib/chrome_installed_checker.rb index bc89ff0b48e..0576eb74016 100644 --- a/lib/chrome_installed_checker.rb +++ b/lib/chrome_installed_checker.rb @@ -3,8 +3,10 @@ require "rbconfig" class ChromeInstalledChecker - class ChromeNotInstalled < StandardError; end - class ChromeVersionTooLow < StandardError; end + class ChromeError < StandardError; end + class ChromeVersionError < ChromeError; end + class ChromeNotInstalled < ChromeError; end + class ChromeVersionTooLow < ChromeError; end def self.run if RbConfig::CONFIG['host_os'][/darwin|mac os/] @@ -13,12 +15,20 @@ class ChromeInstalledChecker binary = "google-chrome-stable" end binary ||= "google-chrome" if system("command -v google-chrome >/dev/null;") + binary ||= "chromium" if system("command -v chromium >/dev/null;") if !binary raise ChromeNotInstalled.new("Chrome is not installed. Download from https://www.google.com/chrome/browser/desktop/index.html") end - if Gem::Version.new(`\"#{binary}\" --version`.match(/[\d\.]+/)[0]) < Gem::Version.new("59") + version = `\"#{binary}\" --version` + version_match = version.match(/[\d\.]+/) + + if !version_match + raise ChromeError.new("Can't get the #{binary} version") + end + + if Gem::Version.new(version_match[0]) < Gem::Version.new("59") raise ChromeVersionTooLow.new("Chrome 59 or higher is required") end end diff --git a/lib/tasks/qunit.rake b/lib/tasks/qunit.rake index 2f25312047a..dedd18e6db2 100644 --- a/lib/tasks/qunit.rake +++ b/lib/tasks/qunit.rake @@ -8,7 +8,7 @@ task "qunit:test", [:timeout, :qunit_path] do |_, args| begin ChromeInstalledChecker.run - rescue ChromeNotInstalled, ChromeVersionTooLow => err + rescue ChromeInstalledChecker::ChromeError => err abort err.message end diff --git a/lib/tasks/smoke_test.rake b/lib/tasks/smoke_test.rake index cc686ddf223..fc19481778a 100644 --- a/lib/tasks/smoke_test.rake +++ b/lib/tasks/smoke_test.rake @@ -6,7 +6,7 @@ task "smoke:test" do begin ChromeInstalledChecker.run - rescue ChromeNotInstalled, ChromeVersionTooLow => err + rescue ChromeInstalledChecker::ChromeError => err abort err.message end