Class: CypressRails::Init

Inherits:
Object
  • Object
show all
Defined in:
lib/cypress-rails/init.rb

Constant Summary collapse

DEFAULT_CONFIG =
<<~JS
  const { defineConfig } = require('cypress')

  module.exports = defineConfig({
    // setupNodeEvents can be defined in either
    // the e2e or component configuration
    e2e: {
      setupNodeEvents(on, config) {
        on('before:browser:launch', (browser = {}, launchOptions) => {
          /* ... */
        })
      },
    },
    screenshotsFolder: "tmp/cypress_screenshots",
    videosFolder: "tmp/cypress_videos",
    trashAssetsBeforeRuns: false
  })
JS

Instance Method Summary collapse

Instance Method Details

#call(cypress_dir = Config.new.cypress_dir) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/cypress-rails/init.rb', line 22

def call(cypress_dir = Config.new.cypress_dir)
  config_path = File.join(cypress_dir, "cypress.config.js")
  if !File.exist?(config_path)
    File.write(config_path, DEFAULT_CONFIG)
    puts "Cypress config initialized in `#{config_path}'"
  else
    warn "Cypress config already exists in `#{config_path}'. Skipping."
  end
end