This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 154
/
global_flask.ts
68 lines (61 loc) · 1.88 KB
/
global_flask.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
import path from "path";
import * as dappeteer from "../src";
import {
InjectableContext,
LOCAL_PREFUNDED_MNEMONIC,
PASSWORD,
TestContext,
} from "./constant";
import { deployContract, startLocalEthereum, buildSnaps } from "./deploy";
export const mochaHooks = {
async beforeAll(this: Mocha.Context): Promise<void> {
this.timeout(100000);
const ethereum = await startLocalEthereum({
wallet: {
mnemonic: LOCAL_PREFUNDED_MNEMONIC,
defaultBalance: 100,
},
});
const { browser, metaMask, metaMaskPage } = await dappeteer.bootstrap({
// optional, else it will use a default seed
seed: LOCAL_PREFUNDED_MNEMONIC,
password: PASSWORD,
automation:
(process.env.AUTOMATION as "puppeteer" | "playwright") ?? "puppeteer",
metaMaskVersion:
process.env.METAMASK_VERSION || dappeteer.RECOMMENDED_METAMASK_VERSION,
metaMaskFlask: true,
});
const snapServers = await buildSnaps();
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const contract = await deployContract(ethereum.provider);
const context: InjectableContext = {
ethereum: ethereum,
provider: ethereum.provider,
browser,
snapServers: snapServers,
metaMask,
metaMaskPage,
flask: true,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
contract,
};
Object.assign(this, context);
},
async afterAll(this: TestContext): Promise<void> {
await this.browser.close();
await this.ethereum.close();
},
async afterEach(this: TestContext): Promise<void> {
if (this.currentTest.state === "failed") {
await this.metaMaskPage.screenshot(
path.resolve(
__dirname,
`../${
process.env.AUTOMATION ?? "puppeteer"
}_flask_${this.currentTest.fullTitle()}.png`
)
);
}
},
};