cypress-on-rails 1.18.0 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/claude-code-review.yml +57 -0
  3. data/.github/workflows/claude.yml +50 -0
  4. data/CHANGELOG.md +399 -98
  5. data/README.md +139 -19
  6. data/RELEASING.md +200 -0
  7. data/Rakefile +1 -4
  8. data/cypress-on-rails.gemspec +3 -2
  9. data/docs/BEST_PRACTICES.md +678 -0
  10. data/docs/DX_IMPROVEMENTS.md +163 -0
  11. data/docs/PLAYWRIGHT_GUIDE.md +554 -0
  12. data/docs/RELEASE.md +124 -0
  13. data/docs/TROUBLESHOOTING.md +351 -0
  14. data/docs/VCR_GUIDE.md +499 -0
  15. data/lib/cypress_on_rails/command_executor.rb +24 -0
  16. data/lib/cypress_on_rails/configuration.rb +32 -0
  17. data/lib/cypress_on_rails/railtie.rb +7 -0
  18. data/lib/cypress_on_rails/server.rb +258 -0
  19. data/lib/cypress_on_rails/state_reset_middleware.rb +58 -0
  20. data/lib/cypress_on_rails/version.rb +1 -1
  21. data/lib/generators/cypress_on_rails/install_generator.rb +2 -2
  22. data/lib/generators/cypress_on_rails/templates/config/initializers/cypress_on_rails.rb.erb +14 -2
  23. data/lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/using_factory_bot.cy.js +2 -2
  24. data/lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/using_scenarios.cy.js +1 -1
  25. data/lib/generators/cypress_on_rails/templates/spec/cypress/support/on-rails.js +1 -1
  26. data/lib/tasks/cypress.rake +33 -0
  27. data/rakelib/release.rake +80 -0
  28. data/rakelib/task_helpers.rb +23 -0
  29. data/rakelib/update_changelog.rake +63 -0
  30. data/spec/cypress_on_rails/configuration_spec.rb +6 -0
  31. data/spec/generators/install_generator_spec.rb +222 -0
  32. metadata +34 -4
data/README.md CHANGED
@@ -47,6 +47,28 @@ Consider first learning the basics of Playwright before attempting to integrate
47
47
 
48
48
  * [Good start Here](https://playwright.dev/docs/writing-tests)
49
49
 
50
+ ## Quick Start
51
+
52
+ ```bash
53
+ # 1. Add to Gemfile
54
+ gem 'cypress-on-rails', '~> 1.0'
55
+
56
+ # 2. Install and generate
57
+ bundle install
58
+ bin/rails g cypress_on_rails:install
59
+
60
+ # 3. Run tests (new rake tasks!)
61
+ bin/rails cypress:open # Open Cypress UI
62
+ bin/rails cypress:run # Run headless
63
+ ```
64
+
65
+ For Playwright:
66
+ ```bash
67
+ bin/rails g cypress_on_rails:install --framework playwright
68
+ bin/rails playwright:open # Open Playwright UI
69
+ bin/rails playwright:run # Run headless
70
+ ```
71
+
50
72
  ## Overview
51
73
 
52
74
  Gem for using [cypress.io](http://github.com/cypress-io/) or [playwright.dev](https://playwright.dev/) in Rails and Ruby Rack applications to control state as mentioned in [Cypress Best Practices](https://docs.cypress.io/guides/references/best-practices.html#Organizing-Tests-Logging-In-Controlling-State).
@@ -64,7 +86,16 @@ Has examples of setting up state with:
64
86
  * scenarios
65
87
  * custom commands
66
88
 
67
- ## Resources
89
+ ## Documentation
90
+
91
+ ### 📚 Essential Guides
92
+ * **[Best Practices Guide](docs/BEST_PRACTICES.md)** - Recommended patterns and practices
93
+ * **[Troubleshooting Guide](docs/TROUBLESHOOTING.md)** - Solutions to common issues
94
+ * **[Playwright Guide](docs/PLAYWRIGHT_GUIDE.md)** - Complete Playwright documentation
95
+ * **[VCR Integration Guide](docs/VCR_GUIDE.md)** - HTTP recording and mocking
96
+ * **[DX Improvements](docs/DX_IMPROVEMENTS.md)** - Recent improvements based on user feedback
97
+
98
+ ### 🎥 Resources
68
99
  * [Video of getting started with this gem](https://grant-ps.blog/2018/08/10/getting-started-with-cypress-io-and-ruby-on-rails/)
69
100
  * [Article: Introduction to Cypress on Rails](https://www.shakacode.com/blog/introduction-to-cypress-on-rails/)
70
101
 
@@ -103,17 +134,52 @@ bin/rails g cypress_on_rails:install --install_with=skip
103
134
  bin/rails g cypress_on_rails:install --install_with=skip
104
135
  ```
105
136
 
106
- The generator modifies/adds the following files/directory in your application:
107
- * `config/initializers/cypress_on_rails.rb` used to configure Cypress on Rails
108
- * `e2e/cypress/integration/` contains your cypress tests
109
- * `e2e/cypress/support/on-rails.js` contains Cypress on Rails support code
110
- * `e2e/cypress/e2e_helper.rb` contains helper code to require libraries like factory_bot
111
- * `e2e/cypress/app_commands/` contains your scenario definitions
112
- * `e2e/playwright/e2e/` contains your playwright tests
113
- * `e2e/playwright/support/on-rails.js` contains Playwright on Rails support code
137
+ The generator creates the following structure in your application:
138
+
139
+ **For Cypress:**
140
+ ```
141
+ e2e/
142
+ cypress.config.js # Cypress configuration
143
+ e2e_helper.rb # Helper code for factory_bot, database_cleaner, etc.
144
+ app_commands/ # Your custom commands and scenarios
145
+ clean.rb
146
+ factory_bot.rb
147
+ scenarios/
148
+ basic.rb
149
+ fixtures/
150
+ vcr_cassettes/ # VCR recordings (if using VCR)
151
+ cypress/
152
+ support/
153
+ index.js
154
+ commands.js
155
+ on-rails.js # Cypress on Rails support code
156
+ e2e/
157
+ rails_examples/ # Example tests
158
+ ```
159
+
160
+ **For Playwright:**
161
+ ```
162
+ e2e/
163
+ playwright.config.js # Playwright configuration
164
+ e2e_helper.rb # Helper code for factory_bot, database_cleaner, etc.
165
+ app_commands/ # Your custom commands and scenarios (shared with Cypress)
166
+ fixtures/
167
+ vcr_cassettes/ # VCR recordings (if using VCR)
168
+ playwright/
169
+ support/
170
+ index.js
171
+ on-rails.js # Playwright on Rails support code
172
+ e2e/
173
+ rails_examples/ # Example tests
174
+ ```
175
+
176
+ **Additional files:**
177
+ * `config/initializers/cypress_on_rails.rb` - Configuration for Cypress on Rails
178
+
179
+ **Important:** Note that `e2e_helper.rb` and `app_commands/` are at the root of the install folder (e.g., `e2e/`), NOT inside the framework subdirectory (e.g., `e2e/cypress/`). This allows both Cypress and Playwright to share the same commands and helpers when using both frameworks.
114
180
 
115
- If you are not using `database_cleaner` look at `e2e/cypress/app_commands/clean.rb`.
116
- If you are not using `factory_bot` look at `e2e/cypress/app_commands/factory_bot.rb`.
181
+ If you are not using `database_cleaner` look at `e2e/app_commands/clean.rb`.
182
+ If you are not using `factory_bot` look at `e2e/app_commands/factory_bot.rb`.
117
183
 
118
184
  Now you can create scenarios and commands that are plain Ruby files that get loaded through middleware, the ruby sky is your limit.
119
185
 
@@ -143,6 +209,29 @@ Please use with extra caution if starting your local server on 0.0.0.0 or runnin
143
209
 
144
210
  Getting started on your local environment
145
211
 
212
+ ### Using Rake Tasks (Recommended)
213
+
214
+ The easiest way to run tests is using the provided rake tasks, which automatically manage the Rails server:
215
+
216
+ ```shell
217
+ # For Cypress
218
+ bin/rails cypress:open # Opens Cypress test runner UI
219
+ bin/rails cypress:run # Runs Cypress tests in headless mode
220
+
221
+ # For Playwright
222
+ bin/rails playwright:open # Opens Playwright test runner UI
223
+ bin/rails playwright:run # Runs Playwright tests in headless mode
224
+ ```
225
+
226
+ These tasks will:
227
+ - Start the Rails test server automatically
228
+ - Execute your tests
229
+ - Stop the server when done
230
+
231
+ ### Manual Server Management
232
+
233
+ You can also manage the server manually:
234
+
146
235
  ```shell
147
236
  # start rails
148
237
  CYPRESS=1 bin/rails server -p 5017
@@ -394,8 +483,7 @@ Add your VCR configuration to your `config/cypress_on_rails.rb`
394
483
  c.vcr_options = {
395
484
  hook_into: :webmock,
396
485
  default_cassette_options: { record: :once },
397
- # It's possible to override cassette_library_dir using install_folder
398
- cassette_library_dir: File.expand_path("#{__dir__}/../../spec/cypress/fixtures/vcr_cassettes")
486
+ cassette_library_dir: File.expand_path("#{__dir__}/../../e2e/fixtures/vcr_cassettes")
399
487
  }
400
488
  ```
401
489
 
@@ -506,6 +594,44 @@ Consider VCR configuration in `cypress_helper.rb` to ignore hosts.
506
594
  All cassettes will be recorded and saved automatically, using the pattern `<vcs_cassettes_path>/graphql/<operation_name>`
507
595
 
508
596
 
597
+ ## Server Hooks Configuration
598
+
599
+ When using the rake tasks (`cypress:open`, `cypress:run`, `playwright:open`, `playwright:run`), you can configure lifecycle hooks to customize test server behavior:
600
+
601
+ ```ruby
602
+ CypressOnRails.configure do |c|
603
+ # Run code before Rails server starts
604
+ c.before_server_start = -> {
605
+ puts "Preparing test environment..."
606
+ }
607
+
608
+ # Run code after Rails server is ready
609
+ c.after_server_start = -> {
610
+ puts "Server is ready for testing!"
611
+ }
612
+
613
+ # Run code after database transaction begins (transactional mode only)
614
+ c.after_transaction_start = -> {
615
+ # Load seed data that should be rolled back after tests
616
+ }
617
+
618
+ # Run code after application state is reset
619
+ c.after_state_reset = -> {
620
+ Rails.cache.clear
621
+ }
622
+
623
+ # Run code before Rails server stops
624
+ c.before_server_stop = -> {
625
+ puts "Cleaning up test environment..."
626
+ }
627
+
628
+ # Configure server settings
629
+ c.server_host = 'localhost' # or use ENV['CYPRESS_RAILS_HOST']
630
+ c.server_port = 3001 # or use ENV['CYPRESS_RAILS_PORT']
631
+ c.transactional_server = true # Enable automatic transaction rollback
632
+ end
633
+ ```
634
+
509
635
  ## `before_request` configuration
510
636
 
511
637
  You may perform any custom action before running a CypressOnRails command, such as authentication, or sending metrics. Please set `before_request` as part of the CypressOnRails configuration.
@@ -685,15 +811,9 @@ In `config/initializers/cypress_on_rails.rb`, add this line:
685
811
  <img alt="BrowserStack" src="https://user-images.githubusercontent.com/4244251/184881129-e1edf4b7-3ae1-4ea8-9e6d-3595cf01609e.png" height="55px">
686
812
  </picture>
687
813
  </a>
688
- <a href="https://railsautoscale.com">
689
- <img src="https://user-images.githubusercontent.com/4244251/184881144-95c2c25c-9879-4069-864d-4e67d6ed39d2.png" alt="Rails Autoscale" height="55px">
690
- </a>
691
814
  <a href="https://www.honeybadger.io">
692
815
  <img src="https://user-images.githubusercontent.com/4244251/184881133-79ee9c3c-8165-4852-958e-31687b9536f4.png" alt="Honeybadger" height="55px">
693
816
  </a>
694
- <a href="https://reviewable.io">
695
- <img src="https://user-images.githubusercontent.com/20628911/230848305-c94510a4-82d7-468f-bf9f-eeb81d3f2ce0.png" alt="Reviewable" height="55px">
696
- </a>
697
817
 
698
818
  <br />
699
819
  <br />
data/RELEASING.md ADDED
@@ -0,0 +1,200 @@
1
+ # Release Process
2
+
3
+ This document describes how to release a new version of cypress-playwright-on-rails.
4
+
5
+ ## Prerequisites
6
+
7
+ 1. Maintainer access to the repository
8
+ 2. RubyGems account with publish permissions for `cypress-on-rails`
9
+ 3. Clean working directory on `master` branch
10
+ 4. Development dependencies installed: `bundle install`
11
+ - Includes `gem-release` for gem management (like react_on_rails)
12
+
13
+ ## Release Command
14
+
15
+ The project uses a single rake task to automate the entire release process:
16
+
17
+ ```bash
18
+ rake release[VERSION,DRY_RUN]
19
+ ```
20
+
21
+ ### Examples
22
+
23
+ ```bash
24
+ # Release version 1.19.0
25
+ rake release[1.19.0]
26
+
27
+ # Automatic patch version bump (e.g., 1.18.0 -> 1.18.1)
28
+ rake release
29
+
30
+ # Dry run to preview what would happen
31
+ rake release[1.19.0,true]
32
+ ```
33
+
34
+ ### What the Release Task Does
35
+
36
+ The `rake release` task will:
37
+
38
+ 1. Pull latest changes from master
39
+ 2. Bump the version in `lib/cypress_on_rails/version.rb`
40
+ 3. Update `Gemfile.lock` via `bundle install`
41
+ 4. Commit the version bump and Gemfile.lock changes
42
+ 5. Create a git tag (e.g., `v1.19.0`)
43
+ 6. Push the commit and tag to GitHub
44
+ 7. Build and publish the gem to RubyGems (will prompt for OTP)
45
+
46
+ ### Post-Release Steps
47
+
48
+ After publishing, complete these manual steps:
49
+
50
+ 1. **Update CHANGELOG.md**
51
+ ```bash
52
+ bundle exec rake update_changelog
53
+ git commit -a -m 'Update CHANGELOG.md'
54
+ git push
55
+ ```
56
+
57
+ 2. **Create GitHub Release**
58
+ - Go to the releases page: https://github.com/shakacode/cypress-playwright-on-rails/releases
59
+ - Click on the newly created tag
60
+ - Copy release notes from CHANGELOG.md
61
+ - Publish the release
62
+
63
+ 3. **Announce the Release** (optional)
64
+ - Post in Slack channel
65
+ - Tweet about the release
66
+ - Update forum posts if needed
67
+
68
+ ## Version Numbering
69
+
70
+ Follow [Semantic Versioning](https://semver.org/):
71
+
72
+ - **MAJOR** (X.0.0): Breaking changes
73
+ - **MINOR** (1.X.0): New features, backwards compatible
74
+ - **PATCH** (1.19.X): Bug fixes, backwards compatible
75
+
76
+ ### Examples
77
+
78
+ ```bash
79
+ # Patch release (bug fixes)
80
+ rake release[1.18.1]
81
+
82
+ # Minor release (new features)
83
+ rake release[1.19.0]
84
+
85
+ # Major release (breaking changes)
86
+ rake release[2.0.0]
87
+
88
+ # Automatic patch bump
89
+ rake release
90
+ ```
91
+
92
+ ## Pre-Release Checklist
93
+
94
+ Before running `rake release`:
95
+
96
+ - [ ] All PRs for the release are merged
97
+ - [ ] CI is passing on master
98
+ - [ ] CHANGELOG.md has [Unreleased] section with all changes
99
+ - [ ] Major changes have been tested manually
100
+ - [ ] Documentation is up to date
101
+
102
+ ## Troubleshooting
103
+
104
+ ### "Must be on master branch" error
105
+
106
+ ```bash
107
+ git checkout master
108
+ git pull --rebase
109
+ ```
110
+
111
+ ### "Working directory is not clean" error
112
+
113
+ ```bash
114
+ # Commit or stash your changes
115
+ git status
116
+ git add -A && git commit -m "Your message"
117
+ # or
118
+ git stash
119
+ ```
120
+
121
+
122
+ ### "Failed to push gem to RubyGems" error
123
+
124
+ Ensure you're authenticated with RubyGems:
125
+ ```bash
126
+ gem signin
127
+ # Enter your RubyGems credentials
128
+ ```
129
+
130
+ ### Tag already exists
131
+
132
+ If you need to re-release the same version:
133
+ ```bash
134
+ # Delete local tag
135
+ git tag -d v1.19.0
136
+
137
+ # Delete remote tag
138
+ git push origin :v1.19.0
139
+
140
+ # Reset to before the release commit
141
+ git reset --hard HEAD~1
142
+
143
+ # Try the release again
144
+ rake release[1.19.0]
145
+ ```
146
+
147
+ ## Rollback
148
+
149
+ If you need to rollback a release:
150
+
151
+ ### Yank the gem from RubyGems
152
+ ```bash
153
+ gem yank cypress-on-rails -v 1.19.0
154
+ ```
155
+
156
+ ### Delete the git tag
157
+ ```bash
158
+ git tag -d v1.19.0
159
+ git push origin :v1.19.0
160
+ ```
161
+
162
+ ### Revert the version commit
163
+ ```bash
164
+ git revert HEAD
165
+ git push origin master
166
+ ```
167
+
168
+ ## Example Release Flow
169
+
170
+ ```bash
171
+ # 1. Ensure you're on master and up to date
172
+ git checkout master
173
+ git pull --rebase
174
+
175
+ # 2. Check CI is passing
176
+ # Visit: https://github.com/shakacode/cypress-playwright-on-rails/actions
177
+
178
+ # 3. Release (will handle everything automatically)
179
+ rake release[1.19.0]
180
+ # Enter your RubyGems OTP when prompted
181
+
182
+ # 4. Update the changelog
183
+ bundle exec rake update_changelog
184
+ git commit -a -m 'Update CHANGELOG.md'
185
+ git push
186
+
187
+ # 5. Create GitHub release
188
+ open "https://github.com/shakacode/cypress-playwright-on-rails/releases"
189
+ # Click on the new tag, add release notes from CHANGELOG.md
190
+
191
+ # 6. Celebrate! 🎉
192
+ ```
193
+
194
+ ## Notes
195
+
196
+ - The release task handles all git operations (commit, tag, push) automatically
197
+ - Always ensure CI is green before releasing
198
+ - The task will fail fast if working directory is not clean
199
+ - Failed releases can be retried after fixing issues
200
+ - Use dry run mode (`rake release[VERSION,true]`) to preview changes
data/Rakefile CHANGED
@@ -1,9 +1,6 @@
1
- require 'bundler/gem_tasks'
2
-
3
-
4
1
  require 'rspec/core/rake_task'
5
2
  RSpec::Core::RakeTask.new(:spec) do |t|
6
3
  t.pattern = 'spec/cypress_on_rails/*_spec.rb'
7
4
  end
8
5
 
9
- task default: %w[spec build]
6
+ task default: :spec
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
8
8
  s.author = ["miceportal team", 'Grant Petersen-Speelman']
9
9
  s.email = ["info@miceportal.de", 'grantspeelman@gmail.com']
10
10
  s.homepage = "http://github.com/shakacode/cypress-on-rails"
11
- s.summary = "Integrates cypress with rails or rack applications"
12
- s.description = "Integrates cypress with rails or rack applications"
11
+ s.summary = "Integrates Cypress and Playwright with Rails or Rack applications"
12
+ s.description = "Integrates Cypress and Playwright with Rails or Rack applications"
13
13
  s.post_install_message = 'The CypressDev constant is being deprecated and will be completely removed and replaced with CypressOnRails.'
14
14
  s.files = `git ls-files`.split("\n")
15
15
  s.test_files = `git ls-files -- {spec}/*`.split("\n")
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.add_development_dependency 'railties', '>= 3.2'
22
22
  s.add_development_dependency 'factory_bot', '!= 6.4.5'
23
23
  s.add_development_dependency 'vcr'
24
+ s.add_development_dependency 'gem-release'
24
25
  s.metadata = {
25
26
  "bug_tracker_uri" => "https://github.com/shakacode/cypress-on-rails/issues",
26
27
  "changelog_uri" => "https://github.com/shakacode/cypress-on-rails/blob/master/CHANGELOG.md",