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
Fix generator folder structure for install (#201) (#203)
Why
Generator placed e2e_helper.rb in framework subdirectory, breaking
middleware file discovery and Cypress config location.
Summary
Moved e2e_helper.rb and app_commands to install_folder root instead
of framework subdirectory. Added 20 tests, migration guide, and
backward-compatible fallback loading.
Key improvements
- Backward compatible fallback loads from old location with warning
- Comprehensive test coverage including negative assertions
- CHANGELOG migration guide with three upgrade paths
Impact
- Existing: Files must migrate or fallback loads with warning
- New: Correct structure created, both frameworks share helpers
Risks
- Breaking: Old structure deprecated, migration required for clean setup
Copy file name to clipboardExpand all lines: CHANGELOG.md
+77Lines changed: 77 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,82 @@ This project adheres to [Semantic Versioning](https://semver.org/).
7
7
8
8
## [Unreleased]
9
9
10
+
### Fixed
11
+
***BREAKING: Generator folder structure**: Fixed install generator to create `e2e_helper.rb` and `app_commands/` at the install folder root (e.g., `e2e/`) instead of inside the framework subdirectory (e.g., `e2e/cypress/`). This ensures compatibility between Cypress/Playwright config file location and middleware expectations. [#201]
12
+
13
+
### Migration Guide for Folder Structure Change
14
+
15
+
#### Breaking Change Notice
16
+
If you previously ran the install generator (versions prior to 1.20.0), the file structure created was incorrect. The generator placed helper and command files in the framework subdirectory when they should be at the install folder root.
17
+
18
+
**Old (Incorrect) Structure:**
19
+
```
20
+
e2e/
21
+
cypress.config.js
22
+
cypress/
23
+
e2e_helper.rb ← Wrong location
24
+
app_commands/ ← Wrong location
25
+
support/
26
+
e2e/
27
+
```
28
+
29
+
**New (Correct) Structure:**
30
+
```
31
+
e2e/
32
+
cypress.config.js
33
+
e2e_helper.rb ← Correct location
34
+
app_commands/ ← Correct location
35
+
fixtures/
36
+
vcr_cassettes/ ← VCR cassettes also at root
37
+
cypress/
38
+
support/
39
+
e2e/
40
+
```
41
+
42
+
#### How to Migrate
43
+
44
+
**Option 1: Fresh Installation (Recommended for new projects)**
45
+
```bash
46
+
# Remove old structure
47
+
rm -rf e2e/
48
+
49
+
# Re-run generator
50
+
bin/rails g cypress_on_rails:install --force
51
+
```
52
+
53
+
**Option 2: Manual Migration (For existing projects with custom code)**
54
+
```bash
55
+
# Move files to correct location
56
+
mv e2e/cypress/e2e_helper.rb e2e/
57
+
mv e2e/cypress/app_commands e2e/
58
+
59
+
# Update VCR cassettes path if using VCR
60
+
mv e2e/cypress/fixtures e2e/
61
+
62
+
# Verify your initializer has the correct path
63
+
# Should be: c.install_folder = File.expand_path("#{__dir__}/../../e2e")
However, this means Cypress may have issues finding config files. We recommend migrating to the correct structure.
74
+
75
+
#### Why This Change?
76
+
The middleware expects to find `e2e_helper.rb` at `#{install_folder}/e2e_helper.rb` and commands at `#{install_folder}/app_commands/`. Meanwhile, Cypress/Playwright expect config files at the install_folder root when using `--project` flag. The previous structure created a conflict where these requirements couldn't both be satisfied.
77
+
78
+
#### Testing Your Migration
79
+
After migrating, verify:
80
+
1. Run `bin/rails cypress:open` or `bin/rails playwright:open` - should open successfully
81
+
2. Run a test that uses app commands - should execute without "file not found" errors
82
+
3. Check that VCR cassettes (if used) are being created/loaded correctly
83
+
84
+
---
85
+
10
86
## [1.19.0] - 2025-10-01
11
87
12
88
### Added
@@ -436,6 +512,7 @@ If migrating from the `cypress-rails` gem:
Copy file name to clipboardExpand all lines: README.md
+47-13Lines changed: 47 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -134,17 +134,52 @@ bin/rails g cypress_on_rails:install --install_with=skip
134
134
bin/rails g cypress_on_rails:install --install_with=skip
135
135
```
136
136
137
-
The generator modifies/adds the following files/directory in your application:
138
-
*`config/initializers/cypress_on_rails.rb` used to configure Cypress on Rails
139
-
*`e2e/cypress/integration/` contains your cypress tests
140
-
*`e2e/cypress/support/on-rails.js` contains Cypress on Rails support code
141
-
*`e2e/cypress/e2e_helper.rb` contains helper code to require libraries like factory_bot
142
-
*`e2e/cypress/app_commands/` contains your scenario definitions
143
-
*`e2e/playwright/e2e/` contains your playwright tests
144
-
*`e2e/playwright/support/on-rails.js` contains Playwright on Rails support code
145
-
146
-
If you are not using `database_cleaner` look at `e2e/cypress/app_commands/clean.rb`.
147
-
If you are not using `factory_bot` look at `e2e/cypress/app_commands/factory_bot.rb`.
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.
180
+
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`.
148
183
149
184
Now you can create scenarios and commands that are plain Ruby files that get loaded through middleware, the ruby sky is your limit.
150
185
@@ -448,8 +483,7 @@ Add your VCR configuration to your `config/cypress_on_rails.rb`
448
483
c.vcr_options = {
449
484
hook_into::webmock,
450
485
default_cassette_options: { record::once },
451
-
# It's possible to override cassette_library_dir using install_folder
0 commit comments