1
1
module CypressOnRails
2
2
class InstallGenerator < Rails ::Generators ::Base
3
3
class_option :api_prefix , type : :string , default : ''
4
+ class_option :framework , type : :string , default : 'cypress'
4
5
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
7
6
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'
10
7
class_option :experimental , type : :boolean , default : false
11
8
source_root File . expand_path ( '../templates' , __FILE__ )
12
9
@@ -17,10 +14,11 @@ def install_framework
17
14
18
15
command = nil
19
16
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
24
22
if options . install_with == 'yarn'
25
23
command = "yarn --cwd=#{ install_dir } add #{ packages . join ( ' ' ) } --dev"
26
24
elsif options . install_with == 'npm'
@@ -31,28 +29,28 @@ def install_framework
31
29
fail "failed to install #{ packages . join ( ' ' ) } " unless system ( command )
32
30
end
33
31
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"
38
36
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"
42
40
end
43
41
end
44
42
45
43
def add_initial_files
46
44
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"
52
50
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"
56
54
end
57
55
end
58
56
0 commit comments