Sha256: 0ea36a175d0491d50d00c69c37a0d4b6aa06df870de35ee0cd3be7d537a00238

Contents?: true

Size: 1022 Bytes

Versions: 1

Compression:

Stored size: 1022 Bytes

Contents

# frozen_string_literal: true

module CypressRails
  class Runner
    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

    def run
      pid = Process.spawn(
        {
          "CYPRESS_app_host" => host,
          "CYPRESS_app_port" => port.to_s,
        },
        [bin_path, "run", "-P #{tests_path}"].join(" "),
        out: output,
        err: [:child, :out]
      )
      output.close
      _, status = Process.wait2(pid)
      status.exitstatus
    end

    def open
      pid = Process.spawn(
        {
          "CYPRESS_app_host" => host,
          "CYPRESS_app_port" => port.to_s,
        },
        [bin_path, "open", "-P #{tests_path}"].join(" "),
        out: output,
        err: [:child, :out]
      )
      output.close
      Process.wait(pid)
    end

    private

    attr_reader :host, :port, :bin_path, :tests_path, :output
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cypress_rails-0.3.0 lib/cypress_rails/runner.rb