|
| 1 | +# Local E2E Testing and Build Simulation |
| 2 | + |
| 3 | +This guide explains how to run e2e test steps and build jobs locally to debug failures before pushing to CI. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +E2E tests run in AWS CodeBuild with specific build steps defined in `codebuild_specs/*.yml`. Each build spec calls functions from `shared-scripts.sh`. You can simulate these steps locally to debug issues. |
| 8 | + |
| 9 | +## Prerequisites |
| 10 | + |
| 11 | +### Authentication |
| 12 | + |
| 13 | +Most e2e operations require AWS credentials. The repository uses `ada` (Amazon's credential management tool) for authentication, which is called automatically by the scripts. |
| 14 | + |
| 15 | +**Setup:** |
| 16 | + |
| 17 | +1. Ensure you have `ada` and `mwinit` installed |
| 18 | +2. Create `scripts/.env` file with account details: |
| 19 | + ```bash |
| 20 | + # scripts/.env |
| 21 | + E2E_ACCOUNT_PROD=<account-id> |
| 22 | + E2E_ACCOUNT_BETA=<account-id> |
| 23 | + ``` |
| 24 | +3. If you see authentication errors, run `mwinit` in your terminal |
| 25 | + |
| 26 | +**Note:** The scripts automatically call `ada` for credential refresh. You don't need to run `ada` commands manually. |
| 27 | + |
| 28 | +## Common Build Steps |
| 29 | + |
| 30 | +### 1. Unit Tests (`test` build) |
| 31 | + |
| 32 | +**What it does:** Runs all unit tests with coverage in CI mode |
| 33 | + |
| 34 | +**Command:** |
| 35 | + |
| 36 | +```bash |
| 37 | +yarn test-ci |
| 38 | +``` |
| 39 | + |
| 40 | +**Equivalent to:** |
| 41 | + |
| 42 | +```bash |
| 43 | +lerna run test --concurrency 4 -- --ci -i |
| 44 | +``` |
| 45 | + |
| 46 | +**Common issues:** |
| 47 | + |
| 48 | +- Coverage threshold failures: Check `jest.config.js` in the failing package |
| 49 | +- Pre-existing coverage issues may not be related to your changes |
| 50 | +- To verify if an issue is pre-existing, test on the base branch |
| 51 | + |
| 52 | +### 2. Linting (`lint` build) |
| 53 | + |
| 54 | +**What it does:** Checks code style and linting rules |
| 55 | + |
| 56 | +**Command:** |
| 57 | + |
| 58 | +```bash |
| 59 | +yarn lint-check |
| 60 | +``` |
| 61 | + |
| 62 | +**Common issues:** |
| 63 | + |
| 64 | +- Use `yarn lint-fix` to auto-fix some issues |
| 65 | +- Some lint errors require manual fixes |
| 66 | +- Check `.eslintrc.js` for linting rules |
| 67 | + |
| 68 | +### 3. Local Registry Publish (`publish_to_local_registry` build) |
| 69 | + |
| 70 | +**What it does:** Publishes packages to a local Verdaccio registry for e2e testing |
| 71 | + |
| 72 | +**Command:** |
| 73 | + |
| 74 | +```bash |
| 75 | +# Start Verdaccio (in separate terminal) |
| 76 | +yarn verdaccio-start |
| 77 | + |
| 78 | +# Publish packages |
| 79 | +yarn publish-to-verdaccio |
| 80 | + |
| 81 | +# Stop Verdaccio when done |
| 82 | +yarn verdaccio-stop |
| 83 | +``` |
| 84 | + |
| 85 | +**Common issues:** |
| 86 | + |
| 87 | +- Requires Verdaccio running locally |
| 88 | +- May fail if packages have version conflicts |
| 89 | +- Check `lerna.json` for version configuration |
| 90 | + |
| 91 | +### 4. Windows Build (`build_windows` build) |
| 92 | + |
| 93 | +**What it does:** Builds all packages on Windows with Node.js 22 or later |
| 94 | + |
| 95 | +**Command (on Windows):** |
| 96 | + |
| 97 | +```powershell |
| 98 | +yarn production-build |
| 99 | +yarn build-tests |
| 100 | +``` |
| 101 | + |
| 102 | +**Command (on macOS/Linux):** |
| 103 | +Cannot be fully simulated on non-Windows systems. However, you can: |
| 104 | + |
| 105 | +```bash |
| 106 | +yarn production-build |
| 107 | +yarn build-tests |
| 108 | +``` |
| 109 | + |
| 110 | +**Common issues:** |
| 111 | + |
| 112 | +- Path separator differences (Windows uses `\`, Unix uses `/`) |
| 113 | +- Line ending differences (CRLF vs LF) |
| 114 | +- Case-sensitive filesystem differences |
| 115 | +- Windows-specific Node.js modules |
| 116 | + |
| 117 | +### 5. Linux Build (`build_linux` build) |
| 118 | + |
| 119 | +**What it does:** Builds all packages on Linux |
| 120 | + |
| 121 | +**Command:** |
| 122 | + |
| 123 | +```bash |
| 124 | +yarn production-build |
| 125 | +yarn build-tests |
| 126 | +``` |
| 127 | + |
| 128 | +**Common issues:** |
| 129 | + |
| 130 | +- Build errors usually indicate TypeScript or dependency issues |
| 131 | +- Check for missing dependencies in package.json files |
| 132 | + |
| 133 | +## Debugging E2E Failures |
| 134 | + |
| 135 | +### Step 1: Identify the Failing Build |
| 136 | + |
| 137 | +```bash |
| 138 | +yarn e2e-failed <batch-id> |
| 139 | +``` |
| 140 | + |
| 141 | +This shows which specific builds failed. |
| 142 | + |
| 143 | +### Step 2: Get Build Logs |
| 144 | + |
| 145 | +```bash |
| 146 | +yarn e2e-logs <build-id> |
| 147 | +``` |
| 148 | + |
| 149 | +This downloads and displays the full build log. |
| 150 | + |
| 151 | +### Step 3: Simulate Locally |
| 152 | + |
| 153 | +Run the equivalent local command (see sections above) to reproduce the issue. |
| 154 | + |
| 155 | +### Step 4: Check for Pre-existing Issues |
| 156 | + |
| 157 | +Before fixing, verify the issue exists on the base branch: |
| 158 | + |
| 159 | +```bash |
| 160 | +# Stash your changes |
| 161 | +git stash |
| 162 | + |
| 163 | +# Checkout base branch |
| 164 | +git checkout dev |
| 165 | + |
| 166 | +# Run the failing command |
| 167 | +yarn <command> |
| 168 | + |
| 169 | +# Restore your changes |
| 170 | +git checkout <your-branch> |
| 171 | +git stash pop |
| 172 | +``` |
| 173 | + |
| 174 | +## E2E Test Workflow |
| 175 | + |
| 176 | +### Full E2E Test Suite |
| 177 | + |
| 178 | +```bash |
| 179 | +# 1. Commit and push all changes |
| 180 | +git push |
| 181 | + |
| 182 | +# 2. Trigger e2e suite |
| 183 | +yarn cloud-e2e |
| 184 | + |
| 185 | +# 3. Monitor with auto-retry |
| 186 | +yarn e2e-monitor <batch-id> |
| 187 | +``` |
| 188 | + |
| 189 | +### Targeted E2E Tests |
| 190 | + |
| 191 | +You can run specific e2e test files locally: |
| 192 | + |
| 193 | +```bash |
| 194 | +# Run specific test file |
| 195 | +cd packages/amplify-e2e-tests |
| 196 | +yarn e2e src/__tests__/api_1.test.ts |
| 197 | +``` |
| 198 | + |
| 199 | +**Note:** Local e2e tests still require AWS credentials and will create real resources in your AWS account. |
| 200 | + |
| 201 | +## Common Failure Patterns |
| 202 | + |
| 203 | +### 1. Transient Infrastructure Failures |
| 204 | + |
| 205 | +**Symptoms:** |
| 206 | + |
| 207 | +- Timeout errors |
| 208 | +- Credential expiration |
| 209 | +- Quota/limit errors |
| 210 | + |
| 211 | +**Solution:** Retry the build |
| 212 | + |
| 213 | +```bash |
| 214 | +yarn e2e-retry <batch-id> |
| 215 | +``` |
| 216 | + |
| 217 | +### 2. Code-Related Failures |
| 218 | + |
| 219 | +**Symptoms:** |
| 220 | + |
| 221 | +- Test failures |
| 222 | +- Build errors |
| 223 | +- Linting errors |
| 224 | +- Coverage threshold failures |
| 225 | + |
| 226 | +**Solution:** Fix the code and re-run locally, then push and re-trigger e2e tests |
| 227 | + |
| 228 | +### 3. Dependency-Related Failures |
| 229 | + |
| 230 | +**Symptoms:** |
| 231 | + |
| 232 | +- Module not found errors |
| 233 | +- Version conflicts |
| 234 | +- Breaking API changes |
| 235 | + |
| 236 | +**Solution:** |
| 237 | + |
| 238 | +- Check if dependency upgrade is necessary |
| 239 | +- Look for major version changes that may have breaking changes |
| 240 | +- Consider pinning to a compatible version |
| 241 | + |
| 242 | +## Build Job Types |
| 243 | + |
| 244 | +The e2e workflow includes these build types: |
| 245 | + |
| 246 | +- `build_linux` - Build on Linux (not retried by monitor) |
| 247 | +- `build_windows` - Build on Windows (not retried by monitor) |
| 248 | +- `test` - Run unit tests (not retried by monitor) |
| 249 | +- `lint` - Run linting (not retried by monitor) |
| 250 | +- `verify_yarn_lock` - Verify yarn.lock consistency |
| 251 | +- `publish_to_local_registry` - Publish to Verdaccio |
| 252 | +- `amplify_e2e_tests_*` - E2E test suites (multiple jobs) |
| 253 | + |
| 254 | +**Note:** The monitor script skips auto-retrying `build_linux`, `build_windows`, `test`, and `lint` because failures in these are typically code-related and require fixes, not retries. |
| 255 | + |
| 256 | +## Tips |
| 257 | + |
| 258 | +1. **Always test locally first** before pushing to CI |
| 259 | +2. **Check pre-commit hooks** - they run tests automatically |
| 260 | +3. **Monitor resource usage** - e2e tests create real AWS resources |
| 261 | +4. **Clean up resources** - use cleanup scripts periodically |
| 262 | +5. **Check credentials** - most failures are due to expired credentials |
| 263 | +6. **Read the logs** - build logs contain detailed error information |
| 264 | + |
| 265 | +## Troubleshooting |
| 266 | + |
| 267 | +### "Command failed with exit code 1" |
| 268 | + |
| 269 | +This is a generic error. Check the full output for the actual error message. |
| 270 | + |
| 271 | +### "Cannot read properties of undefined" |
| 272 | + |
| 273 | +Often indicates a dependency version mismatch or breaking API change. |
| 274 | + |
| 275 | +### "Coverage threshold not met" |
| 276 | + |
| 277 | +Check if this is a pre-existing issue by testing on the base branch. Coverage can change due to: |
| 278 | + |
| 279 | +- Code changes |
| 280 | +- Dependency updates affecting how coverage is calculated |
| 281 | +- Test changes |
| 282 | + |
| 283 | +### "Linting errors" |
| 284 | + |
| 285 | +Run `yarn lint-fix` to auto-fix some issues. Others require manual fixes. |
| 286 | + |
| 287 | +## Related Documentation |
| 288 | + |
| 289 | +- [DEPENDABOT.md](./DEPENDABOT.md) - Dependency update workflow |
| 290 | +- [AGENTS.md](../AGENTS.md) - General agent workflow |
| 291 | +- [shared-scripts.sh](../shared-scripts.sh) - Build step implementations |
0 commit comments