Commit d26d966
authored
Add cypress-rails compatible rake tasks and server lifecycle hooks (#179)
This PR adds comprehensive test automation support with automatic server
lifecycle management, making cypress-on-rails a drop-in replacement for
the cypress-rails gem while extending support to Playwright.
Key Improvements:
* Rake Tasks for Test Execution
- Added cypress:open, cypress:run, playwright:open, playwright:run
- Automatic Rails server startup/shutdown during test execution
- Dynamic port detection to avoid conflicts
- Support for CYPRESS_RAILS_HOST and CYPRESS_RAILS_PORT environment variables
* Server Lifecycle Hooks
- before_server_start: Execute code before Rails server starts
- after_server_start: Execute code when server is ready
- after_transaction_start: Execute code after database transaction begins
- after_state_reset: Execute code after state cleanup (runs AFTER cleanup)
- before_server_stop: Execute code before server shutdown
* State Reset Functionality
- Added /cypress_rails_reset_state endpoint for cypress-rails compatibility
- Added /__cypress__/reset_state endpoint for existing users
- Automatic database cleanup with referential integrity support
- Uses disable_referential_integrity when available
- Proper table name quoting with quote_table_name
- Rails cache clearing and dependency reset
* Transactional Test Mode
- Optional automatic database transaction rollback
- Configurable via transactional_server option
- Faster test execution for compatible test suites
* Security Improvements
- Refactored shell command execution to prevent injection attacks
- Commands passed as argument arrays instead of string interpolation
- Uses spawn(*args) and system(*args) for safe execution
- Added missing require 'fileutils' dependency
* Configuration & Documentation
- New configuration initializer template with all hook examples
- Comprehensive migration guide from manual server management
- Migration guide from cypress-rails gem
- Updated README with rake task usage examples
Breaking Changes:
NONE - This is purely additive functionality. All existing middleware-based
usage continues to work unchanged.
Impact on Users:
New Installations:
- Can immediately use rake tasks for automated test execution
- No need to manually manage Rails test server
- Simplified setup with single-command test execution
Existing Installations:
- No changes required - existing setup continues to work
- Can opt-in to rake tasks for improved workflow
- Can gradually adopt lifecycle hooks for custom test setup
- State reset endpoint provides backward compatibility
Migration from cypress-rails:
- Drop-in replacement with same rake task names
- Compatible state reset endpoint
- Adds Playwright support not available in cypress-rails
- More flexible with configurable hooks and options
Technical Notes:
The implementation uses TCPServer for port detection and spawns the Rails
server as a subprocess. Server readiness is verified by attempting TCP
connections. State reset uses DatabaseCleaner when available, falling back
to manual table truncation with proper referential integrity handling.
All shell commands use argument arrays to prevent command injection
vulnerabilities. Table names are properly quoted using ActiveRecord's
quote_table_name method.1 parent d50de89 commit d26d966
File tree
8 files changed
+467
-0
lines changed- lib
- cypress_on_rails
- generators/cypress_on_rails/templates/config/initializers
- tasks
8 files changed
+467
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
8 | 83 | | |
9 | 84 | | |
10 | 85 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
146 | 169 | | |
147 | 170 | | |
148 | 171 | | |
| |||
506 | 529 | | |
507 | 530 | | |
508 | 531 | | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
509 | 570 | | |
510 | 571 | | |
511 | 572 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
13 | 25 | | |
14 | 26 | | |
15 | 27 | | |
| |||
38 | 50 | | |
39 | 51 | | |
40 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
41 | 65 | | |
42 | 66 | | |
43 | 67 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
6 | 9 | | |
7 | 10 | | |
8 | 11 | | |
9 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
10 | 17 | | |
11 | 18 | | |
12 | 19 | | |
| |||
0 commit comments