|
| 1 | +# Recreating Example Apps |
| 2 | + |
| 3 | +When an example needs to be refreshed against the latest framework version, follow this workflow: scaffold a fresh app from the official template, then restore the Reassure setup and perf tests from the existing code. |
| 4 | + |
| 5 | +## General Workflow |
| 6 | + |
| 7 | +1. **Capture what must be restored** — before removing anything, note the files that are not generated by the scaffold tool: `src/*.perf.tsx`, `jest-setup.js` / `jest.setup.ts`, `jest.config.*`, `babel.config.*`, `reassure-tests.sh`, `dangerfile.js`, `README.md`. |
| 8 | +2. **Remove the old example** — delete the example directory (e.g. `examples/web-vite`). |
| 9 | +3. **Scaffold a fresh app** — run the official getting-started command for that framework (see per-example commands below). Use the same template flags as the original. |
| 10 | +4. **Rename / move into place** — the scaffold tool creates a subdirectory; move it to `examples/<name>` and ensure `package.json` `"name"` matches the original. |
| 11 | +5. **Restore Reassure setup** — follow the setup steps in that example's `README.md`. See the per-example section below for specifics. |
| 12 | +6. **Restore perf tests** — copy `src/*.perf.tsx` files back. Adjust imports if the scaffold changed any paths. |
| 13 | +7. **Restore `README.md`** — replace the scaffold-generated README with the reassure-setup README that was there before (or update it to match the new template version). |
| 14 | +8. **Validate** — from inside the example directory run `yarn install && yarn test && yarn perf-test && yarn typecheck`. |
| 15 | + |
| 16 | +Always use `yarn`, not `npm`, for every install and script invocation. |
| 17 | + |
| 18 | +--- |
| 19 | + |
| 20 | +## Per-Example Details |
| 21 | + |
| 22 | +### `web-vite` — React + TypeScript + Vite |
| 23 | + |
| 24 | +**Scaffold command:** |
| 25 | +```sh |
| 26 | +yarn create vite web-vite --template react-ts |
| 27 | +``` |
| 28 | + |
| 29 | +**Reassure setup** (after scaffolding): |
| 30 | +1. Install dev dependencies: `jest`, `jest-environment-jsdom`, `@types/jest`, `@testing-library/react`, `@testing-library/dom`, `@babel/preset-env`, `@babel/preset-react`, `@babel/preset-typescript`, `@types/babel__preset-env`, `reassure`, `danger`. |
| 31 | +2. Restore `jest.config.cjs` and `babel.config.cjs` from the previous version (the scaffold does not generate these). |
| 32 | +3. Restore `jest-setup.js` — it calls `configure({ testingLibrary: 'react' })` from `reassure`. |
| 33 | +4. Run `yarn reassure init` — this generates `reassure-tests.sh`, `dangerfile.js`, and adds `.reassure` to `.gitignore`. |
| 34 | +5. Add `"test": "jest"`, `"perf-test": "reassure"`, and `"typecheck": "tsc --noEmit"` to `package.json` `"scripts"`. |
| 35 | + |
| 36 | +**Key config files to restore:** `jest.config.cjs`, `babel.config.cjs`, `jest-setup.js`. |
| 37 | + |
| 38 | +--- |
| 39 | + |
| 40 | +### `web-nextjs` — Next.js |
| 41 | + |
| 42 | +**Scaffold command:** |
| 43 | +```sh |
| 44 | +yarn create next-app web-nextjs --typescript --eslint --app --src-dir --import-alias "@/*" |
| 45 | +``` |
| 46 | +Accept defaults for any prompts not listed above. |
| 47 | + |
| 48 | +**Reassure setup** (after scaffolding): |
| 49 | +1. Install dev dependencies: `jest`, `jest-environment-jsdom`, `@types/jest`, `@testing-library/react`, `@testing-library/dom`, `@testing-library/jest-dom`, `ts-node`, `reassure`, `danger`. |
| 50 | +2. Restore `jest.config.ts` from the previous version. |
| 51 | +3. Restore `jest.setup.ts` — it calls `configure({ testingLibrary: 'react' })` from `reassure`. |
| 52 | +4. Run `yarn reassure init` — generates `reassure-tests.sh`, `dangerfile.js`, `.gitignore` entry. |
| 53 | +5. Add `"test": "jest"` and `"perf-test": "reassure"` to `package.json` `"scripts"`. |
| 54 | + |
| 55 | +**Key config files to restore:** `jest.config.ts`, `jest.setup.ts`. |
| 56 | + |
| 57 | +--- |
| 58 | + |
| 59 | +### `native-expo` — Expo React Native |
| 60 | + |
| 61 | +**Scaffold command:** |
| 62 | +```sh |
| 63 | +npx create-expo-app native-expo --template blank-typescript |
| 64 | +``` |
| 65 | + |
| 66 | +**Reassure setup** (after scaffolding): |
| 67 | +1. Install dev dependencies: `@testing-library/react-native`, `@types/jest`, `reassure`, `danger`. (Expo templates already include Jest and a basic preset.) |
| 68 | +2. Restore `jest.config.js` from the previous version — it sets `preset: 'react-native'` and points to the setup file. |
| 69 | +3. Restore `jest-setup.js` — it calls `configure({ testingLibrary: 'react-native' })` from `reassure`. |
| 70 | +4. Run `yarn reassure init` — generates `reassure-tests.sh`, `dangerfile.js`, `.gitignore` entry. |
| 71 | +5. Add `"test": "jest"`, `"perf-test": "reassure"`, and `"typecheck": "tsc --noEmit"` to `package.json` `"scripts"` if missing. |
| 72 | + |
| 73 | +**Key config files to restore:** `jest.config.js`, `jest-setup.js`. |
| 74 | + |
| 75 | +--- |
| 76 | + |
| 77 | +### `native-cli` — React Native CLI |
| 78 | + |
| 79 | +**Scaffold command:** |
| 80 | +```sh |
| 81 | +npx @react-native-community/cli init NativeCli --template react-native-template-typescript |
| 82 | +``` |
| 83 | +Then rename the directory to `native-cli` and set `"name"` in `package.json` to `reassure-native-example` (matching the original). |
| 84 | + |
| 85 | +**Reassure setup** (after scaffolding): |
| 86 | +1. Install dev dependencies: `@testing-library/react-native`, `@types/jest`, `reassure`, `danger`. (The CLI template already ships Jest via `react-native` preset.) |
| 87 | +2. Replace the generated `jest.config.js` with the restored version — it sets `preset: 'react-native'` and points to the setup file. |
| 88 | +3. Restore `jest-setup.js` — it calls `configure({ testingLibrary: 'react-native' })` from `reassure`. |
| 89 | +4. Run `yarn reassure init` — generates `reassure-tests.sh`, `dangerfile.js`, `.gitignore` entry. |
| 90 | +5. Add `"perf-test": "reassure"` and `"typecheck": "tsc --noEmit"` to `package.json` `"scripts"` if missing. |
| 91 | + |
| 92 | +**Key config files to restore:** `jest.config.js`, `jest-setup.js`. |
| 93 | + |
| 94 | +--- |
| 95 | + |
| 96 | +## Perf Tests |
| 97 | + |
| 98 | +All examples contain perf tests under `src/`: |
| 99 | + |
| 100 | +- `TestList.perf.tsx` — measures list rendering performance. |
| 101 | +- `AsyncComponent.perf.tsx` — measures async component rendering performance. |
| 102 | + |
| 103 | +Copy these files back after scaffolding. Check imports against the new scaffold's file layout and adjust if needed. Run `yarn perf-test` to confirm they execute without errors. |
| 104 | + |
| 105 | +## Avoiding Image Churn |
| 106 | + |
| 107 | +Scaffold tools regenerate image assets from their own templates on every run. These binary files often differ byte-for-byte from the ones already in the repo even when visually identical, producing noisy, meaningless diffs in git. |
| 108 | + |
| 109 | +**Rule: prefer the existing committed images over freshly generated ones.** |
| 110 | + |
| 111 | +After scaffolding, restore the original images by copying them from git before staging anything: |
| 112 | + |
| 113 | +```sh |
| 114 | +git checkout HEAD -- <path-to-image-or-directory> |
| 115 | +``` |
| 116 | + |
| 117 | +Locations to restore per example: |
| 118 | + |
| 119 | +| Example | Images to restore | |
| 120 | +|---------|-------------------| |
| 121 | +| `native-cli` | `android/app/src/main/res/mipmap-*/ic_launcher.png` and `ic_launcher_round.png` (10 files) | |
| 122 | +| `native-expo` | `assets/adaptive-icon.png`, `assets/icon.png`, `assets/splash-icon.png`, `assets/favicon.png` | |
| 123 | +| `web-nextjs` | `public/*.svg`, `src/app/favicon.ico` | |
| 124 | +| `web-vite` | `public/vite.svg`, `src/assets/react.svg` | |
| 125 | + |
| 126 | +Only commit a regenerated image if the asset itself genuinely changed (e.g. the framework updated its default branding). In that case, note it explicitly in the commit message. |
| 127 | + |
| 128 | +--- |
| 129 | + |
| 130 | +## Files Never Generated by Scaffold Tools |
| 131 | + |
| 132 | +These must always be restored manually: |
| 133 | + |
| 134 | +| File | Purpose | |
| 135 | +|------|---------| |
| 136 | +| `src/*.perf.tsx` | Reassure performance tests | |
| 137 | +| `jest-setup.js` / `jest.setup.ts` | Jest setup with `configure()` call | |
| 138 | +| `jest.config.*` | Jest configuration (env, preset, setup file) | |
| 139 | +| `babel.config.*` | Babel presets for Jest (web examples only) | |
| 140 | +| `reassure-tests.sh` | CI script for baseline/branch comparison | |
| 141 | +| `dangerfile.js` | Danger config for PR reporting | |
| 142 | +| `README.md` | Reassure setup documentation | |
0 commit comments