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 brittle positional assertions in create-app tests (#2923)
## Summary
- Replace `toHaveBeenNthCalledWith` ordinals with `toHaveBeenCalledWith`
(semantic argument matching)
- Replace `mockImplementationOnce` chains with command-matching
`mockImplementation`
- Replace `toHaveBeenCalledTimes` with `stepCallSummaries()` — a
filtered sequence assertion on non-git commands that verifies ordering,
count, and argument correctness in one check
- Add `stepCallSummaries()` helper (mirrors the existing
`gitCommitSubjects()` pattern for commit ordering)
## Context
PR #2849 added educational git commits to the
`create-react-on-rails-app` scaffold flow, interleaving `git add` + `git
commit` calls between each real step. The existing tests were updated to
use new ordinal positions (1→4→7→10) and counts (9, 12), but a reviewer
flagged this as brittle and it was deferred as item 1 of #2888.
The brittleness was verified: adding a single `execLiveArgs` call to
`create-app.ts` broke 13 of 78 tests — 7 from shifted ordinals, 5 from
`mockImplementationOnce` chain off-by-one, and 1 from a count mismatch.
## Approach
The test file already had `gitCommitSubjects().toEqual([...])` which
verifies commit ordering through `mock.calls` filtering — the [standard
Jest community pattern](jestjs/jest#4402) for
asserting call order on a subset of calls. This PR extends that pattern
to step commands via `stepCallSummaries()`, which filters out
educational git operations and asserts on the exact sequence of real
steps:
```typescript
expect(stepCallSummaries()).toEqual([
'rails new',
'bundle add react_on_rails',
'bundle add react_on_rails_pro',
'bundle generate',
]);
```
This provides ordering verification (via `toEqual` on an ordered array),
count verification (exact array length), and resilience to
educational-commit interleaving — without the positional coupling of the
original ordinal assertions.
Partially addresses #2888.
## Test plan
- [x] All 78 existing tests pass
- [x] Adding an extra `git` command to `create-app.ts` → 0 test failures
(correctly tolerant of git interleaving)
- [x] Adding an extra non-git command to `create-app.ts` →
`stepCallSummaries()` catches the sequence mismatch
- [x] Inserting a command at the wrong position → `stepCallSummaries()`
catches the ordering violation
- [x] Pre-commit hooks pass (prettier, eslint, trailing-newlines)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Tests**
* Improved test reliability and maintainability for the app-creation
flow by adding helpers to summarize and verify ordered setup steps,
shifting assertions from strict call-count/order to presence and
expected step sequences, and consolidating failure-path mocks for
clearer, more robust error simulations.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
0 commit comments