Skip to content

Commit 92ed2fd

Browse files
Update install generator and remove update generator (#149)
1 parent 7b54a14 commit 92ed2fd

File tree

15 files changed

+228
-99
lines changed

15 files changed

+228
-99
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ vendor/bundle
99
.vscode
1010
node_modules
1111
package-lock.json
12-
yarn.lock
12+
yarn.lock
13+
specs_e2e/server.pid

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## [Unreleased]
2+
3+
### Changed
4+
* Removed the update generator and reduced options for install generator [PR 149](https://github.com/shakacode/cypress-on-rails/pull/149)
5+
16
## [1.16.0]
27
[Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.15.1...v1.16.0
38

README.md

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -61,46 +61,43 @@ Generate the boilerplate code using:
6161
# by default installs only cypress
6262
bin/rails g cypress_on_rails:install
6363

64-
# if you have/want a different cypress folder (default is cypress)
65-
bin/rails g cypress_on_rails:install --cypress_folder=spec/cypress
64+
# if you have/want a different cypress folder (default is e2e)
65+
bin/rails g cypress_on_rails:install --install_folder=spec/cypress
6666

67-
# to install both cypress and playwright
68-
bin/rails g cypress_on_rails:install --install_cypress --install_playwright --playwright_folder=playwright
69-
70-
# to change where the Ruby files reside (default is e2e)
71-
bin/rails g cypress_on_rails:install --install_folder=test/e2e
67+
# to install playwright instead of cypress
68+
bin/rails g cypress_on_rails:install --framework playwright
7269

7370
# if you target the Rails server with a path prefix to your URL
7471
bin/rails g cypress_on_rails:install --api_prefix=/api
7572

76-
# if you want to install cypress with npm
73+
# if you want to install with npm instead
7774
bin/rails g cypress_on_rails:install --install_with=npm
7875

7976
# if you already have cypress installed globally
80-
bin/rails g cypress_on_rails:install --no-install-cypress
77+
bin/rails g cypress_on_rails:install --install_with=skip
8178

8279
# to update the generated files run
83-
bin/rails g cypress_on_rails:update
80+
bin/rails g cypress_on_rails:install --install_with=skip
8481
```
8582

8683
The generator modifies/adds the following files/directory in your application:
8784
* `config/initializers/cypress_on_rails.rb` used to configure Cypress on Rails
88-
* `spec/cypress/e2e/` contains your cypress tests
89-
* `spec/playwright/e2e/` contains your playwright tests
90-
* `spec/cypress/support/on-rails.js` contains Cypress on Rails support code
91-
* `spec/playwright/support/on-rails.js` contains Playwright on Rails support code
92-
* `spec/e2e/app_commands/scenarios/` contains your Cypress on Rails scenario definitions
93-
* `spec/e2e/cypress_helper.rb` contains helper code for Cypress on Rails app commands
85+
* `e2e/cypress/integration/` contains your cypress tests
86+
* `e2e/cypress/support/on-rails.js` contains Cypress on Rails support code
87+
* `e2e/cypress/e2e_helper.rb` contains helper code to require libraries like factory_bot
88+
* `e2e/cypress/app_commands/` contains your scenario definitions
89+
* `e2e/playwright/e2e/` contains your playwright tests
90+
* `e2e/playwright/support/on-rails.js` contains Playwright on Rails support code
9491

95-
If you are not using `database_cleaner` look at `spec/e2e/app_commands/clean.rb`.
96-
If you are not using `factory_bot` look at `spec/e2e/app_commands/factory_bot.rb`.
92+
If you are not using `database_cleaner` look at `e2e/cypress/app_commands/clean.rb`.
93+
If you are not using `factory_bot` look at `e2e/cypress/app_commands/factory_bot.rb`.
9794

9895
Now you can create scenarios and commands that are plain Ruby files that get loaded through middleware, the ruby sky is your limit.
9996

10097
### Update your database.yml
10198

102-
When running `cypress test` or `playwright test` on your local computer it's recommended to start your server in development mode so that changes you
103-
make are picked up without having to restart the server.
99+
When writing and running tests on your local computer it's recommended to start your server in development mode so that changes you
100+
make are picked up without having to restart your local server.
104101
It's recommended you update your `database.yml` to check if the `CYPRESS` environment variable is set and switch it to the test database
105102
otherwise cypress will keep clearing your development database.
106103

@@ -127,11 +124,9 @@ Getting started on your local environment
127124
CYPRESS=1 bin/rails server -p 5017
128125

129126
# in separate window start cypress
130-
yarn cypress open
127+
yarn cypress open --project ./e2e
131128
# or for npm
132-
node_modules/.bin/cypress open
133-
# or if you changed the cypress folder to spec/cypress
134-
yarn cypress open --project ./spec
129+
npx cypress open --project ./e2e
135130
# or for playwright
136131
yarn playwright test --ui
137132
# or using npm
@@ -144,9 +139,9 @@ How to run cypress on CI
144139
# setup rails and start server in background
145140
# ...
146141

147-
yarn run cypress run
142+
yarn run cypress run --project ./e2e
148143
# or for npm
149-
npx cypress run
144+
npx cypress run --project ./e2e
150145
```
151146

152147
### Example of using factory bot

cypress-on-rails.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
1919
s.add_development_dependency 'rake'
2020
s.add_development_dependency 'rspec'
2121
s.add_development_dependency 'railties', '>= 3.2'
22-
s.add_development_dependency 'factory_bot'
22+
s.add_development_dependency 'factory_bot', '!= 6.4.5'
2323
s.add_development_dependency 'vcr'
2424
s.metadata = {
2525
"bug_tracker_uri" => "https://github.com/shakacode/cypress-on-rails/issues",

lib/generators/cypress_on_rails/install_generator.rb

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
module 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

lib/generators/cypress_on_rails/templates/config/initializers/cypress_on_rails.rb.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
if defined?(CypressOnRails)
22
CypressOnRails.configure do |c|
33
c.api_prefix = "<%= options.api_prefix %>"
4-
c.install_folder = File.expand_path("#{__dir__}/../../<%= options.install_folder %>")
4+
c.install_folder = File.expand_path("#{__dir__}/../../<%= options.install_folder %>/<%= options.framework %>")
55
# WARNING!! CypressOnRails can execute arbitrary ruby code
66
# please use with extra caution if enabling on hosted servers or starting your local server on 0.0.0.0
77
c.use_middleware = !Rails.env.production?

lib/generators/cypress_on_rails/update_generator.rb

Lines changed: 0 additions & 24 deletions
This file was deleted.

specs_e2e/rails_3_2/test.sh

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@ export BUNDLE_GEMFILE="$DIR/Gemfile"
1010
cd $DIR
1111

1212
echo '-- bundle install'
13-
bundle --version
14-
bundle install --quiet --gemfile="$DIR/Gemfile" --retry 2 --path vendor/bundle
13+
gem install bundler -v '1.0.22'
14+
bundle _1.0.22_ --version
15+
bundle _1.0.22_ install --quiet --gemfile="$DIR/Gemfile" --path vendor/bundle
1516

1617
echo '-- cypress install'
17-
bundle exec ./bin/rails g cypress_on_rails:install --install_cypress --install_playwright --install_with=npm
18+
bundle exec ./bin/rails g cypress_on_rails:install --install_with=npm --install_folder="." --force
1819
rm -vf cypress/e2e/rails_examples/advance_factory_bot.cy.js
1920
rm -vf cypress/e2e/rails_examples/using_vcr.cy.js
2021

2122
echo '-- start rails server'
2223
# make sure the server is not running
23-
(kill -9 `cat tmp/pids/server.pid` || true )
24+
(kill -9 `cat ../server.pid` || true )
2425

25-
bundle exec ./bin/rails server -p 5017 -e test &
26+
bundle exec ./bin/rails server -p 5017 -e test -P ../server.pid &
2627
sleep 2 # give rails a chance to start up correctly
2728

2829
echo '-- cypress run'
@@ -31,13 +32,19 @@ cp -fv ../cypress.config.js .
3132
# then
3233
# node_modules/.bin/cypress run
3334
# else
34-
node_modules/.bin/cypress run --record
35+
npx cypress run --record
3536
# fi
3637

38+
echo '-- playwright install'
39+
bundle exec ./bin/rails g cypress_on_rails:install --framework playwright --install_with=npm --install_folder="." --force
40+
rm -vf playwright/e2e/rails_examples/advance_factory_bot.cy.js
41+
rm -vf playwright/e2e/rails_examples/using_vcr.cy.js
42+
3743
echo '-- playwright run'
3844
cp -fv ../playwright.config.js .
3945
npx playwright install-deps
46+
npx playwright install
4047
npx playwright test playwright/e2e/
4148

4249
echo '-- stop rails server'
43-
kill -9 `cat tmp/pids/server.pid`
50+
kill -9 `cat ../server.pid` || true

specs_e2e/rails_4_2/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ spec/cypress.config.js
44
spec/package.json
55
spec/yarn.lock
66
spec/cypress
7+
spec/app_commands
78
config/initializers/cypress_on_rails.rb
89
vendor/bundle
910
tmp/pids

specs_e2e/rails_4_2/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"main": "index.js",
55
"license": "MIT",
66
"devDependencies": {
7-
"cypress": "^10.0.2",
8-
"cypress-on-rails": "file:../../plugin"
7+
"@playwright/test": "^1.40.1",
8+
"cypress": "^10.11.0",
9+
"cypress-on-rails": "file:../../plugin",
10+
"playwright": "^1.40.1"
911
}
1012
}

0 commit comments

Comments
 (0)