@dfinity/internet-identity-playwright 0.0.5 → 2.0.0

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
@@ -84,6 +84,16 @@ testWithII('should sign-in with a new user when II requires a captcha', async ({
84
84
  });
85
85
  ```
86
86
 
87
+ Similarly, you can test a flow where Internet Identity requires the user to create and save a passkey:
88
+
89
+ ```javascript
90
+ testWithII('should sign in with a new user when II requires a passkey', async ({page, iiPage}) => {
91
+ await page.goto('/');
92
+
93
+ await iiPage.signInWithNewIdentity({createPasskey: true});
94
+ });
95
+ ```
96
+
87
97
  ### 3. Wait for Internet Identity (optional)
88
98
 
89
99
  You might encounter scenarios where you perform tests against a local replica started in parallel with your tests, commonly when automating the tests in a CI environment. The library also exposes a fixture that lets you wait for Internet Identity to be ready.
@@ -167,6 +177,20 @@ Then, navigate to the root directory and run the dedicated test:
167
177
  npm run e2e:captcha
168
178
  ```
169
179
 
180
+ ### Running Required Passkey Tests Locally
181
+
182
+ The default test suite validates the use of the latest Internet Identity, which does not require the user to complete a specific step to create a passkey. To test a flow where passkey creation is required, run the following command from the `demo` directory:
183
+
184
+ ```bash
185
+ docker compose -f docker-compose.passkey.yml up
186
+ ```
187
+
188
+ Then, navigate to the root directory and run the dedicated test:
189
+
190
+ ```bash
191
+ npm run e2e:passkey
192
+ ```
193
+
170
194
  ## 🚧 Limitations
171
195
 
172
196
  Currently, the library's fixtures cannot be implemented with Playwright's ability to [load existing authenticated state](https://playwright.dev/docs/auth). Playwright currently does not support IndexedDB for such features. This limitation is tracked in their [GitHub issue #11164](https://github.com/microsoft/playwright/issues/11164).
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{test as I}from"@playwright/test";import{expect as a}from"@playwright/test";var n=class{page;browser;context;constructor({page:o,context:i,browser:t}){this.page=o,this.browser=t,this.context=i}waitReady=async({url:o,canisterId:i,timeout:t=6e4})=>{let{host:e,protocol:c}=new URL(o),d=i!==void 0?this.browser.browserType().name()==="webkit"?`${c}//${e}?canisterId=${i}`:`${c}//${i}.${e.replace("127.0.0.1","localhost")}`:o,p=async()=>{try{return(await this.page.goto(d,{waitUntil:"domcontentloaded"}))?.ok()??!1}catch{return!1}},l=500,u=async({count:r})=>{if(await p())return"ready";let w=r-1;return w===0?"timeout":(await new Promise(m=>setTimeout(m,l)),await u({count:w}))},y=await u({count:t/l});a(y).toEqual("ready"),await a(this.page).toHaveTitle("Internet Identity");let g=this.page.locator("#registerButton");a(g).not.toBeNull()};signInWithNewIdentity=async o=>{let i=this.context.waitForEvent("page");await this.page.locator(o?.selector??"[data-tid=login-button]").click();let t=await i;await a(t).toHaveTitle("Internet Identity"),await t.locator("#registerButton").click(),await t.locator("[data-action=construct-identity]").click(),o?.captcha===!0&&(await t.locator("input#captchaInput").fill("a",{timeout:1e4}),await t.locator("#confirmRegisterButton").click());let e=await t.locator("#userNumber").textContent();return a(e).not.toBeNull(),await t.locator("#displayUserContinue").click(),await t.waitForEvent("close"),a(t.isClosed()).toBe(!0),parseInt(e)};signInWithIdentity=async({selector:o,identity:i})=>{let t=this.context.waitForEvent("page");await this.page.locator(o??"[data-tid=login-button]").click();let e=await t;await a(e).toHaveTitle("Internet Identity"),await e.locator(`[data-anchor-id='${i}']`).click(),await e.waitForEvent("close"),a(e.isClosed()).toBe(!0)}};import{expect as $}from"@playwright/test";var v=I.extend({iiPage:async({page:s,browser:o,context:i},t)=>{let e=new n({page:s,context:i,browser:o});await t(e)}});export{n as InternetIdentityPage,$ as expect,v as testWithII};
1
+ import{test as I}from"@playwright/test";import{expect as a}from"@playwright/test";var n=class{page;browser;context;constructor({page:e,context:i,browser:t}){this.page=e,this.browser=t,this.context=i}waitReady=async({url:e,canisterId:i,timeout:t=6e4})=>{let{host:o,protocol:c}=new URL(e),d=i!==void 0?this.browser.browserType().name()==="webkit"?`${c}//${o}?canisterId=${i}`:`${c}//${i}.${o.replace("127.0.0.1","localhost")}`:e,y=async()=>{try{return(await this.page.goto(d,{waitUntil:"domcontentloaded"}))?.ok()??!1}catch{return!1}},l=500,u=async({count:r})=>{if(await y())return"ready";let w=r-1;return w===0?"timeout":(await new Promise(m=>setTimeout(m,l)),await u({count:w}))},p=await u({count:t/l});a(p).toEqual("ready"),await a(this.page).toHaveTitle("Internet Identity");let g=this.page.locator("#registerButton");a(g).not.toBeNull()};signInWithNewIdentity=async e=>{let i=this.context.waitForEvent("page");await this.page.locator(e?.selector??"[data-tid=login-button]").click();let t=await i;await a(t).toHaveTitle("Internet Identity"),await t.locator("#registerButton").click(),e?.createPasskey===!0&&await t.locator("[data-action=construct-identity]").click(),e?.captcha===!0&&(await t.locator("input#captchaInput").fill("a",{timeout:1e4}),await t.locator("#confirmRegisterButton").click());let o=await t.locator("#userNumber").textContent();return a(o).not.toBeNull(),await t.locator("#displayUserContinue").click(),await t.waitForEvent("close"),a(t.isClosed()).toBe(!0),parseInt(o)};signInWithIdentity=async({selector:e,identity:i})=>{let t=this.context.waitForEvent("page");await this.page.locator(e??"[data-tid=login-button]").click();let o=await t;await a(o).toHaveTitle("Internet Identity"),await o.locator(`[data-anchor-id='${i}']`).click(),await o.waitForEvent("close"),a(o.isClosed()).toBe(!0)}};import{expect as $}from"@playwright/test";var k=I.extend({iiPage:async({page:s,browser:e,context:i},t)=>{let o=new n({page:s,context:i,browser:e});await t(o)}});export{n as InternetIdentityPage,$ as expect,k as testWithII};
@@ -30,8 +30,8 @@ export declare class InternetIdentityPage {
30
30
  */
31
31
  waitReady: ({ url: rootUrl, canisterId, timeout }: {
32
32
  url: string;
33
- canisterId?: string | undefined;
34
- timeout?: number | undefined;
33
+ canisterId?: string;
34
+ timeout?: number;
35
35
  }) => Promise<void>;
36
36
  /**
37
37
  * Signs in and create a new user.
@@ -39,11 +39,13 @@ export declare class InternetIdentityPage {
39
39
  * @param {Object} [params] - The optional arguments for the sign-in method.
40
40
  * @param {string} [params.selector] - The selector for the login button. Defaults to [data-tid=login-button].
41
41
  * @param {boolean} [params.captcha] - Set to true if the II login flow requires a captcha.
42
+ * @param {boolean} [params.createPasskey] - Set to true if the II login flow requires the user to create a passkey.
42
43
  * @returns {Promise<number>} A promise that resolves to the new identity number.
43
44
  */
44
45
  signInWithNewIdentity: (params?: {
45
46
  selector?: string;
46
47
  captcha?: boolean;
48
+ createPasskey?: boolean;
47
49
  }) => Promise<number>;
48
50
  /**
49
51
  * Signs in with an existing identity.
@@ -53,7 +55,7 @@ export declare class InternetIdentityPage {
53
55
  * @returns {Promise<void>} A promise that resolves when the sign-in process is complete.
54
56
  */
55
57
  signInWithIdentity: ({ selector, identity }: {
56
- selector?: string | undefined;
58
+ selector?: string;
57
59
  identity: number;
58
60
  }) => Promise<void>;
59
61
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dfinity/internet-identity-playwright",
3
- "version": "0.0.5",
3
+ "version": "2.0.0",
4
4
  "description": "A Playwright library to simplify the integration of Internet Identity authentication in E2E tests.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -44,25 +44,27 @@
44
44
  "format:check": "prettier --check .",
45
45
  "ts-declaration": "tsc --emitDeclarationOnly --outDir dist/types",
46
46
  "build": "tsc --noEmit && node rmdir.mjs && node esbuild.mjs && npm run ts-declaration",
47
- "lint": "eslint --max-warnings 0 \"src/**/*\"",
47
+ "lint": "eslint --max-warnings 0",
48
48
  "dev": "npm --prefix demo run dev",
49
- "e2e": "NODE_ENV=development playwright test --grep-invert 'captcha'",
50
- "e2e:ci": "playwright test --reporter=html --grep-invert 'captcha'",
49
+ "e2e": "NODE_ENV=development playwright test e2e/login.spec",
50
+ "e2e:ci": "playwright test --reporter=html e2e/login.spec",
51
51
  "e2e:captcha": "NODE_ENV=development playwright test e2e/captcha.spec",
52
- "e2e:captcha:ci": "playwright test --reporter=html e2e/captcha.spec"
52
+ "e2e:captcha:ci": "playwright test --reporter=html e2e/captcha.spec",
53
+ "e2e:passkey": "NODE_ENV=development playwright test e2e/passkey.spec",
54
+ "e2e:passkey:ci": "playwright test --reporter=html e2e/passkey.spec"
53
55
  },
54
56
  "devDependencies": {
55
- "@dfinity/eslint-config-oisy-wallet": "^0.0.6",
56
- "@types/node": "^22.13.4",
57
- "esbuild": "^0.25.0",
58
- "prettier": "^3.5.1",
57
+ "@dfinity/eslint-config-oisy-wallet": "^0.1.10",
58
+ "@types/node": "^22.15.18",
59
+ "esbuild": "^0.25.4",
60
+ "prettier": "^3.5.3",
59
61
  "prettier-plugin-organize-imports": "^4.1.0",
60
- "typescript": "^5.3.3"
62
+ "typescript": "^5.7.3"
61
63
  },
62
64
  "engines": {
63
65
  "node": ">=22"
64
66
  },
65
67
  "peerDependencies": {
66
- "@playwright/test": "^1.44.1"
68
+ "@playwright/test": "^1.52.0"
67
69
  }
68
70
  }