Skip to content

Commit ceed7ce

Browse files
committed
test: fix flaky tests
1 parent 6d85a23 commit ceed7ce

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
@@ -11,6 +11,7 @@ import {
1111
electrumPort,
1212
getSeed,
1313
restoreWallet,
14+
waitForBackup,
1415
} from './helpers';
1516
import initWaitForElectrumToSync from '../__tests__/utils/wait-for-electrum';
1617

@@ -95,7 +96,7 @@ d('Backup', () => {
9596
await element(by.id('NavigationClose')).atIndex(0).tap();
9697

9798
// remove 2 default widgets, leave PriceWidget
98-
await element(by.id('WalletsScrollView')).scroll(200, 'down', NaN, 0.85);
99+
await element(by.id('WalletsScrollView')).scroll(200, 'down', 0);
99100
await element(by.id('WidgetsEdit')).tap();
100101
for (const w of ['NewsWidget', 'BlocksWidget']) {
101102
await element(by.id('WidgetActionDelete').withAncestor(by.id(w))).tap();
@@ -107,6 +108,7 @@ d('Backup', () => {
107108

108109
// restore wallet
109110
const seed = await getSeed();
111+
await waitForBackup();
110112
await restoreWallet(seed);
111113

112114
// check settings
@@ -124,7 +126,7 @@ d('Backup', () => {
124126
await sleep(200); // animation
125127

126128
// check widgets
127-
await element(by.id('WalletsScrollView')).scroll(300, 'down', NaN, 0.85);
129+
await element(by.id('WalletsScrollView')).scroll(300, 'down', 0);
128130
await expect(element(by.id('PriceWidget'))).toExist();
129131
await expect(element(by.id('NewsWidget'))).not.toExist();
130132
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
@@ -13,6 +13,7 @@ import {
1313
electrumPort,
1414
getSeed,
1515
restoreWallet,
16+
waitForBackup,
1617
} from './helpers';
1718
import initWaitForElectrumToSync from '../__tests__/utils/wait-for-electrum';
1819

@@ -100,7 +101,7 @@ d('Boost', () => {
100101
await element(by.id('Close')).tap();
101102

102103
// check Activity
103-
await element(by.id('WalletsScrollView')).scrollTo('bottom', NaN, 0.85);
104+
await element(by.id('WalletsScrollView')).scrollTo('bottom', 0);
104105
await expect(element(by.id('ActivityShort-1'))).toBeVisible();
105106
await expect(
106107
element(by.text('100 000').withAncestor(by.id('ActivityShort-2'))),
@@ -211,7 +212,7 @@ d('Boost', () => {
211212
await element(by.id('Close')).tap();
212213

213214
// check Activity
214-
await element(by.id('WalletsScrollView')).scrollTo('bottom', NaN, 0.85);
215+
await element(by.id('WalletsScrollView')).scrollTo('bottom', 0);
215216
await expect(element(by.id('ActivityShort-1'))).toBeVisible();
216217
await expect(
217218
element(by.text('100 000').withAncestor(by.id('ActivityShort-2'))),
@@ -273,10 +274,11 @@ d('Boost', () => {
273274

274275
// wipe & restore
275276
const seed = await getSeed();
277+
await waitForBackup();
276278
await restoreWallet(seed);
277279

278280
// check activity after restore
279-
await element(by.id('WalletsScrollView')).scrollTo('bottom', NaN, 0.85);
281+
await element(by.id('WalletsScrollView')).scrollTo('bottom', 0);
280282
await expect(element(by.id('BoostingIcon'))).toBeVisible();
281283
await element(by.id('ActivityShort-1')).tap();
282284
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
@@ -17,6 +17,7 @@ import {
1717
waitForPeerConnection,
1818
restoreWallet,
1919
getSeed,
20+
waitForBackup,
2021
} from './helpers';
2122

2223
d = checkComplete('lighting-1') ? describe.skip : describe;
@@ -83,7 +84,7 @@ d('Lightning', () => {
8384
await waitFor(element(by.id('LDKNodeID')))
8485
.toBeVisible()
8586
.withTimeout(60000);
86-
let { label: ldkNodeId } = await element(
87+
const { label: ldkNodeId } = await element(
8788
by.id('LDKNodeID'),
8889
).getAttributes();
8990
await element(by.id('NavigationBack')).atIndex(0).tap();
@@ -123,7 +124,7 @@ d('Lightning', () => {
123124
await expect(
124125
element(by.id('MoneyText').withAncestor(by.id('TotalSize'))),
125126
).toHaveText('100 000');
126-
await element(by.id('ChannelScrollView')).scrollTo('bottom', NaN, 0.1);
127+
await element(by.id('ChannelScrollView')).scrollTo('bottom', Number.NaN, 0.1);
127128
await expect(element(by.id('IsUsableYes'))).toBeVisible();
128129
await element(by.id('NavigationClose')).atIndex(0).tap();
129130

@@ -234,7 +235,7 @@ d('Lightning', () => {
234235
.withTimeout(10000);
235236

236237
// check tx history
237-
await element(by.id('WalletsScrollView')).scroll(1000, 'down', NaN, 0.85);
238+
await element(by.id('WalletsScrollView')).scroll(1000, 'down', 0);
238239
await expect(
239240
element(by.text('1 000').withAncestor(by.id('ActivityShort-1'))),
240241
).toBeVisible();
@@ -315,6 +316,7 @@ d('Lightning', () => {
315316

316317
// wipe and restore wallet
317318
const seed = await getSeed();
319+
await waitForBackup();
318320
await restoreWallet(seed);
319321

320322
// check balance
@@ -325,7 +327,7 @@ d('Lightning', () => {
325327
.withTimeout(10000);
326328

327329
// check tx history
328-
await element(by.id('WalletsScrollView')).scroll(1000, 'down', NaN, 0.85);
330+
await element(by.id('WalletsScrollView')).scroll(1000, 'down', 0);
329331
await expect(
330332
element(by.text('111').withAncestor(by.id('ActivityShort-2'))),
331333
).toBeVisible();
@@ -339,7 +341,7 @@ d('Lightning', () => {
339341
await sleep(100);
340342
await element(by.id('Channels')).tap();
341343
await element(by.id('Channel')).atIndex(0).tap();
342-
await element(by.id('ChannelScrollView')).scrollTo('bottom', NaN, 0.1);
344+
await element(by.id('ChannelScrollView')).scrollTo('bottom', Number.NaN, 0.1);
343345
await expect(element(by.id('IsUsableYes'))).toBeVisible();
344346

345347
// close channel

e2e/lnurl.e2e.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ d('LNURL', () => {
104104
await waitFor(element(by.id('LDKNodeID')))
105105
.toBeVisible()
106106
.withTimeout(60000);
107-
let { label: ldkNodeID } = await element(
107+
const { label: ldkNodeID } = await element(
108108
by.id('LDKNodeID'),
109109
).getAttributes();
110110
await element(by.id('NavigationClose')).atIndex(0).tap();
@@ -200,7 +200,7 @@ d('LNURL', () => {
200200
.withTimeout(10000);
201201
await element(by.id('Close')).tap();
202202
// check if comment is displayed
203-
await element(by.id('WalletsScrollView')).scrollTo('bottom', NaN, 0.85);
203+
await element(by.id('WalletsScrollView')).scrollTo('bottom', 0);
204204
await element(by.id('ActivityShort-1')).tap();
205205
await expect(element(by.id('InvoiceComment'))).toHaveText('test comment');
206206
await element(by.id('NavigationClose')).tap();

e2e/onchain.e2e.js

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

147147
// check Activity
148-
await element(by.id('WalletsScrollView')).scroll(1000, 'down', NaN, 0.85);
148+
await element(by.id('WalletsScrollView')).scroll(1000, 'down', 0);
149149
await expect(element(by.id('ActivityShort-1'))).toBeVisible();
150150
await expect(element(by.id('ActivityShort-2'))).toBeVisible();
151151
await expect(element(by.id('ActivityShort-3'))).toBeVisible();
@@ -311,7 +311,7 @@ d('Onchain', () => {
311311
).toHaveText('0');
312312

313313
// check number of outputs for send tx
314-
await element(by.id('WalletsScrollView')).scroll(1000, 'down', NaN, 0.85);
314+
await element(by.id('WalletsScrollView')).scroll(1000, 'down', 0);
315315
await expect(element(by.id('ActivityShort-1'))).toBeVisible();
316316
await expect(element(by.id('ActivityShort-2'))).toBeVisible();
317317
await element(by.id('ActivityShowAll')).tap();

e2e/send.e2e.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ d('Send', () => {
198198
await waitFor(element(by.id('LDKNodeID')))
199199
.toBeVisible()
200200
.withTimeout(60000);
201-
let { label: ldkNodeId } = await element(
201+
const { label: ldkNodeId } = await element(
202202
by.id('LDKNodeID'),
203203
).getAttributes();
204204
await element(by.id('NavigationBack')).atIndex(0).tap();
@@ -238,7 +238,7 @@ d('Send', () => {
238238
await expect(
239239
element(by.id('MoneyText').withAncestor(by.id('TotalSize'))),
240240
).toHaveText('100 000');
241-
await element(by.id('ChannelScrollView')).scrollTo('bottom', NaN, 0.1);
241+
await element(by.id('ChannelScrollView')).scrollTo('bottom', Number.NaN, 0.1);
242242
await expect(element(by.id('IsUsableYes'))).toBeVisible();
243243
await element(by.id('NavigationClose')).atIndex(0).tap();
244244
await sleep(500);

e2e/slashtags.e2e.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
electrumPort,
1212
getSeed,
1313
restoreWallet,
14+
waitForBackup,
1415
} from './helpers';
1516
import initWaitForElectrumToSync from '../__tests__/utils/wait-for-electrum';
1617

@@ -227,6 +228,7 @@ d('Profile and Contacts', () => {
227228

228229
// WIPE APP AND RESTORE FROM THE SEED
229230
const seed = await getSeed();
231+
await waitForBackup();
230232
await restoreWallet(seed);
231233

232234
// CHECK PROFILE, CONTACTS, TRANSACTION

e2e/transfer.e2e.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
waitForPeerConnection,
1818
getSeed,
1919
restoreWallet,
20+
waitForBackup,
2021
} from './helpers';
2122

2223
d = checkComplete(['transfer-1', 'transfer-2']) ? describe.skip : describe;
@@ -104,7 +105,7 @@ d('Transfer', () => {
104105
await expect(element(by.text('100 000'))).toBeVisible();
105106
await element(by.id('SpendingAdvancedDefault')).tap();
106107
await element(by.id('SpendingAdvancedNumberField')).tap();
107-
let { label } = await element(
108+
const { label } = await element(
108109
by.id('SpendingAdvancedNumberField'),
109110
).getAttributes();
110111
const lspBalance = Number.parseInt(label, 10);
@@ -211,13 +212,14 @@ d('Transfer', () => {
211212
await element(by.id('NavigationClose')).tap();
212213

213214
const seed = await getSeed();
215+
await waitForBackup();
214216
await restoreWallet(seed);
215217

216218
// check transfer card
217219
await expect(element(by.id('Suggestion-lightningSettingUp'))).toBeVisible();
218220

219221
// check activity after restore
220-
await element(by.id('WalletsScrollView')).scrollTo('bottom', NaN, 0.85);
222+
await element(by.id('WalletsScrollView')).scrollTo('bottom', 0);
221223
await element(by.id('ActivityShort-1')).tap();
222224
await expect(element(by.id('StatusTransfer'))).toBeVisible();
223225

@@ -234,10 +236,11 @@ d('Transfer', () => {
234236
.withTimeout(30000);
235237

236238
// reset & restore again
239+
await waitForBackup();
237240
await restoreWallet(seed);
238241

239242
// check activity after restore
240-
await element(by.id('WalletsScrollView')).scrollTo('bottom', NaN, 0.85);
243+
await element(by.id('WalletsScrollView')).scrollTo('bottom', 0);
241244
await expect(element(by.id('BoostingIcon'))).toBeVisible();
242245
await element(by.id('ActivityShort-1')).tap();
243246
await expect(element(by.id('StatusBoosting'))).toBeVisible();
@@ -275,9 +278,7 @@ d('Transfer', () => {
275278
await waitFor(element(by.id('LDKNodeID')))
276279
.toBeVisible()
277280
.withTimeout(60000);
278-
let { label: ldkNodeId } = await element(
279-
by.id('LDKNodeID'),
280-
).getAttributes();
281+
const { label: ldkNodeId } = await element(by.id('LDKNodeID')).getAttributes();
281282
await element(by.id('NavigationClose')).tap();
282283

283284
// Get LND node id
@@ -331,12 +332,10 @@ d('Transfer', () => {
331332
await expect(element(by.id('Suggestion-lightningSettingUp'))).toBeVisible();
332333

333334
// check activity
334-
await element(by.id('WalletsScrollView')).scrollTo('bottom', NaN, 0.85);
335+
await element(by.id('WalletsScrollView')).scrollTo('bottom', 0);
335336
await expect(element(by.text('From Savings (±30m)'))).toBeVisible();
336337
await element(by.id('ActivityShort-1')).tap();
337338
await expect(element(by.text('Transfer (±30m)'))).toBeVisible();
338-
await element(by.id('NavigationClose')).tap();
339-
await element(by.id('WalletsScrollView')).scrollTo('top', NaN, 0.85);
340339

341340
// Mine 3 blocks
342341
await rpc.generateToAddress(3, await rpc.getNewAddress());
@@ -361,7 +360,7 @@ d('Transfer', () => {
361360
await expect(
362361
element(by.id('MoneyText').withAncestor(by.id('TotalSize'))),
363362
).toHaveText('20 000');
364-
await element(by.id('ChannelScrollView')).scrollTo('bottom', NaN, 0.1);
363+
await element(by.id('ChannelScrollView')).scrollTo('bottom', Number.NaN, 0.1);
365364
await expect(element(by.id('IsUsableYes'))).toBeVisible();
366365
await element(by.id('NavigationClose')).atIndex(0).tap();
367366

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)