11module CypressOnRails
22 class InstallGenerator < Rails ::Generators ::Base
33 class_option :api_prefix , type : :string , default : ''
4+ class_option :framework , type : :string , default : 'cypress'
45 class_option :install_folder , type : :string , default : 'e2e'
5- class_option :install_cypress , type : :boolean , default : true
6- class_option :install_playwright , type : :boolean , default : false
76 class_option :install_with , type : :string , default : 'yarn'
8- class_option :cypress_folder , type : :string , default : 'cypress'
9- class_option :playwright_folder , type : :string , default : 'playwright'
107 class_option :experimental , type : :boolean , default : false
118 source_root File . expand_path ( '../templates' , __FILE__ )
129
@@ -17,10 +14,11 @@ def install_framework
1714
1815 command = nil
1916 packages = [ ]
20-
21- packages << 'cypress' if options . install_cypress
22- packages . push ( 'playwright' , '@playwright/test' ) if options . install_playwright
23-
17+ packages = if options . framework == 'cypress'
18+ [ 'cypress' , 'cypress-on-rails' ]
19+ elsif options . framework == 'playwright'
20+ [ 'playwright' , '@playwright/test' ]
21+ end
2422 if options . install_with == 'yarn'
2523 command = "yarn --cwd=#{ install_dir } add #{ packages . join ( ' ' ) } --dev"
2624 elsif options . install_with == 'npm'
@@ -31,28 +29,28 @@ def install_framework
3129 fail "failed to install #{ packages . join ( ' ' ) } " unless system ( command )
3230 end
3331
34- if options . install_cypress
35- template "spec/cypress/support/index.js.erb" , "#{ options . cypress_folder } /support/index.js"
36- copy_file "spec/cypress/support/commands.js" , "#{ options . cypress_folder } /support/commands.js"
37- copy_file "spec/cypress.config.js" , "#{ options . cypress_folder } /.. /cypress.config.js"
32+ if options . framework == 'cypress'
33+ template "spec/cypress/support/index.js.erb" , "#{ options . install_folder } /cypress /support/index.js"
34+ copy_file "spec/cypress/support/commands.js" , "#{ options . install_folder } /cypress /support/commands.js"
35+ copy_file "spec/cypress.config.js" , "#{ options . install_folder } /cypress.config.js"
3836 end
39- if options . install_playwright
40- template "spec/playwright/support/index.js.erb" , "#{ options . playwright_folder } /support/index.js"
41- copy_file "spec/playwright.config.js" , "#{ options . playwright_folder } /.. /playwright.config.js"
37+ if options . framework == 'playwright'
38+ template "spec/playwright/support/index.js.erb" , "#{ options . install_folder } /playwright /support/index.js"
39+ copy_file "spec/playwright.config.js" , "#{ options . install_folder } /playwright.config.js"
4240 end
4341 end
4442
4543 def add_initial_files
4644 template "config/initializers/cypress_on_rails.rb.erb" , "config/initializers/cypress_on_rails.rb"
47- template "spec/e2e/e2e_helper.rb.erb" , "#{ options . install_folder } /e2e_helper.rb"
48- directory 'spec/e2e/app_commands' , "#{ options . install_folder } /app_commands"
49- if options . install_cypress
50- copy_file "spec/cypress/support/on-rails.js" , "#{ options . cypress_folder } /support/on-rails.js"
51- directory 'spec/cypress/e2e/rails_examples' , "#{ options . cypress_folder } /e2e/rails_examples"
45+ template "spec/e2e/e2e_helper.rb.erb" , "#{ options . install_folder } /#{ options . framework } / e2e_helper.rb"
46+ directory 'spec/e2e/app_commands' , "#{ options . install_folder } /#{ options . framework } / app_commands"
47+ if options . framework == 'cypress'
48+ copy_file "spec/cypress/support/on-rails.js" , "#{ options . install_folder } /cypress /support/on-rails.js"
49+ directory 'spec/cypress/e2e/rails_examples' , "#{ options . install_folder } /cypress /e2e/rails_examples"
5250 end
53- if options . install_playwright
54- copy_file "spec/playwright/support/on-rails.js" , "#{ options . playwright_folder } /support/on-rails.js"
55- directory 'spec/playwright/e2e/rails_examples' , "#{ options . playwright_folder } /e2e/rails_examples"
51+ if options . framework == 'playwright'
52+ copy_file "spec/playwright/support/on-rails.js" , "#{ options . install_folder } /playwright /support/on-rails.js"
53+ directory 'spec/playwright/e2e/rails_examples' , "#{ options . install_folder } /playwright /e2e/rails_examples"
5654 end
5755 end
5856
0 commit comments