Sha256: eeb11a5db3e2f7961236c9de7529ef6cfdfa79e00277efcf52f2b1cea65c5afb

Contents?: true

Size: 1.72 KB

Versions: 5

Compression:

Stored size: 1.72 KB

Contents

# frozen_string_literal: true

require "thor"
require "cypress_rails/runner"
require "cypress_rails/server"

module CypressRails
  Config = Struct.new(:command, :cypress_bin_path, :host, :log_path, :tests_path)

  class CLI < Thor
    class_option :command,
      type: :string,
      desc: "command to start the server",
      default: "bundle exec rails server",
      aliases: %w(-c)
    class_option :cypress_bin_path,
      type: :string,
      desc: "command to run cypress",
      default: "npx cypress",
      aliases: %w(-cc)
    class_option :host,
      type: :string,
      desc: "host on which to start the local server",
      default: "localhost",
      aliases: %w(-h)
    class_option :log_path,
      type: :string,
      desc: "path to the log file for the server",
      default: "/dev/null",
      aliases: %w(-l)
    class_option :tests_path,
      type: :string,
      desc: "path to Cypress tests",
      default: "./spec",
      aliases: %w(-t)

    desc "test", "Run all tests in headless mode"
    def test
      server.start do |host, port|
        exit Runner.new(
          host: host, port: port, bin_path: config.cypress_bin_path, tests_path: config.tests_path
        ).run
      end
    end

    desc "open", "Start the server and open Cypress Dashboard"
    def open
      server.start do |host, port|
        exit Runner.new(
          host: host, port: port, bin_path: config.cypress_bin_path, tests_path: config.tests_path
        ).open
      end
    end

    private

    def server
      @server ||= Server.new(config.host, config.command, config.log_path)
    end

    def config
      @config ||= Config.new(
        *options.values_at(:command, :cypress_bin_path, :host, :log_path, :tests_path)
      )
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
cypress_rails-0.5.0 lib/cypress_rails/cli.rb
cypress_rails-0.4.2 lib/cypress_rails/cli.rb
cypress_rails-0.4.1 lib/cypress_rails/cli.rb
cypress_rails-0.4.0 lib/cypress_rails/cli.rb
cypress_rails-0.3.0 lib/cypress_rails/cli.rb