-
Notifications
You must be signed in to change notification settings - Fork 176
/
playwrightWithFixtures.js
41 lines (38 loc) · 1.9 KB
/
playwrightWithFixtures.js
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
const base = require("@playwright/test");
const { BN } = require("bn.js");
const { WALLET_NETWORK } = require("./constants");
const { getBankAccount } = require("./utils/account");
const nearApiJsConnection = require("./utils/connectionSingleton");
const E2eTestAccount = require("./utils/E2eTestAccount");
const { getTestAccountSeedPhrase, getWorkerAccountId } = require("./utils/helpers");
const SelfReloadingE2eTestAccount = require("./utils/SelfReloadingE2eTestAccount");
module.exports = base;
module.exports.test = base.test.extend({
bankAccount: [
async ({}, use, workerInfo) => {
const bankAccount = await getBankAccount();
const workerBankAccountId = getWorkerAccountId(workerInfo.workerIndex);
const workerBankAccountSeedphrase = getTestAccountSeedPhrase(workerBankAccountId);
const workerBankAccount = await new (nearApiJsConnection.config.networkId !== WALLET_NETWORK.MAINNET
? SelfReloadingE2eTestAccount
: E2eTestAccount)(
workerBankAccountId,
workerBankAccountSeedphrase,
bankAccount.nearApiJsAccount
).connectOrCreate();
const { total: startBalance } = await workerBankAccount.getUpdatedBalance();
process.env.workerBankStartBalance = startBalance;
await use(workerBankAccount);
const { total: endBalance } = await workerBankAccount.getUpdatedBalance();
const amountSpent = new BN(process.env.workerBankStartBalance).sub(new BN(endBalance)).toString();
console.log(
JSON.stringify([
"WorkerExpenseLog",
{ workerBankAccount: workerBankAccount.accountId, amountSpent, workerIndex: workerInfo.workerIndex },
])
);
await workerBankAccount.delete();
},
{ scope: "worker", auto: true },
],
});