Class: CypressRails::Runner
- Inherits:
-
Object
- Object
- CypressRails::Runner
- Defined in:
- lib/cypress_rails/runner.rb
Instance Method Summary collapse
-
#initialize(host:, port:, bin_path: "npx cypress", tests_path:, output: IO.new(1)) ⇒ Runner
constructor
A new instance of Runner.
- #open ⇒ Object
- #run(browser = "chrome") ⇒ Object
Constructor Details
#initialize(host:, port:, bin_path: "npx cypress", tests_path:, output: IO.new(1)) ⇒ Runner
Returns a new instance of Runner.
5 6 7 8 9 10 11 |
# File 'lib/cypress_rails/runner.rb', line 5 def initialize(host:, port:, bin_path: "npx cypress", tests_path:, output: IO.new(1)) @host = host @port = port @bin_path = bin_path @tests_path = tests_path @output = output end |
Instance Method Details
#open ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/cypress_rails/runner.rb', line 34 def open pid = Process.spawn( { "CYPRESS_app_host" => host, "CYPRESS_app_port" => port.to_s, "CYPRESS_baseUrl" => "http://#{host}:#{port}" }, [bin_path, "open", "-P #{tests_path}"].join(" "), out: output, err: [:child, :out] ) output.close Process.wait(pid) end |
#run(browser = "chrome") ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/cypress_rails/runner.rb', line 13 def run(browser = "chrome") command = [bin_path, "run", "-P #{tests_path}"] command << "--browser #{browser}" if %w(chrome electron).include?(browser) command << "--record" if ENV.fetch("CYPRESS_RECORD_KEY", false) command << "--parallel" if ENV.fetch("CYPRESS_PARALLEL", false) command << "--config video=false" if browser == "chrome" pid = Process.spawn( { "CYPRESS_app_host" => host, "CYPRESS_app_port" => port.to_s, "CYPRESS_baseUrl" => "http://#{host}:#{port}" }, command.join(" "), out: output, err: [:child, :out] ) output.close _, status = Process.wait2(pid) status.exitstatus end |