You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add cypress-rails compatible rake tasks and server lifecycle hooks
This enhancement brings cypress-rails functionality to cypress-playwright-on-rails:
- Added rake tasks for cypress:open, cypress:run, playwright:open, playwright:run
- Implemented automatic Rails server management with dynamic port selection
- Added server lifecycle hooks (before_server_start, after_server_start, etc.)
- Added transactional test mode for automatic database rollback
- Added state reset middleware for /cypress_rails_reset_state endpoint
- Support for CYPRESS_RAILS_HOST and CYPRESS_RAILS_PORT environment variables
These changes make cypress-playwright-on-rails a more complete replacement for
cypress-rails, providing the same developer-friendly test execution experience
while maintaining all the existing cypress-on-rails functionality.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+17Lines changed: 17 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,23 @@ This project adheres to [Semantic Versioning](https://semver.org/).
5
5
6
6
---
7
7
8
+
## [Unreleased]
9
+
10
+
### Added
11
+
***Rake tasks for test execution**: Added `cypress:open` and `cypress:run` rake tasks for seamless test execution, similar to cypress-rails functionality. Also added `playwright:open` and `playwright:run` tasks.
12
+
***Server lifecycle hooks**: Added configuration hooks for test server management:
13
+
-`before_server_start`: Run code before Rails server starts
14
+
-`after_server_start`: Run code after Rails server is ready
15
+
-`after_transaction_start`: Run code after database transaction begins
16
+
-`after_state_reset`: Run code after application state is reset
17
+
-`before_server_stop`: Run code before Rails server stops
18
+
***State reset endpoint**: Added `/cypress_rails_reset_state` and `/__cypress__/reset_state` endpoints for compatibility with cypress-rails
19
+
***Transactional test mode**: Added support for automatic database transaction rollback between tests
20
+
***Environment configuration**: Support for `CYPRESS_RAILS_HOST` and `CYPRESS_RAILS_PORT` environment variables
21
+
***Automatic server management**: Test server automatically starts and stops with test execution
Copy file name to clipboardExpand all lines: README.md
+61Lines changed: 61 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -143,6 +143,29 @@ Please use with extra caution if starting your local server on 0.0.0.0 or runnin
143
143
144
144
Getting started on your local environment
145
145
146
+
### Using Rake Tasks (Recommended)
147
+
148
+
The easiest way to run tests is using the provided rake tasks, which automatically manage the Rails server:
149
+
150
+
```shell
151
+
# For Cypress
152
+
bin/rails cypress:open # Opens Cypress test runner UI
153
+
bin/rails cypress:run # Runs Cypress tests in headless mode
154
+
155
+
# For Playwright
156
+
bin/rails playwright:open # Opens Playwright test runner UI
157
+
bin/rails playwright:run # Runs Playwright tests in headless mode
158
+
```
159
+
160
+
These tasks will:
161
+
- Start the Rails test server automatically
162
+
- Execute your tests
163
+
- Stop the server when done
164
+
165
+
### Manual Server Management
166
+
167
+
You can also manage the server manually:
168
+
146
169
```shell
147
170
# start rails
148
171
CYPRESS=1 bin/rails server -p 5017
@@ -506,6 +529,44 @@ Consider VCR configuration in `cypress_helper.rb` to ignore hosts.
506
529
All cassettes will be recorded and saved automatically, using the pattern `<vcs_cassettes_path>/graphql/<operation_name>`
507
530
508
531
532
+
## Server Hooks Configuration
533
+
534
+
When using the rake tasks (`cypress:open`, `cypress:run`, `playwright:open`, `playwright:run`), you can configure lifecycle hooks to customize test server behavior:
535
+
536
+
```ruby
537
+
CypressOnRails.configure do |c|
538
+
# Run code before Rails server starts
539
+
c.before_server_start =-> {
540
+
puts"Preparing test environment..."
541
+
}
542
+
543
+
# Run code after Rails server is ready
544
+
c.after_server_start =-> {
545
+
puts"Server is ready for testing!"
546
+
}
547
+
548
+
# Run code after database transaction begins (transactional mode only)
549
+
c.after_transaction_start =-> {
550
+
# Load seed data that should be rolled back after tests
551
+
}
552
+
553
+
# Run code after application state is reset
554
+
c.after_state_reset =-> {
555
+
Rails.cache.clear
556
+
}
557
+
558
+
# Run code before Rails server stops
559
+
c.before_server_stop =-> {
560
+
puts"Cleaning up test environment..."
561
+
}
562
+
563
+
# Configure server settings
564
+
c.server_host ='localhost'# or use ENV['CYPRESS_RAILS_HOST']
565
+
c.server_port =3001# or use ENV['CYPRESS_RAILS_PORT']
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.
0 commit comments