mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-04-29 21:49:16 +08:00
When Chrome isn't installed, running "bin/rails qunit:test" would fail because it wouldn't be able to detect that Chromium was installed. This fixed that and also pass the detected browser to testem
46 lines
1.3 KiB
Ruby
46 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "rbconfig"
|
|
|
|
class ChromeInstalledChecker
|
|
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/]
|
|
chrome_path = "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"
|
|
binary = chrome_path if File.exist?(chrome_path)
|
|
elsif system("command -v google-chrome-stable >/dev/null;")
|
|
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
|
|
|
|
version = `\"#{binary}\" --version`
|
|
version_match = version.match(/[\d\.]+/)
|
|
|
|
raise ChromeError.new("Can't get the #{binary} version") if !version_match
|
|
|
|
if Gem::Version.new(version_match[0]) < Gem::Version.new("59")
|
|
raise ChromeVersionTooLow.new("Chrome 59 or higher is required")
|
|
end
|
|
|
|
# Return browser name for testem launcher (case-sensitive)
|
|
binary.include?("chromium") ? "Chromium" : "Chrome"
|
|
end
|
|
end
|