Skip to content

Commit f5a581f

Browse files
authored
test: fix flaky tests (#2493)
1 parent db664c5 commit f5a581f

File tree

15 files changed

+91
-44
lines changed

15 files changed

+91
-44
lines changed

e2e/backup.e2e.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
bitcoinURL,
1010
getSeed,
1111
restoreWallet,
12+
waitForBackup,
1213
} from './helpers';
1314
import initElectrum from './electrum';
1415

@@ -90,7 +91,7 @@ d('Backup', () => {
9091
await element(by.id('NavigationClose')).atIndex(0).tap();
9192

9293
// remove 2 default widgets, leave PriceWidget
93-
await element(by.id('WalletsScrollView')).scroll(200, 'down', NaN, 0.85);
94+
await element(by.id('WalletsScrollView')).scroll(200, 'down', 0);
9495
await element(by.id('WidgetsEdit')).tap();
9596
for (const w of ['NewsWidget', 'BlocksWidget']) {
9697
await element(by.id('WidgetActionDelete').withAncestor(by.id(w))).tap();
@@ -102,6 +103,7 @@ d('Backup', () => {
102103

103104
// restore wallet
104105
const seed = await getSeed();
106+
await waitForBackup();
105107
await restoreWallet(seed);
106108

107109
// check settings
@@ -119,7 +121,7 @@ d('Backup', () => {
119121
await sleep(200); // animation
120122

121123
// check widgets
122-
await element(by.id('WalletsScrollView')).scroll(300, 'down', NaN, 0.85);
124+
await element(by.id('WalletsScrollView')).scroll(300, 'down', 0);
123125
await expect(element(by.id('PriceWidget'))).toExist();
124126
await expect(element(by.id('NewsWidget'))).not.toExist();
125127
await expect(element(by.id('BlocksWidget'))).not.toExist();

e2e/boost.e2e.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
bitcoinURL,
1212
getSeed,
1313
restoreWallet,
14+
waitForBackup,
1415
} from './helpers';
1516
import initElectrum from './electrum';
1617

@@ -95,7 +96,7 @@ d('Boost', () => {
9596
await element(by.id('Close')).tap();
9697

9798
// check Activity
98-
await element(by.id('WalletsScrollView')).scrollTo('bottom', NaN, 0.85);
99+
await element(by.id('WalletsScrollView')).scrollTo('bottom', 0);
99100
await expect(element(by.id('ActivityShort-1'))).toBeVisible();
100101
await expect(
101102
element(by.text('100 000').withAncestor(by.id('ActivityShort-2'))),
@@ -206,7 +207,7 @@ d('Boost', () => {
206207
await element(by.id('Close')).tap();
207208

208209
// check Activity
209-
await element(by.id('WalletsScrollView')).scrollTo('bottom', NaN, 0.85);
210+
await element(by.id('WalletsScrollView')).scrollTo('bottom', 0);
210211
await expect(element(by.id('ActivityShort-1'))).toBeVisible();
211212
await expect(
212213
element(by.text('100 000').withAncestor(by.id('ActivityShort-2'))),
@@ -268,10 +269,11 @@ d('Boost', () => {
268269

269270
// wipe & restore
270271
const seed = await getSeed();
272+
await waitForBackup();
271273
await restoreWallet(seed);
272274

273275
// check activity after restore
274-
await element(by.id('WalletsScrollView')).scrollTo('bottom', NaN, 0.85);
276+
await element(by.id('WalletsScrollView')).scrollTo('bottom', 0);
275277
await expect(element(by.id('BoostingIcon'))).toBeVisible();
276278
await element(by.id('ActivityShort-1')).tap();
277279
await expect(element(by.id('BoostedButton'))).toBeVisible();

e2e/helpers.js

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const checkComplete = (name) => {
2323
}
2424

2525
for (const n of name) {
26-
if (!fs.existsSync(path.join(LOCK_PATH, 'lock-' + n))) {
26+
if (!fs.existsSync(path.join(LOCK_PATH, `lock-${n}`))) {
2727
return false;
2828
}
2929
}
@@ -38,7 +38,7 @@ export const markComplete = (name) => {
3838
}
3939

4040
fs.mkdirSync(LOCK_PATH, { recursive: true });
41-
fs.writeFileSync(path.join(LOCK_PATH, 'lock-' + name), '1');
41+
fs.writeFileSync(path.join(LOCK_PATH, `lock-${name}`), '1');
4242
};
4343

4444
export const sleep = (ms) => {
@@ -63,15 +63,13 @@ export async function waitForElementAttribute(
6363
if (attributes[attribute] === expectedValue) {
6464
console.log(`${elementId} has attribute ${attribute}=${expectedValue}`);
6565
break;
66-
} else {
67-
console.log(
68-
`Waiting for ${elementId} to have attribute ${attribute}=${expectedValue}...`,
69-
);
70-
await new Promise((resolve) => {
71-
setTimeout(resolve, 1000);
72-
});
73-
timeout--;
7466
}
67+
68+
console.log(
69+
`Waiting for ${elementId} to have attribute ${attribute}=${expectedValue}...`,
70+
);
71+
await sleep(1000);
72+
timeout--;
7573
}
7674
}
7775

@@ -102,7 +100,7 @@ export const completeOnboarding = async () => {
102100
await element(by.id('WalletOnboardingClose')).tap();
103101
await sleep(3000); // wait for redux-persist to save state
104102
return;
105-
} catch (e) {}
103+
} catch (_e) {}
106104
}
107105

108106
throw new Error('Tapping "WalletOnboardingClose" timeout');
@@ -124,9 +122,7 @@ export const launchAndWait = async () => {
124122
await element(by.id('SuggestionsLabel')).tap();
125123
await sleep(1000);
126124
break;
127-
} catch (e) {
128-
continue;
129-
}
125+
} catch (_e) {}
130126
}
131127
};
132128

@@ -246,6 +242,15 @@ export const restoreWallet = async (seed, passphrase) => {
246242
try {
247243
await element(by.id('SuggestionsLabel')).tap();
248244
break;
249-
} catch (e) {}
245+
} catch (_e) {}
250246
}
251247
};
248+
249+
export const waitForBackup = async () => {
250+
await element(by.id('Settings')).tap();
251+
await element(by.id('BackupSettings')).tap();
252+
await waitFor(element(by.id('AllSynced')))
253+
.toBeVisible()
254+
.withTimeout(40000);
255+
await element(by.id('NavigationClose')).atIndex(0).tap();
256+
};

e2e/lightning.e2e.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
waitForPeerConnection,
1616
restoreWallet,
1717
getSeed,
18+
waitForBackup,
1819
} from './helpers';
1920

2021
d = checkComplete('lighting-1') ? describe.skip : describe;
@@ -78,7 +79,7 @@ d('Lightning', () => {
7879
await waitFor(element(by.id('LDKNodeID')))
7980
.toBeVisible()
8081
.withTimeout(60000);
81-
let { label: ldkNodeId } = await element(
82+
const { label: ldkNodeId } = await element(
8283
by.id('LDKNodeID'),
8384
).getAttributes();
8485
await element(by.id('NavigationBack')).atIndex(0).tap();
@@ -118,7 +119,7 @@ d('Lightning', () => {
118119
await expect(
119120
element(by.id('MoneyText').withAncestor(by.id('TotalSize'))),
120121
).toHaveText('100 000');
121-
await element(by.id('ChannelScrollView')).scrollTo('bottom', NaN, 0.1);
122+
await element(by.id('ChannelScrollView')).scrollTo('bottom', Number.NaN, 0.1);
122123
await expect(element(by.id('IsUsableYes'))).toBeVisible();
123124
await element(by.id('NavigationClose')).atIndex(0).tap();
124125

@@ -229,7 +230,7 @@ d('Lightning', () => {
229230
.withTimeout(10000);
230231

231232
// check tx history
232-
await element(by.id('WalletsScrollView')).scroll(1000, 'down', NaN, 0.85);
233+
await element(by.id('WalletsScrollView')).scroll(1000, 'down', 0);
233234
await expect(
234235
element(by.text('1 000').withAncestor(by.id('ActivityShort-1'))),
235236
).toBeVisible();
@@ -310,6 +311,7 @@ d('Lightning', () => {
310311

311312
// wipe and restore wallet
312313
const seed = await getSeed();
314+
await waitForBackup();
313315
await restoreWallet(seed);
314316

315317
// check balance
@@ -320,7 +322,7 @@ d('Lightning', () => {
320322
.withTimeout(10000);
321323

322324
// check tx history
323-
await element(by.id('WalletsScrollView')).scroll(1000, 'down', NaN, 0.85);
325+
await element(by.id('WalletsScrollView')).scroll(1000, 'down', 0);
324326
await expect(
325327
element(by.text('111').withAncestor(by.id('ActivityShort-2'))),
326328
).toBeVisible();
@@ -334,7 +336,7 @@ d('Lightning', () => {
334336
await sleep(100);
335337
await element(by.id('Channels')).tap();
336338
await element(by.id('Channel')).atIndex(0).tap();
337-
await element(by.id('ChannelScrollView')).scrollTo('bottom', NaN, 0.1);
339+
await element(by.id('ChannelScrollView')).scrollTo('bottom', Number.NaN, 0.1);
338340
await expect(element(by.id('IsUsableYes'))).toBeVisible();
339341

340342
// close channel

e2e/lnurl.e2e.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ d('LNURL', () => {
9999
await waitFor(element(by.id('LDKNodeID')))
100100
.toBeVisible()
101101
.withTimeout(60000);
102-
let { label: ldkNodeID } = await element(
102+
const { label: ldkNodeID } = await element(
103103
by.id('LDKNodeID'),
104104
).getAttributes();
105105
await element(by.id('NavigationClose')).atIndex(0).tap();
@@ -195,7 +195,7 @@ d('LNURL', () => {
195195
.withTimeout(10000);
196196
await element(by.id('Close')).tap();
197197
// check if comment is displayed
198-
await element(by.id('WalletsScrollView')).scrollTo('bottom', NaN, 0.85);
198+
await element(by.id('WalletsScrollView')).scrollTo('bottom', 0);
199199
await element(by.id('ActivityShort-1')).tap();
200200
await expect(element(by.id('InvoiceComment'))).toHaveText('test comment');
201201
await element(by.id('NavigationClose')).tap();

e2e/onchain.e2e.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ d('Onchain', () => {
140140
).toHaveText('0');
141141

142142
// check Activity
143-
await element(by.id('WalletsScrollView')).scroll(1000, 'down', NaN, 0.85);
143+
await element(by.id('WalletsScrollView')).scroll(1000, 'down', 0);
144144
await expect(element(by.id('ActivityShort-1'))).toBeVisible();
145145
await expect(element(by.id('ActivityShort-2'))).toBeVisible();
146146
await expect(element(by.id('ActivityShort-3'))).toBeVisible();
@@ -306,7 +306,7 @@ d('Onchain', () => {
306306
).toHaveText('0');
307307

308308
// check number of outputs for send tx
309-
await element(by.id('WalletsScrollView')).scroll(1000, 'down', NaN, 0.85);
309+
await element(by.id('WalletsScrollView')).scroll(1000, 'down', 0);
310310
await expect(element(by.id('ActivityShort-1'))).toBeVisible();
311311
await expect(element(by.id('ActivityShort-2'))).toBeVisible();
312312
await element(by.id('ActivityShowAll')).tap();

e2e/send.e2e.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ d('Send', () => {
193193
await waitFor(element(by.id('LDKNodeID')))
194194
.toBeVisible()
195195
.withTimeout(60000);
196-
let { label: ldkNodeId } = await element(
196+
const { label: ldkNodeId } = await element(
197197
by.id('LDKNodeID'),
198198
).getAttributes();
199199
await element(by.id('NavigationBack')).atIndex(0).tap();
@@ -233,7 +233,7 @@ d('Send', () => {
233233
await expect(
234234
element(by.id('MoneyText').withAncestor(by.id('TotalSize'))),
235235
).toHaveText('100 000');
236-
await element(by.id('ChannelScrollView')).scrollTo('bottom', NaN, 0.1);
236+
await element(by.id('ChannelScrollView')).scrollTo('bottom', Number.NaN, 0.1);
237237
await expect(element(by.id('IsUsableYes'))).toBeVisible();
238238
await element(by.id('NavigationClose')).atIndex(0).tap();
239239
await sleep(500);

e2e/slashtags.e2e.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
sleep,
1010
getSeed,
1111
restoreWallet,
12+
waitForBackup,
1213
} from './helpers';
1314
import initElectrum from './electrum';
1415

@@ -222,6 +223,7 @@ d('Profile and Contacts', () => {
222223

223224
// WIPE APP AND RESTORE FROM THE SEED
224225
const seed = await getSeed();
226+
await waitForBackup();
225227
await restoreWallet(seed);
226228

227229
// CHECK PROFILE, CONTACTS, TRANSACTION

e2e/transfer.e2e.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
waitForPeerConnection,
1616
getSeed,
1717
restoreWallet,
18+
waitForBackup,
1819
} from './helpers';
1920

2021
d = checkComplete(['transfer-1', 'transfer-2']) ? describe.skip : describe;
@@ -99,7 +100,7 @@ d('Transfer', () => {
99100
await expect(element(by.text('100 000'))).toBeVisible();
100101
await element(by.id('SpendingAdvancedDefault')).tap();
101102
await element(by.id('SpendingAdvancedNumberField')).tap();
102-
let { label } = await element(
103+
const { label } = await element(
103104
by.id('SpendingAdvancedNumberField'),
104105
).getAttributes();
105106
const lspBalance = Number.parseInt(label, 10);
@@ -206,13 +207,14 @@ d('Transfer', () => {
206207
await element(by.id('NavigationClose')).tap();
207208

208209
const seed = await getSeed();
210+
await waitForBackup();
209211
await restoreWallet(seed);
210212

211213
// check transfer card
212214
await expect(element(by.id('Suggestion-lightningSettingUp'))).toBeVisible();
213215

214216
// check activity after restore
215-
await element(by.id('WalletsScrollView')).scrollTo('bottom', NaN, 0.85);
217+
await element(by.id('WalletsScrollView')).scrollTo('bottom', 0);
216218
await element(by.id('ActivityShort-1')).tap();
217219
await expect(element(by.id('StatusTransfer'))).toBeVisible();
218220

@@ -229,10 +231,11 @@ d('Transfer', () => {
229231
.withTimeout(30000);
230232

231233
// reset & restore again
234+
await waitForBackup();
232235
await restoreWallet(seed);
233236

234237
// check activity after restore
235-
await element(by.id('WalletsScrollView')).scrollTo('bottom', NaN, 0.85);
238+
await element(by.id('WalletsScrollView')).scrollTo('bottom', 0);
236239
await expect(element(by.id('BoostingIcon'))).toBeVisible();
237240
await element(by.id('ActivityShort-1')).tap();
238241
await expect(element(by.id('StatusBoosting'))).toBeVisible();
@@ -270,9 +273,7 @@ d('Transfer', () => {
270273
await waitFor(element(by.id('LDKNodeID')))
271274
.toBeVisible()
272275
.withTimeout(60000);
273-
let { label: ldkNodeId } = await element(
274-
by.id('LDKNodeID'),
275-
).getAttributes();
276+
const { label: ldkNodeId } = await element(by.id('LDKNodeID')).getAttributes();
276277
await element(by.id('NavigationClose')).tap();
277278

278279
// Get LND node id
@@ -326,12 +327,10 @@ d('Transfer', () => {
326327
await expect(element(by.id('Suggestion-lightningSettingUp'))).toBeVisible();
327328

328329
// check activity
329-
await element(by.id('WalletsScrollView')).scrollTo('bottom', NaN, 0.85);
330+
await element(by.id('WalletsScrollView')).scrollTo('bottom', 0);
330331
await expect(element(by.text('From Savings (±30m)'))).toBeVisible();
331332
await element(by.id('ActivityShort-1')).tap();
332333
await expect(element(by.text('Transfer (±30m)'))).toBeVisible();
333-
await element(by.id('NavigationClose')).tap();
334-
await element(by.id('WalletsScrollView')).scrollTo('top', NaN, 0.85);
335334

336335
// Mine 3 blocks
337336
await rpc.generateToAddress(3, await rpc.getNewAddress());
@@ -356,7 +355,7 @@ d('Transfer', () => {
356355
await expect(
357356
element(by.id('MoneyText').withAncestor(by.id('TotalSize'))),
358357
).toHaveText('20 000');
359-
await element(by.id('ChannelScrollView')).scrollTo('bottom', NaN, 0.1);
358+
await element(by.id('ChannelScrollView')).scrollTo('bottom', Number.NaN, 0.1);
360359
await expect(element(by.id('IsUsableYes'))).toBeVisible();
361360
await element(by.id('NavigationClose')).atIndex(0).tap();
362361

e2e/widgets.e2e.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ d('Widgets', () => {
3535
}
3636

3737
// add price widget
38-
await element(by.id('WalletsScrollView')).scroll(300, 'down', NaN, 0.85);
38+
await element(by.id('WalletsScrollView')).scroll(300, 'down', 0);
3939
await element(by.id('WidgetsAdd')).tap();
4040
await element(by.id('WidgetsOnboarding-button')).tap();
4141
await element(by.id('WidgetListItem-price')).tap();
@@ -50,7 +50,7 @@ d('Widgets', () => {
5050
await element(by.id('WidgetEditField-showSource')).tap();
5151
await element(by.id('WidgetEditPreview')).tap();
5252
await element(by.id('WidgetSave')).tap();
53-
await element(by.id('WalletsScrollView')).scroll(200, 'down', NaN, 0.85);
53+
await element(by.id('WalletsScrollView')).scroll(200, 'down', 0);
5454
await expect(element(by.id('PriceWidget'))).toBeVisible();
5555
await expect(element(by.id('PriceWidgetRow-BTC/EUR'))).toBeVisible();
5656
await expect(element(by.id('PriceWidgetSource'))).toBeVisible();

0 commit comments

Comments
 (0)