w3wallets 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  ![License](https://img.shields.io/badge/License-MIT-yellow.svg)
4
4
  [![npm version](https://img.shields.io/npm/v/w3wallets.svg)](https://www.npmjs.com/package/w3wallets)
5
5
  ![CodeQL](https://github.com/Maksandre/w3wallets/actions/workflows/github-code-scanning/codeql/badge.svg?branch=main)
6
+ [![Tests](https://github.com/Maksandre/w3wallets/actions/workflows/playwright.yml/badge.svg?branch=main)](https://github.com/Maksandre/w3wallets/actions/workflows/playwright.yml)
6
7
 
7
8
  Web3 wallets for Playwright.
8
9
 
@@ -16,6 +17,11 @@ npm install -D w3wallets
16
17
 
17
18
  The `Backpack` and the `Polkadot{.js}` wallets are currently supported.
18
19
 
20
+ <p align="center">
21
+ <img src="https://raw.githubusercontent.com/coral-xyz/backpack/refs/heads/master/assets/backpack.png" alt="Backpack Logo" width="60"/>
22
+ <img src="https://polkadot.js.org/logo.svg" alt="Polkadot JS Logo" width="60"/>
23
+ </p>
24
+
19
25
  #### 1. Download wallets
20
26
 
21
27
  ```sh
@@ -26,54 +32,33 @@ The unzipped files should be stored in the `.w3wallets/<wallet-name>` directory.
26
32
 
27
33
  #### 2. Wrap your fixture `withWallets`
28
34
 
35
+ Install needed wallets into the chromium using `withWallets`.
36
+
29
37
  ```ts
38
+ // your-fixture.ts
39
+ import { withWallets } from "w3wallets";
30
40
  import { test as base } from "@playwright/test";
31
- import { withWallets } from "../src/withWallets";
32
-
33
- // Specify one or many wallets that should be installed in the browser
34
- const test = withWallets(base, "backpack", "polkadotJS");
35
-
36
- test("has title", async ({ page, backpack }) => {
37
- await page.goto("https://playwright.dev/");
38
41
 
39
- const privateKey =
40
- "4wDJd9Ds5ueTdS95ReAZGSBVkjMcNKbgZk47xcmqzpUJjCt7VoB2Cs7hqwXWRnopzXqE4mCP6BEDHCYrFttEcBw2";
41
-
42
- await backpack.onboard("Eclipse", privateKey);
42
+ export const test = withWallets(base, 'backpack', 'polkadotJS').extend<BaseFixture>({
43
+ magic: (_, use) => use(42),
43
44
  });
44
- ```
45
-
46
- ## Run tests
47
45
 
48
- To work on this project in VS Code, make sure you open the project's root directory.
46
+ type BaseFixture = {
47
+ magic: number;
48
+ };
49
49
 
50
- 0. Create the `.env` using `.env.example` as a reference.
51
- 1. Install dependencies
52
-
53
- ```sh
54
- yarn
50
+ export { expect } from "@playwright/test";
55
51
  ```
56
52
 
57
- 2. Install Chrome browser
58
-
59
- ```sh
60
- npx playwright install chromium
61
- ```
53
+ #### 3. Use the installed wallets in tests
62
54
 
63
- 3. Download wallet extensions
64
-
65
- ```sh
66
- npx w3wallets backpack polkadotJS
67
- ```
68
-
69
- 4. Start UI
70
-
71
- ```sh
72
- yarn start:ui
73
- ```
55
+ ```ts
56
+ import { test } from "./your-fixture";
74
57
 
75
- 5. Run Tests with Playwright
58
+ test("Can use wallet", async ({ page, backpack }) => {
59
+ const privateKey =
60
+ "4wDJd9Ds5ueTdS95ReAZGSBVkjMcNKbgZk47xcmqzpUJjCt7VoB2Cs7hqwXWRnopzXqE4mCP6BEDHCYrFttEcBw2";
76
61
 
77
- ```sh
78
- yarn test
62
+ await backpack.onboard("Eclipse", privateKey);
63
+ });
79
64
  ```
package/dist/index.js CHANGED
@@ -98,10 +98,10 @@ var Backpack = class extends Wallet {
98
98
  await ignoreButton.click();
99
99
  }
100
100
  async approve() {
101
- await this.page.getByText("Approve").click();
101
+ await this.page.getByText("Approve", { exact: true }).click();
102
102
  }
103
103
  async deny() {
104
- await this.page.getByText("Deny").click();
104
+ await this.page.getByText("Deny", { exact: true }).click();
105
105
  }
106
106
  };
107
107
 
@@ -191,13 +191,13 @@ function withWallets(test, ...config) {
191
191
  extensionPaths.push(polkadotJSPath);
192
192
  }
193
193
  const context = await import_test3.chromium.launchPersistentContext(userDataDir, {
194
- headless: false,
194
+ headless: testInfo.project.use.headless ?? true,
195
+ channel: "chromium",
195
196
  args: [
196
197
  `--disable-extensions-except=${extensionPaths.join(",")}`,
197
198
  `--load-extension=${extensionPaths.join(",")}`
198
199
  ]
199
200
  });
200
- await context.waitForEvent("serviceworker");
201
201
  while (context.serviceWorkers().length < extensionPaths.length) {
202
202
  await sleep(1e3);
203
203
  }
package/dist/index.mjs CHANGED
@@ -64,10 +64,10 @@ var Backpack = class extends Wallet {
64
64
  await ignoreButton.click();
65
65
  }
66
66
  async approve() {
67
- await this.page.getByText("Approve").click();
67
+ await this.page.getByText("Approve", { exact: true }).click();
68
68
  }
69
69
  async deny() {
70
- await this.page.getByText("Deny").click();
70
+ await this.page.getByText("Deny", { exact: true }).click();
71
71
  }
72
72
  };
73
73
 
@@ -157,13 +157,13 @@ function withWallets(test, ...config) {
157
157
  extensionPaths.push(polkadotJSPath);
158
158
  }
159
159
  const context = await chromium.launchPersistentContext(userDataDir, {
160
- headless: false,
160
+ headless: testInfo.project.use.headless ?? true,
161
+ channel: "chromium",
161
162
  args: [
162
163
  `--disable-extensions-except=${extensionPaths.join(",")}`,
163
164
  `--load-extension=${extensionPaths.join(",")}`
164
165
  ]
165
166
  });
166
- await context.waitForEvent("serviceworker");
167
167
  while (context.serviceWorkers().length < extensionPaths.length) {
168
168
  await sleep(1e3);
169
169
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "w3wallets",
3
3
  "description": "browser wallets for playwright",
4
- "version": "0.2.0",
4
+ "version": "0.2.2",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "homepage": "https://github.com/Maksandre/w3wallets",
@@ -31,8 +31,9 @@
31
31
  ],
32
32
  "bin": "./src/scripts/download.js",
33
33
  "scripts": {
34
- "start:ui": "yarn workspace @w3wallets/test-app dev",
35
- "test": "npx playwright test",
34
+ "start:ui": "yarn workspace @w3wallets/test-app buildAndStart",
35
+ "download-wallets": "npx w3wallets backpack polkadotJS",
36
+ "test": "npx playwright test --project=ci",
36
37
  "build": "tsup",
37
38
  "clean": "rm -rf dist",
38
39
  "check-format": "prettier --check .",
@@ -43,10 +44,6 @@
43
44
  "changeset": "npx changeset",
44
45
  "local-release": "changeset version && changeset publish"
45
46
  },
46
- "dependencies": {
47
- "follow-redirects": "^1.15.9",
48
- "unzip-crx": "^0.2.0"
49
- },
50
47
  "devDependencies": {
51
48
  "@arethetypeswrong/cli": "^0.17.2",
52
49
  "@changesets/cli": "^2.27.11",