Sha256: 1cc1072b68cfd55d1193d7b4f020c0bb17d5ce14a64df6ddb31b747cf9f417ce

Contents?: true

Size: 788 Bytes

Versions: 5

Compression:

Stored size: 788 Bytes

Contents

module CypressRails
  class Init
    DEFAULT_CONFIG = {
      "screenshotsFolder" => "tmp/cypress_screenshots",
      "videosFolder" => "tmp/cypress_videos",
      "trashAssetsBeforeRuns" => false
    }

    def call(dir = Dir.pwd)
      config_path = File.join(dir, "cypress.json")
      json = JSON.pretty_generate(determine_new_config(config_path))
      File.write(config_path, json)
      puts "Cypress config (re)initialized in #{config_path}"
    end

    private

    def determine_new_config(config_path)
      if File.exist?(config_path)
        merge_existing_with_defaults(config_path)
      else
        DEFAULT_CONFIG
      end
    end

    def merge_existing_with_defaults(json_path)
      JSON.parse(File.read(json_path)).merge(DEFAULT_CONFIG).sort.to_h
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
cypress-rails-0.5.5 lib/cypress-rails/init.rb
cypress-rails-0.5.4 lib/cypress-rails/init.rb
cypress-rails-0.5.3 lib/cypress-rails/init.rb
cypress-rails-0.5.2 lib/cypress-rails/init.rb
cypress-rails-0.5.1 lib/cypress-rails/init.rb