Skip to content

Commit c816c59

Browse files
committed
run prettier
1 parent 859f8eb commit c816c59

File tree

3 files changed

+121
-68
lines changed

3 files changed

+121
-68
lines changed

docs/testing/e2e/mobile-e2e-api-mocking.md

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ export const DEFAULT_MOCKS = {
6868
],
6969
};
7070
```
71+
7172
j
73+
7274
### Adding New Default Mocks
7375

7476
To add default mocks that benefit all tests:
@@ -209,10 +211,10 @@ import { setupMockPostRequest } from '../api-mocking/helpers/mockHelpers';
209211
await setupMockPostRequest(
210212
mockServer,
211213
'https://api.example.com/validate',
212-
{
214+
{
213215
method: 'transfer',
214216
amount: '1000000000000000000',
215-
to: '0x742d35cc6634c0532925a3b8d0ea4405abf5adf3'
217+
to: '0x742d35cc6634c0532925a3b8d0ea4405abf5adf3',
216218
}, // Expected request body
217219
{ result: 'validated', txId: '0x123...' }, // Mock response
218220
{
@@ -232,7 +234,7 @@ await setupMockRequest(mockServer, {
232234
response: { data: 'secure-data' },
233235
responseCode: 200,
234236
headers: {
235-
'Authorization': 'Bearer mock-token',
237+
Authorization: 'Bearer mock-token',
236238
'Content-Type': 'application/json',
237239
},
238240
});
@@ -313,10 +315,14 @@ await setupRemoteFeatureFlagsMock(mockServer, {
313315
});
314316

315317
// Environment-specific flags
316-
await setupRemoteFeatureFlagsMock(mockServer, {
317-
devOnlyFeature: true,
318-
prodOptimization: false,
319-
}, 'flask'); // Flask distribution
318+
await setupRemoteFeatureFlagsMock(
319+
mockServer,
320+
{
321+
devOnlyFeature: true,
322+
prodOptimization: false,
323+
},
324+
'flask',
325+
); // Flask distribution
320326
```
321327

322328
## 🎭 Complete Mocking Examples
@@ -337,8 +343,9 @@ describe(SmokeE2E('Token Price Display'), () => {
337343
requestMethod: 'GET',
338344
url: 'https://price-api.metamask.io/v2/chains/1/spot-prices',
339345
response: {
340-
'0x0000000000000000000000000000000000000000': { // ETH
341-
price: 2500.50,
346+
'0x0000000000000000000000000000000000000000': {
347+
// ETH
348+
price: 2500.5,
342349
currency: 'usd',
343350
},
344351
},
@@ -415,23 +422,29 @@ const setupSwapMocks = async (mockServer: Mockttp) => {
415422
await setupMockRequest(mockServer, {
416423
requestMethod: 'GET',
417424
url: 'https://price-api.metamask.io/v2/chains/1/spot-prices',
418-
response: { /* price data */ },
425+
response: {
426+
/* price data */
427+
},
419428
responseCode: 200,
420429
});
421430

422431
// Swap quotes mock
423432
await setupMockRequest(mockServer, {
424433
requestMethod: 'GET',
425434
url: /^https:\/\/swap-api\.metamask\.io\/networks\/1\/trades/,
426-
response: { /* quote data */ },
435+
response: {
436+
/* quote data */
437+
},
427438
responseCode: 200,
428439
});
429440

430441
// Gas API mock
431442
await setupMockRequest(mockServer, {
432443
requestMethod: 'GET',
433444
url: 'https://gas-api.metamask.io/networks/1/gasPrices',
434-
response: { /* gas prices */ },
445+
response: {
446+
/* gas prices */
447+
},
435448
responseCode: 200,
436449
});
437450
};
@@ -453,13 +466,13 @@ await withFixtures(
453466

454467
```typescript
455468
// ✅ Good - specific endpoint
456-
url: 'https://api.metamask.io/v2/chains/1/spot-prices'
469+
url: 'https://api.metamask.io/v2/chains/1/spot-prices';
457470

458471
// ✅ Better - regex for dynamic parts
459-
url: /^https:\/\/api\.metamask\.io\/v2\/chains\/\d+\/spot-prices$/
472+
url: /^https:\/\/api\.metamask\.io\/v2\/chains\/\d+\/spot-prices$/;
460473

461474
// ❌ Avoid - too broad, may interfere with other requests
462-
url: 'metamask.io'
475+
url: 'metamask.io';
463476
```
464477

465478
### 2. Handle Request Bodies Properly
@@ -513,7 +526,6 @@ The mock server automatically tracks and logs:
513526
- **Request/response timing** information
514527
- **Feature flag configurations** applied
515528

516-
517529
### Common Debugging Steps
518530

519531
1. **Check test output** for mock-related warnings
@@ -542,10 +554,10 @@ Enable debug logging to see mock activity:
542554

543555
```typescript
544556
// ❌ Too specific - might miss query parameters
545-
url: 'https://api.example.com/data'
557+
url: 'https://api.example.com/data';
546558

547559
// ✅ More flexible pattern
548-
url: /^https:\/\/api\.example\.com\/data(\?.*)?$/
560+
url: /^https:\/\/api\.example\.com\/data(\?.*)?$/;
549561
```
550562

551563
### POST Body Validation Failing
@@ -599,4 +611,4 @@ Before submitting tests with custom mocks:
599611
- [ ] No hardcoded values that should come from constants
600612
- [ ] Error scenarios mocked when testing error handling
601613

602-
The MetaMask Mobile API mocking system provides comprehensive control over network requests, enabling reliable and deterministic E2E tests. By following these patterns, you'll create tests that are both isolated and realistic.
614+
The MetaMask Mobile API mocking system provides comprehensive control over network requests, enabling reliable and deterministic E2E tests. By following these patterns, you'll create tests that are both isolated and realistic.

docs/testing/e2e/mobile-e2e-framework-guide.md

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ MetaMask Mobile uses a modern TypeScript-based E2E testing framework built on De
2525

2626
```
2727
e2e/framework/ # Modern TypeScript framework
28-
├── Assertions.ts # Enhanced assertions with auto-retry
28+
├── Assertions.ts # Enhanced assertions with auto-retry
2929
├── Gestures.ts # Robust user interactions
3030
├── Matchers.ts # Type-safe element selectors
3131
├── Utilities.ts # Core utilities with retry mechanisms
@@ -61,7 +61,7 @@ describe(SmokeE2E('Feature Name'), () => {
6161
},
6262
async () => {
6363
await loginToApp();
64-
64+
6565
// Test implementation here
6666
},
6767
);
@@ -153,7 +153,7 @@ await Utilities.executeWithRetry(
153153
timeout: 30000,
154154
description: 'tap button and verify navigation',
155155
elemDescription: 'Submit Button',
156-
}
156+
},
157157
);
158158

159159
// Element state checking utilities
@@ -170,56 +170,63 @@ await Utilities.checkElementReadyState(element, {
170170

171171
```typescript
172172
// Basic fixture
173-
new FixtureBuilder().build()
173+
new FixtureBuilder().build();
174174

175175
// With popular networks
176-
new FixtureBuilder().withPopularNetworks().build()
176+
new FixtureBuilder().withPopularNetworks().build();
177177

178178
// With Ganache network for local testing
179-
new FixtureBuilder().withGanacheNetwork().build()
179+
new FixtureBuilder().withGanacheNetwork().build();
180180

181181
// With connected test dapp
182182
new FixtureBuilder()
183183
.withPermissionControllerConnectedToTestDapp(buildPermissions(['0x539']))
184-
.build()
184+
.build();
185185

186186
// With pre-configured tokens and contacts
187187
new FixtureBuilder()
188188
.withAddressBookControllerContactBob()
189189
.withTokensControllerERC20()
190-
.build()
190+
.build();
191191
```
192192

193193
### Advanced withFixtures Configuration
194194

195195
```typescript
196-
import { DappVariants, LocalNodeType, GanacheHardfork } from '../framework/fixtures/constants';
196+
import {
197+
DappVariants,
198+
LocalNodeType,
199+
GanacheHardfork,
200+
} from '../framework/fixtures/constants';
197201

198202
await withFixtures(
199203
{
200204
fixture: new FixtureBuilder().withGanacheNetwork().build(),
201205
restartDevice: true,
202-
206+
203207
// Configure test dapps
204208
dapps: [
205209
{ dappVariant: DappVariants.MULTICHAIN },
206210
{ dappVariant: DappVariants.TEST_DAPP },
207211
],
208-
212+
209213
// Configure local blockchain nodes
210-
localNodeOptions: [{
211-
type: LocalNodeType.ganache,
212-
options: {
213-
hardfork: GanacheHardfork.london,
214-
mnemonic: 'WORD1 WORD2 WORD3 WORD4 WORD5 WORD6 WORD7 WORD8 WORD9 WORD10 WORD11 WORD12'
215-
}
216-
}],
217-
214+
localNodeOptions: [
215+
{
216+
type: LocalNodeType.ganache,
217+
options: {
218+
hardfork: GanacheHardfork.london,
219+
mnemonic:
220+
'WORD1 WORD2 WORD3 WORD4 WORD5 WORD6 WORD7 WORD8 WORD9 WORD10 WORD11 WORD12',
221+
},
222+
},
223+
],
224+
218225
// Test-specific API mocks (see API Mocking Guide)
219226
testSpecificMock: async (mockServer) => {
220227
// Custom mocking logic
221228
},
222-
229+
223230
// Additional launch arguments
224231
launchArgs: {
225232
fixtureServerPort: 8545,
@@ -244,7 +251,7 @@ class SendView {
244251
get sendButton() {
245252
return Matchers.getElementByID(SendViewSelectors.SEND_BUTTON);
246253
}
247-
254+
248255
get amountInput() {
249256
return Matchers.getElementByID(SendViewSelectors.AMOUNT_INPUT);
250257
}
@@ -269,7 +276,7 @@ class SendView {
269276
description: 'send button should be visible',
270277
});
271278
}
272-
279+
273280
// Complex interaction with retry
274281
async sendETHWithRetry(amount: string): Promise<void> {
275282
await Utilities.executeWithRetry(
@@ -284,7 +291,7 @@ class SendView {
284291
{
285292
timeout: 30000,
286293
description: 'complete send ETH transaction',
287-
}
294+
},
288295
);
289296
}
290297
}
@@ -336,8 +343,10 @@ await Gestures.tap(button, { description: 'tap submit button' });
336343

337344
// ✅ Use framework retry mechanisms
338345
await Utilities.executeWithRetry(
339-
async () => { /* operation */ },
340-
{ timeout: 30000, description: 'retry operation' }
346+
async () => {
347+
/* operation */
348+
},
349+
{ timeout: 30000, description: 'retry operation' },
341350
);
342351
```
343352

@@ -346,6 +355,7 @@ await Utilities.executeWithRetry(
346355
### Common Framework Issues
347356

348357
#### "Element not enabled" Errors
358+
349359
```typescript
350360
// Solution: Skip enabled check for temporarily disabled elements
351361
await Gestures.tap(loadingButton, {
@@ -355,6 +365,7 @@ await Gestures.tap(loadingButton, {
355365
```
356366

357367
#### "Element moving/animating" Errors
368+
358369
```typescript
359370
// Solution: Enable stability checking for animated elements
360371
await Gestures.tap(animatedButton, {
@@ -364,6 +375,7 @@ await Gestures.tap(animatedButton, {
364375
```
365376

366377
#### Framework Migration Issues
378+
367379
```typescript
368380
// ❌ Old deprecated pattern
369381
await Assertions.checkIfVisible(element, 15000);
@@ -378,34 +390,37 @@ await Assertions.expectElementToBeVisible(element, {
378390
## 🔄 Migration from Legacy Framework
379391

380392
### Migration Status
393+
381394
Current migration phases from [`e2e/framework/README.md`](https://github.com/MetaMask/metamask-mobile/blob/main/e2e/framework/README.md):
382395

383396
- ✅ Phase 0: TypeScript framework foundation
384-
- ✅ Phase 1: ESLint for E2E tests
397+
- ✅ Phase 1: ESLint for E2E tests
385398
- ⏳ Phase 2: Legacy framework replacement
386399
- ⏳ Phase 3: Gradual test migration
387400

388401
### For New Tests
402+
389403
- Use TypeScript framework exclusively
390404
- Import from `e2e/framework/index.ts`
391405
- Follow all patterns in this guide
392406
- Use `withFixtures` pattern
393407

394408
### For Existing Tests
409+
395410
- Gradually migrate to TypeScript framework
396411
- Replace deprecated methods (check `@deprecated` tags)
397412
- Update imports to use framework entry point
398413
- Add `description` parameters to all framework calls
399414

400415
### Common Migration Patterns
401416

402-
| Legacy Pattern | Modern Framework Equivalent |
403-
|----------------|----------------------------|
404-
| `TestHelpers.delay(5000)` | `Assertions.expectElementToBeVisible(element, {timeout: 5000})` |
405-
| `checkIfVisible(element, 15000)` | `expectElementToBeVisible(element, {timeout: 15000, description: '...'})` |
406-
| `waitFor(element).toBeVisible()` | `expectElementToBeVisible(element, {description: '...'})` |
407-
| `tapAndLongPress(element)` | `longPress(element, {description: '...'})` |
408-
| `clearField(element); typeText(element, text)` | `typeText(element, text, {clearFirst: true, description: '...'})` |
417+
| Legacy Pattern | Modern Framework Equivalent |
418+
| ---------------------------------------------- | ------------------------------------------------------------------------- |
419+
| `TestHelpers.delay(5000)` | `Assertions.expectElementToBeVisible(element, {timeout: 5000})` |
420+
| `checkIfVisible(element, 15000)` | `expectElementToBeVisible(element, {timeout: 15000, description: '...'})` |
421+
| `waitFor(element).toBeVisible()` | `expectElementToBeVisible(element, {description: '...'})` |
422+
| `tapAndLongPress(element)` | `longPress(element, {description: '...'})` |
423+
| `clearField(element); typeText(element, text)` | `typeText(element, text, {clearFirst: true, description: '...'})` |
409424

410425
## 📚 Framework Resources
411426

@@ -428,4 +443,4 @@ Before using the framework in tests, ensure:
428443
- [ ] Framework retry mechanisms used instead of manual loops
429444
- [ ] TypeScript types used for better development experience
430445

431-
The MetaMask Mobile E2E framework provides a robust, reliable foundation for writing maintainable end-to-end tests. By following these patterns and avoiding anti-patterns, you'll create tests that are both resilient and easy to understand.
446+
The MetaMask Mobile E2E framework provides a robust, reliable foundation for writing maintainable end-to-end tests. By following these patterns and avoiding anti-patterns, you'll create tests that are both resilient and easy to understand.

0 commit comments

Comments
 (0)