@dfinity/internet-identity-playwright 0.0.3 → 0.0.4

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
@@ -126,27 +126,35 @@ Make sure you have Docker installed on your machine ([Windows](https://docs.dock
126
126
  > [!NOTE]
127
127
  > For MacBooks with M processors, it is important to use Docker Desktop version 4.25.0 or later, ideally the latest available version.
128
128
 
129
- 2. Install Juno CLI:
129
+ 2. Start the Demo Application:
130
+
131
+ Navigate to the [demo](./demo) directory and start the application using Docker:
130
132
 
131
133
  ```bash
132
- npm i -g @junobuild/cli
134
+ cd demo
135
+ docker compose up
133
136
  ```
134
137
 
135
- 3. Start the Demo Application:
138
+ 4. Run the Tests:
136
139
 
137
- Navigate to the [demo](./demo) directory and start the application using the Juno CLI:
140
+ Return to the root directory and execute the tests:
138
141
 
139
142
  ```bash
140
- cd demo
141
- juno dev start
143
+ npm run e2e
142
144
  ```
143
145
 
144
- 4. Run the Tests:
146
+ ### Running Captcha Tests Locally
145
147
 
146
- Return to the root directory and execute the tests:
148
+ The default test suite validates the use of Internet Identity without captcha requirements. To test a flow with captcha, run the following command in the `demo` directory:
147
149
 
150
+ ```bash
151
+ docker compose -f docker-compose.captcha.yml up
148
152
  ```
149
- npm run e2e
153
+
154
+ Then, navigate to the root directory and run the dedicated test:
155
+
156
+ ```bash
157
+ npm run e2e:captcha
150
158
  ```
151
159
 
152
160
  ## 🚧 Limitations
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:i,context:o,browser:t}){this.page=i,this.browser=t,this.context=o}waitReady=async({url:i,canisterId:o,timeout:t=6e4})=>{let{host:e,protocol:c}=new URL(i),d=o!==void 0?this.browser.browserType().name()==="webkit"?`${c}//${e}?canisterId=${o}`:`${c}//${o}.${e.replace("127.0.0.1","localhost")}`:i,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 i=>{let o=this.context.waitForEvent("page");await this.page.locator(i?.selector??"[data-tid=login-button]").click();let t=await o;await a(t).toHaveTitle("Internet Identity"),await t.locator("#registerButton").click(),await t.locator("[data-action=construct-identity]").click(),await t.locator("input#captchaInput").fill("a"),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:i,identity:o})=>{let t=this.context.waitForEvent("page");await this.page.locator(i??"[data-tid=login-button]").click();let e=await t;await a(e).toHaveTitle("Internet Identity"),await e.locator(`[data-anchor-id='${o}']`).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:i,context:o},t)=>{let e=new n({page:s,context:o,browser:i});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: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};
@@ -38,10 +38,12 @@ export declare class InternetIdentityPage {
38
38
  *
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
+ * @param {boolean} [params.captcha] - Set to true if the II login flow requires a captcha.
41
42
  * @returns {Promise<number>} A promise that resolves to the new identity number.
42
43
  */
43
44
  signInWithNewIdentity: (params?: {
44
45
  selector?: string;
46
+ captcha?: boolean;
45
47
  }) => Promise<number>;
46
48
  /**
47
49
  * Signs in with an existing identity.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dfinity/internet-identity-playwright",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
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": {
@@ -46,20 +46,15 @@
46
46
  "build": "tsc --noEmit && node rmdir.mjs && node esbuild.mjs && npm run ts-declaration",
47
47
  "lint": "eslint --max-warnings 0 \"src/**/*\"",
48
48
  "dev": "npm --prefix demo run dev",
49
- "e2e": "NODE_ENV=development playwright test",
50
- "e2e:ci": "playwright test --reporter=html"
49
+ "e2e": "NODE_ENV=development playwright test --grep-invert 'captcha'",
50
+ "e2e:ci": "playwright test --reporter=html --grep-invert 'captcha'",
51
+ "e2e:captcha": "NODE_ENV=development playwright test e2e/captcha.spec",
52
+ "e2e:captcha:ci": "playwright test --reporter=html e2e/captcha.spec"
51
53
  },
52
54
  "devDependencies": {
55
+ "@dfinity/eslint-config-oisy-wallet": "^0.0.6",
53
56
  "@types/node": "^20.14.2",
54
- "@typescript-eslint/eslint-plugin": "^6.20.0",
55
57
  "esbuild": "^0.23.1",
56
- "eslint": "^8.57.0",
57
- "eslint-config-prettier": "^9.1.0",
58
- "eslint-config-standard-with-typescript": "^43.0.1",
59
- "eslint-plugin-import": "^2.29.1",
60
- "eslint-plugin-n": "^16.6.2",
61
- "eslint-plugin-prettier": "^5.1.3",
62
- "eslint-plugin-promise": "^6.1.1",
63
58
  "prettier": "^3.3.3",
64
59
  "prettier-plugin-organize-imports": "^4.0.0",
65
60
  "typescript": "^5.3.3"