DEV: correctly detect chromium on macos (#35441)

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
This commit is contained in:
Régis Hanol
2025-10-16 14:54:58 +02:00
committed by GitHub
parent 568f177aa8
commit b042dbcf67
2 changed files with 15 additions and 7 deletions
+5 -1
View File
@@ -17,7 +17,8 @@ class ChromeInstalledChecker
def self.run
if RbConfig::CONFIG["host_os"][/darwin|mac os/]
binary = "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"
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
@@ -38,5 +39,8 @@ class ChromeInstalledChecker
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
+10 -6
View File
@@ -5,11 +5,12 @@ task "qunit:test", %i[qunit_path filter] do |_, args|
require "socket"
require "chrome_installed_checker"
begin
ChromeInstalledChecker.run
rescue ChromeInstalledChecker::ChromeError => err
abort err.message
end
detected_browser =
begin
ChromeInstalledChecker.run
rescue ChromeInstalledChecker::ChromeError => err
abort err.message
end
unless system("command -v pnpm >/dev/null;")
abort "pnpm is not installed. See https://pnpm.io/installation"
@@ -99,7 +100,10 @@ task "qunit:test", %i[qunit_path filter] do |_, args|
end
puts "Rails server is warmed up"
env = { "UNICORN_PORT" => unicorn_port.to_s }
env = {
"UNICORN_PORT" => unicorn_port.to_s,
"TESTEM_DEFAULT_BROWSER" => ENV["TESTEM_DEFAULT_BROWSER"].presence || detected_browser,
}
cmd = []
parallel = ENV["QUNIT_PARALLEL"]