Skip to content

Commit 3974fc2

Browse files
justin808claude
andcommitted
Improve CONTRIBUTING.md with comprehensive generator testing documentation
- Add manual generator testing workflow with systematic approach - Document testing for both Shakapacker scenarios (pre-installed vs fresh install) - Include specific commit testing procedures for 81c66fa and bc69dcd - Add troubleshooting section for common generator testing issues - Document pre-commit requirements for linting and formatting - Provide clean baseline testing process using git tags 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent bc69dcd commit 3974fc2

File tree

1 file changed

+166
-0
lines changed

1 file changed

+166
-0
lines changed

CONTRIBUTING.md

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,112 @@ The generators are covered by generator tests using Rails's generator testing he
268268

269269
`rake run_rspec:shakapacker_examples_basic` is a great way to run tests on one generator. Once that works, you should run `rake run_rspec:shakapacker_examples`. Be aware that this will create a huge number of files under a `/gen-examples` directory. You should be sure to exclude this directory from your IDE and delete it once your testing is done.
270270

271+
#### Manual Generator Testing Workflow
272+
273+
For comprehensive testing of generator changes, use this manual testing workflow with dedicated test applications:
274+
275+
**1. Set up test application with clean baseline:**
276+
277+
```bash
278+
# Navigate to test app directory (replace with your test app)
279+
cd ~/shakacode/react-on-rails/react_on_rails-test-apps/react-on-rails-tutorial-v15
280+
281+
# Create a clean baseline tag for testing
282+
git tag generator_testing_base
283+
284+
# Clean reset to baseline state
285+
git clean -fd && git reset --hard && git clean -fd
286+
```
287+
288+
**2. Test generator commits systematically:**
289+
290+
When testing specific generator improvements or fixes, test both Shakapacker scenarios:
291+
292+
**Scenario A: No Shakapacker installed (fresh Rails app)**
293+
```bash
294+
# Reset to clean baseline before each test
295+
git clean -fd && git reset --hard generator_testing_base && git clean -fd
296+
297+
# Ensure no Shakapacker in Gemfile (remove if present)
298+
# Edit Gemfile to update gem path: gem 'react_on_rails', path: '../path/to/main/repo'
299+
bundle install
300+
301+
# Run generator - should install Shakapacker automatically
302+
rails generate react_on_rails:install
303+
304+
# Verify Shakapacker was added to Gemfile and installed correctly
305+
```
306+
307+
**Scenario B: Shakapacker already installed**
308+
```bash
309+
# Reset to clean baseline
310+
git clean -fd && git reset --hard generator_testing_base && git clean -fd
311+
312+
# Ensure Shakapacker is in Gemfile
313+
echo 'gem "shakapacker", "~> 8.0"' >> Gemfile
314+
bundle install
315+
316+
# Run Shakapacker installer first
317+
bundle exec rails shakapacker:install
318+
319+
# Edit Gemfile to update gem path: gem 'react_on_rails', path: '../path/to/main/repo'
320+
bundle install
321+
322+
# Run generator - should detect existing Shakapacker
323+
rails generate react_on_rails:install
324+
325+
# Verify generator adapts to existing Shakapacker setup
326+
```
327+
328+
**3. Document testing results:**
329+
330+
For each commit tested, document:
331+
- Generator execution success/failure for both scenarios
332+
- Shakapacker installation/detection behavior
333+
- Component rendering in browser
334+
- Console output and warnings
335+
- File generation differences between scenarios
336+
- Specific issues found
337+
338+
This systematic approach ensures generator changes work correctly whether Shakapacker is pre-installed or needs to be installed by the generator.
339+
340+
#### Testing Specific Generator Commits
341+
342+
When testing specific commits that fix generator issues, follow this process:
343+
344+
**Example: Testing commits 81c66fa and bc69dcd0**
345+
346+
1. **Commit 81c66fa**: "Now automatically creates packs" - Test pack generation functionality
347+
2. **Commit bc69dcd0**: "Fix React on Rails v15 generator and restore colorized output" - Test generator fixes and output formatting
348+
349+
**Testing workflow for each commit:**
350+
351+
```bash
352+
# In main react_on_rails repository
353+
cd ~/shakacode/react-on-rails/react_on_rails
354+
git checkout <commit-hash> # e.g., 81c66fa or bc69dcd0
355+
356+
# In test application
357+
cd ~/shakacode/react-on-rails/react_on_rails-test-apps/react-on-rails-tutorial-v15
358+
359+
# Reset to clean baseline
360+
git clean -fd && git reset --hard generator_testing_base && git clean -fd
361+
362+
# Update Gemfile to point to current commit
363+
# Edit: gem 'react_on_rails', path: '../../../react_on_rails'
364+
bundle install
365+
366+
# Test both Shakapacker scenarios (A and B above)
367+
# Document results for this specific commit
368+
```
369+
370+
**Expected outcomes to verify:**
371+
- Generator completes without errors
372+
- Shakapacker integration works correctly
373+
- React components render and are interactive
374+
- Development server starts successfully with `bin/dev`
375+
- Console output shows expected messages and minimal warnings
376+
271377
#### Testing Generator with Yalc for React Component Functionality
272378

273379
When testing the install generator with new Rails apps, you need to use **yalc** for the JavaScript package to ensure React components work correctly. The Ruby gem path reference is insufficient for client-side rendering.
@@ -312,6 +418,66 @@ bin/dev
312418

313419
**Note**: Resource preload warnings in development modes are normal and can be ignored. They occur because Shakapacker generates preload tags but scripts load asynchronously. Production mode eliminates most of these warnings.
314420

421+
#### Generator Testing Troubleshooting
422+
423+
**Common Issues and Solutions:**
424+
425+
1. **React components not rendering (empty divs)**
426+
- **Cause**: Missing yalc setup for JavaScript package
427+
- **Solution**: Follow yalc setup steps above after running generator
428+
429+
2. **Generator fails with Shakapacker errors**
430+
- **Cause**: Conflicting Shakapacker versions or incomplete installation
431+
- **Solution**: Clean reset and ensure consistent Shakapacker version across tests
432+
433+
3. **Babel configuration conflicts during yalc development**
434+
- **Cause**: Both `babel.config.js` and `package.json` "babel" section defining presets
435+
- **Solution**: Remove "babel" section from `package.json`, keep only `babel.config.js`
436+
437+
4. **"Package.json not found" errors**
438+
- **Cause**: Generator trying to access non-existent package.json files
439+
- **Solution**: Test with commits that fix this specific issue (e.g., bc69dcd0)
440+
441+
5. **Port conflicts during testing**
442+
- **Cause**: Multiple development servers running
443+
- **Solution**: Run `bin/dev kill` before starting new test servers
444+
445+
**Testing Best Practices:**
446+
- Always use the double clean command: `git clean -fd && git reset --hard && git clean -fd`
447+
- Test both Shakapacker scenarios for comprehensive coverage
448+
- Document exact error messages and steps to reproduce
449+
- Verify React component interactivity, not just rendering
450+
- Test all development modes: `bin/dev`, `bin/dev static`, `bin/dev prod`
451+
452+
## Pre-Commit Requirements
453+
454+
**CRITICAL**: Before committing any changes, always run the following commands to ensure code quality:
455+
456+
```bash
457+
# Navigate to the main react_on_rails directory
458+
cd react_on_rails/
459+
460+
# Run Prettier for JavaScript/TypeScript formatting
461+
yarn run format
462+
463+
# Run ESLint for JavaScript/TypeScript linting
464+
yarn run lint
465+
466+
# Run RuboCop for Ruby linting and formatting
467+
rake lint:rubocop
468+
469+
# Or run all linters together
470+
rake lint
471+
```
472+
473+
**Automated checks:**
474+
- Format all JavaScript/TypeScript files with Prettier
475+
- Check and fix linting issues with ESLint
476+
- Check and fix Ruby style issues with RuboCop
477+
- Ensure all tests pass before pushing
478+
479+
**Tip**: Set up your IDE to run these automatically on save to catch issues early.
480+
315481
### Linting
316482

317483
All linting is performed from the docker container for CI. You will need docker and docker-compose installed locally to lint code changes via the lint container. You can lint locally by running `npm run lint && npm run flow`

0 commit comments

Comments
 (0)