-
Notifications
You must be signed in to change notification settings - Fork 65
/
cypress.config.ts
73 lines (61 loc) · 2.32 KB
/
cypress.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { defineConfig } from "cypress";
import { ImapFlow } from 'imapflow';
// Cypress doesn't work very well with cross-origin testing (different domains).
// In order to test dApp connection, we need to get WalletConnect uri from the dApp page and pass it to the Wallet.
// Because of that - we have this variable here, and we set/get its value through setWcUrl/getWcUrl tasks in the tests.
let wcUrl;
export default defineConfig({
e2e: {
baseUrl: 'http://localhost:3000/',
experimentalSessionAndOrigin: true,
includeShadowDom: true,
// macbook 13
viewportWidth: 1280,
viewportHeight: 800,
setupNodeEvents(on, config) {
on("task", {
"get-confirm-code": async () => {
const [{ email }] = config.env.ACCOUNTS;
const client = new ImapFlow({
host: 'mail.devlabs.bg',
port: 993,
secure: true,
auth: {
user: email,
pass: config.env.EMAIL_PASSWORD,
},
logger: false,
});
return new Promise(async resolve => {
// Wait until client connects and authorizes
await client.connect();
await client.mailboxOpen('INBOX');
// It returns all the emails' sequences (email index) matching the search criteria
const confirmEmails = await client.search({
from: '[email protected]',
subject: 'Transaction confirmation code',
});
// Most recent email is the email having the highest sequence
const mostRecentConfEmail = Math.max(...confirmEmails);
// Get most recent email content
const { content } = await client.download(mostRecentConfEmail);
content.on('data', chunk => {
const body = chunk.toString();
// Extract the code from the following msg 'Please copy this confirmation code to sign it: {code}.'
const code = body.match(/Please copy this confirmation code to sign it: (.*)\./)[1];
resolve(code);
});
// Log out and close connection
await client.logout();
});
},
setWcUrl: url => {
return (wcUrl = url);
},
getWcUrl: () => {
return wcUrl;
},
});
},
},
});