@junobuild/emulator-playwright 0.0.2 → 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/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- var a={auth:{signInDev:"btn-sign-in-dev",switchDevAccount:"btn-switch-account-dev",inputDevIdentifier:"input-dev-identifier",continueDevAccount:"btn-continue-dev"},launchpad:{launch:"btn-launch-first-satellite",launchExtraSatellite:"btn-launch-extra-satellite",actions:"btn-open-actions"},createSatellite:{create:"btn-create-satellite",input:"input-satellite-name",website:"input-radio-satellite-website",application:"input-radio-satellite-application",continue:"btn-continue-overview"},satelliteOverview:{visit:"link-visit-satellite",copySatelliteId:"btn-copy-satellite-id"},navbar:{openWallet:"btn-open-wallet",getIcp:"btn-get-icp",getCycles:"btn-get-cycles"},createAnalytics:{navLink:"link-analytics-dashboard",launch:"btn-launch-analytics",create:"btn-create-analytics",close:"btn-close-analytics-wizard"},wizard:{closeInsufficientFunds:"btn-close-insufficient-funds"}};import{test as b}from"@playwright/test";import{assertNonNullish as A,notEmptyString as O}from"@dfinity/utils";import{execute as l,spawn as I}from"@junobuild/cli-tools";import{statSync as k}from"node:fs";import{readdir as _,readFile as T,writeFile as B}from"node:fs/promises";import{join as f}from"node:path";var C={command:"juno",args:[]},E=["--mode","development","--headless"],m=class{command;commandArgs;constructor({command:t}){let{command:e,args:o}=t??C;this.command=e,this.commandArgs=o}buildArgs(t){return[...this.commandArgs,...t,...E]}};var u=f(process.cwd(),"juno.config.ts"),p=class n extends m{#t;constructor({satelliteId:t,command:e}){super({command:e}),this.#t=t}static initWithoutLogin(t){return new n(t)}static async initWithEmulatorLogin(t){let e=new n(t);return await e.initConfig(),await e.loginWithEmulator(),await e.applyConfig(),e}async initConfig(){let t=await T(u,"utf-8");t=t.replace("<DEV_SATELLITE_ID>",this.#t),await B(u,t,"utf-8")}async revertConfig(){let t=await T(u,"utf-8");t=t.replace(this.#t,"<DEV_SATELLITE_ID>"),await B(u,t,"utf-8")}async toggleSatelliteId({satelliteId:t}){await this.revertConfig(),this.#t=t,await this.initConfig()}async loginWithEmulator(){await l({command:this.command,args:this.buildArgs(["login","--emulator"])})}async applyConfig(){await l({command:this.command,args:this.buildArgs(["config","apply","--force"])})}async logout(){await l({command:this.command,args:this.buildArgs(["logout"])})}async clearHosting(){await l({command:this.command,args:this.buildArgs(["hosting","clear"])})}async deployHosting({clear:t}){await l({command:this.command,args:this.buildArgs(["hosting","deploy",...t?["--clear"]:[]])})}async createSnapshot({target:t}){await l({command:this.command,args:this.buildArgs(["snapshot","create","--target",t])})}async restoreSnapshot({target:t}){await l({command:this.command,args:this.buildArgs(["snapshot","restore","--target",t])})}async deleteSnapshot({target:t}){await l({command:this.command,args:this.buildArgs(["snapshot","delete","--target",t])})}async downloadSnapshot({target:t}){return await l({command:this.command,args:this.buildArgs(["snapshot","download","--target",t])}),await this.getSnapshotFsFolder()}async getSnapshotFsFolder(){let t=f(process.cwd(),".snapshots"),e=await _(t,{withFileTypes:!0}),[o]=e.filter(i=>i.isDirectory()).map(({name:i})=>{let r=f(t,i),{birthtimeMs:c}=k(r);return{path:r,time:c}}).sort((i,r)=>r.time-i.time);return A(o),{snapshotFolder:o.path}}async uploadSnapshot({target:t,folder:e}){await l({command:this.command,args:this.buildArgs(["snapshot","upload","--target",t,"--dir",e])})}async listSnapshot({target:t}){let e="";await I({command:this.command,args:this.buildArgs(["snapshot","list","--target",t]),stdout:r=>e+=r,silentErrors:!0});let[o,i]=e.split("Snapshot found:");return{snapshotId:O(i)?i.trim():void 0}}async whoami(){let t="";await I({command:this.command,args:this.buildArgs(["whoami"]),stdout:y=>t+=y,silentErrors:!0});let[e,o,i,r]=t.split(" "),[c]=r.split(`
2
- `);return{accessKey:c.replace("\x1B[32m","").replace("\x1B[39m","").trim()}}async close({cleanUp:t}={cleanUp:!0}){t&&await this.cleanUp(),await this.logout()}async cleanUp(){await this.revertConfig()}};import{notEmptyString as F}from"@dfinity/utils";import{PrincipalTextSchema as U}from"@dfinity/zod-schemas";import{expect as s}from"@playwright/test";var P={timeout:15e3},g={timeout:2*15e3},Q={timeout:4*15e3};var d=class{page;context;browser;constructor({page:t,context:e,browser:o}){this.page=t,this.context=e,this.browser=o}async close(){await this.page.close()}};import{expect as x}from"@playwright/test";var h=class extends d{async reload({title:t}={title:"Juno / Satellite"}){await x.poll(async()=>(await this.page.reload({waitUntil:"load"}),await this.page.title()),{...g,intervals:[1e3,2e3,1e4]}).toBe(t)}async assertScreenshot(){await x(this.page).toHaveScreenshot({fullPage:!0})}};var w=class n extends d{constructor(t){super(t)}static async initWithSignIn(t){let e=new n(t);return await e.goto(),await e.signIn(),e}async goto({path:t}={path:"/"}){await this.page.goto(t)}async signIn(){await s(this.page.getByTestId(a.auth.switchDevAccount)).toBeVisible(g),await this.page.getByTestId(a.auth.switchDevAccount).click(),await s(this.page.getByTestId(a.auth.inputDevIdentifier)).toBeVisible(),await this.page.getByTestId(a.auth.inputDevIdentifier).fill(crypto.randomUUID().replaceAll("-","")),await s(this.page.getByTestId(a.auth.continueDevAccount)).toBeVisible(),await this.page.getByTestId(a.auth.continueDevAccount).click()}async createSatellite(t){await s(this.page.getByTestId(a.launchpad.launch)).toBeVisible(g),await this.page.getByTestId(a.launchpad.launch).click(),await this.createSatelliteWizard(t)}async openCreateAdditionalSatelliteWizard(t){await s(this.page.getByTestId(a.launchpad.actions)).toBeVisible(g),await this.page.getByTestId(a.launchpad.actions).click(),await s(this.page.getByTestId(a.launchpad.launchExtraSatellite)).toBeVisible(g),await this.page.getByTestId(a.launchpad.launchExtraSatellite).click(),await this.createSatelliteWizard(t)}async createSatelliteWizard({kind:t}){await s(this.page.getByTestId(a.createSatellite.create)).toBeVisible({timeout:15e3}),await this.page.getByTestId(a.createSatellite.input).fill("Test"),await this.page.getByTestId(a.createSatellite[t]).click(),await this.page.getByTestId(a.createSatellite.create).click(),await s(this.page.getByTestId(a.createSatellite.continue)).toBeVisible(g),await this.page.getByTestId(a.createSatellite.continue).click()}async visitSatelliteSite({title:t}={title:"Juno / Satellite"}){await s(this.page.getByTestId(a.satelliteOverview.visit)).toBeVisible(g);let e=this.context.waitForEvent("page");await this.page.getByTestId(a.satelliteOverview.visit).click();let o=await e;return await s(o).toHaveTitle(t),new h({page:o,browser:this.browser,context:this.context})}async getCycles(){await s(this.page.getByTestId(a.navbar.openWallet)).toBeVisible(),await this.page.getByTestId(a.navbar.openWallet).click(),await s(this.page.getByTestId(a.navbar.getCycles)).toBeVisible(),await this.page.getByTestId(a.navbar.getCycles).click(),await s(this.page.getByText("330.010 TCycles")).toBeVisible({timeout:65e3})}async copySatelliteID(){await s(this.page.getByTestId(a.satelliteOverview.copySatelliteId)).toBeVisible(),await this.page.getByTestId(a.satelliteOverview.copySatelliteId).click();let t=await this.page.evaluate(()=>navigator.clipboard.readText());return s(F(t)).toBeTruthy(),s(U.safeParse(t).success).toBeTruthy(),t}async addSatelliteAdminAccessKey({satelliteId:t,accessKey:e}){await this.goto({path:`/satellite/?s=${t}&tab=setup`});let o=this.page.locator("button",{hasText:"Add an access key"});await s(o).toBeVisible(P),await o.click();let i=this.page.locator("form");await i.getByRole("radio",{name:/enter one manually/i}).check();let r=i.getByLabel("Access Key ID");await s(r).toBeEnabled(),await r.fill(e),await i.locator('select[name="scope"]').selectOption("admin");let c=i.getByRole("button",{name:/^submit$/i});await s(c).toBeEnabled(),await c.click(),await s(this.page.getByText("Access Key Added")).toBeVisible(P)}};var ut=({satelliteKind:n,cli:t})=>{let e,o;return b.beforeAll(async({playwright:i})=>{b.setTimeout(12e4);let r=await i.chromium.launch(),c=await r.newContext(),v=await c.newPage();e=await w.initWithSignIn({page:v,context:c,browser:r}),await e.createSatellite({kind:n});let y=await e.copySatelliteID();o=await p.initWithEmulatorLogin({satelliteId:y,...t})}),b.afterAll(async()=>{let i=await Promise.allSettled([e.close(),o.close()]);if(i.find(({status:r})=>r==="rejected"))throw console.error(i),new Error("Failed to close test suite!")}),()=>({consolePage:e,cliPage:o})};import{assertNonNullish as W}from"@dfinity/utils";import{test as N}from"@playwright/test";import{readJunoConfig as V}from"@junobuild/config-loader";var D="juno.config",J={filename:D},L=async n=>await V({...J,config:e=>typeof e=="function"?e(n):e}),S=async n=>{try{return{ok:await L(n)}}catch(t){return{err:t}}};var It=()=>{let n,t;return N.beforeAll(async()=>{let e=await S({mode:"development"});if("err"in e)throw new Error("Failed to read config");let{ok:o}=e,i=o.satellite.ids?.development;W(i),n=i,t=await p.initWithoutLogin({satelliteId:n})}),()=>({satelliteId:n,cliPage:t})};export{p as CliPage,w as ConsolePage,h as SatellitePage,ut as initEmulatorSuite,It as initSatelliteSuite,a as testIds};
1
+ var a={auth:{signInDev:"btn-sign-in-dev",switchDevAccount:"btn-switch-account-dev",inputDevIdentifier:"input-dev-identifier",continueDevAccount:"btn-continue-dev"},launchpad:{launch:"btn-launch-first-satellite",launchExtraSatellite:"btn-launch-extra-satellite",actions:"btn-open-actions"},createSatellite:{create:"btn-create-satellite",input:"input-satellite-name",website:"input-radio-satellite-website",application:"input-radio-satellite-application",continue:"btn-continue-overview"},satelliteOverview:{visit:"link-visit-satellite",copySatelliteId:"btn-copy-satellite-id"},navbar:{openWallet:"btn-open-wallet",getIcp:"btn-get-icp",getCycles:"btn-get-cycles"},createAnalytics:{navLink:"link-analytics-dashboard",launch:"btn-launch-analytics",create:"btn-create-analytics",close:"btn-close-analytics-wizard"},wizard:{closeInsufficientFunds:"btn-close-insufficient-funds"}};import{test as v}from"@playwright/test";import{assertNonNullish as A,notEmptyString as O}from"@dfinity/utils";import{execute as l,spawn as T}from"@junobuild/cli-tools";import{statSync as k}from"node:fs";import{readdir as _,readFile as B,writeFile as x}from"node:fs/promises";import{join as f}from"node:path";var S={command:"juno",args:[]},E=["--mode","development","--headless"],m=class{command;commandArgs;constructor({command:t}){let{command:e,args:o}=t??S;this.command=e,this.commandArgs=o}buildArgs(t){return[...this.commandArgs,...t,...E]}};var u=f(process.cwd(),"juno.config.ts"),p=class n extends m{#t;constructor({satelliteId:t,command:e}){super({command:e}),this.#t=t}static initWithoutLogin(t){return new n(t)}static async initWithEmulatorLogin(t){let e=new n(t);return await e.initConfig(),await e.loginWithEmulator(),await e.applyConfig(),e}async initConfig(){let t=await B(u,"utf-8");t=t.replace("<DEV_SATELLITE_ID>",this.#t),await x(u,t,"utf-8")}async revertConfig(){let t=await B(u,"utf-8");t=t.replace(this.#t,"<DEV_SATELLITE_ID>"),await x(u,t,"utf-8")}async toggleSatelliteId({satelliteId:t}){await this.revertConfig(),this.#t=t,await this.initConfig()}async loginWithEmulator(){await l({command:this.command,args:this.buildArgs(["login","--emulator"])})}async applyConfig(){await l({command:this.command,args:this.buildArgs(["config","apply","--force"])})}async logout(){await l({command:this.command,args:this.buildArgs(["logout"])})}async clearHosting(){await l({command:this.command,args:this.buildArgs(["hosting","clear"])})}async deployHosting({clear:t}){await l({command:this.command,args:this.buildArgs(["hosting","deploy",...t?["--clear"]:[]])})}async createSnapshot({target:t}){await l({command:this.command,args:this.buildArgs(["snapshot","create","--target",t])})}async restoreSnapshot({target:t}){await l({command:this.command,args:this.buildArgs(["snapshot","restore","--target",t])})}async deleteSnapshot({target:t}){await l({command:this.command,args:this.buildArgs(["snapshot","delete","--target",t])})}async downloadSnapshot({target:t}){return await l({command:this.command,args:this.buildArgs(["snapshot","download","--target",t])}),await this.getSnapshotFsFolder()}async getSnapshotFsFolder(){let t=f(process.cwd(),".snapshots"),e=await _(t,{withFileTypes:!0}),[o]=e.filter(i=>i.isDirectory()).map(({name:i})=>{let r=f(t,i),{birthtimeMs:c}=k(r);return{path:r,time:c}}).sort((i,r)=>r.time-i.time);return A(o),{snapshotFolder:o.path}}async uploadSnapshot({target:t,folder:e}){await l({command:this.command,args:this.buildArgs(["snapshot","upload","--target",t,"--dir",e])})}async listSnapshot({target:t}){let e="";await T({command:this.command,args:this.buildArgs(["snapshot","list","--target",t]),stdout:r=>e+=r,silentErrors:!0});let[o,i]=e.split("Snapshot found:");return{snapshotId:O(i)?i.trim():void 0}}async whoami(){let t="";await T({command:this.command,args:this.buildArgs(["whoami"]),stdout:y=>t+=y,silentErrors:!0});let[e,o,i,r]=t.split(" "),[c]=r.split(`
2
+ `);return{accessKey:c.replace("\x1B[32m","").replace("\x1B[39m","").trim()}}async close({cleanUp:t}={cleanUp:!0}){t&&await this.cleanUp(),await this.logout()}async cleanUp(){await this.revertConfig()}};import{notEmptyString as F}from"@dfinity/utils";import{PrincipalTextSchema as U}from"@dfinity/zod-schemas";import{expect as s}from"@playwright/test";var P={timeout:15e3},g={timeout:2*15e3},Q={timeout:4*15e3};var d=class{page;context;browser;constructor({page:t,context:e,browser:o}){this.page=t,this.context=e,this.browser=o}async close(){await this.page.close()}};import{expect as b}from"@playwright/test";var h=class extends d{async reload({title:t}={title:"Juno / Satellite"}){await b.poll(async()=>(await this.page.reload({waitUntil:"load"}),await this.page.title()),{...g,intervals:[1e3,2e3,1e4]}).toBe(t)}async assertScreenshot(){await b(this.page).toHaveScreenshot({fullPage:!0})}async assertContainText(t){await b(this.page.locator("body")).toContainText(t)}};var w=class n extends d{constructor(t){super(t)}static async initWithSignIn(t){let e=new n(t);return await e.goto(),await e.signIn(),e}async goto({path:t}={path:"/"}){await this.page.goto(t)}async signIn(){await s(this.page.getByTestId(a.auth.switchDevAccount)).toBeVisible(g),await this.page.getByTestId(a.auth.switchDevAccount).click(),await s(this.page.getByTestId(a.auth.inputDevIdentifier)).toBeVisible(),await this.page.getByTestId(a.auth.inputDevIdentifier).fill(crypto.randomUUID().replaceAll("-","")),await s(this.page.getByTestId(a.auth.continueDevAccount)).toBeVisible(),await this.page.getByTestId(a.auth.continueDevAccount).click()}async createSatellite(t){await s(this.page.getByTestId(a.launchpad.launch)).toBeVisible(g),await this.page.getByTestId(a.launchpad.launch).click(),await this.createSatelliteWizard(t)}async openCreateAdditionalSatelliteWizard(t){await s(this.page.getByTestId(a.launchpad.actions)).toBeVisible(g),await this.page.getByTestId(a.launchpad.actions).click(),await s(this.page.getByTestId(a.launchpad.launchExtraSatellite)).toBeVisible(g),await this.page.getByTestId(a.launchpad.launchExtraSatellite).click(),await this.createSatelliteWizard(t)}async createSatelliteWizard({kind:t}){await s(this.page.getByTestId(a.createSatellite.create)).toBeVisible({timeout:15e3}),await this.page.getByTestId(a.createSatellite.input).fill("Test"),await this.page.getByTestId(a.createSatellite[t]).click(),await this.page.getByTestId(a.createSatellite.create).click(),await s(this.page.getByTestId(a.createSatellite.continue)).toBeVisible(g),await this.page.getByTestId(a.createSatellite.continue).click()}async visitSatelliteSite({title:t}={title:"Juno / Satellite"}){await s(this.page.getByTestId(a.satelliteOverview.visit)).toBeVisible(g);let e=this.context.waitForEvent("page");await this.page.getByTestId(a.satelliteOverview.visit).click();let o=await e;return await s(o).toHaveTitle(t),new h({page:o,browser:this.browser,context:this.context})}async getCycles(){await s(this.page.getByTestId(a.navbar.openWallet)).toBeVisible(),await this.page.getByTestId(a.navbar.openWallet).click(),await s(this.page.getByTestId(a.navbar.getCycles)).toBeVisible(),await this.page.getByTestId(a.navbar.getCycles).click(),await s(this.page.getByText("330.010 TCycles")).toBeVisible({timeout:65e3})}async copySatelliteID(){await s(this.page.getByTestId(a.satelliteOverview.copySatelliteId)).toBeVisible(),await this.page.getByTestId(a.satelliteOverview.copySatelliteId).click();let t=await this.page.evaluate(()=>navigator.clipboard.readText());return s(F(t)).toBeTruthy(),s(U.safeParse(t).success).toBeTruthy(),t}async addSatelliteAdminAccessKey({satelliteId:t,accessKey:e}){await this.goto({path:`/satellite/?s=${t}&tab=setup`});let o=this.page.locator("button",{hasText:"Add an access key"});await s(o).toBeVisible(P),await o.click();let i=this.page.locator("form");await i.getByRole("radio",{name:/enter one manually/i}).check();let r=i.getByLabel("Access Key ID");await s(r).toBeEnabled(),await r.fill(e),await i.locator('select[name="scope"]').selectOption("admin");let c=i.getByRole("button",{name:/^submit$/i});await s(c).toBeEnabled(),await c.click(),await s(this.page.getByText("Access Key Added")).toBeVisible(P)}};var ut=({satelliteKind:n,cli:t})=>{let e,o;return v.beforeAll(async({playwright:i})=>{v.setTimeout(12e4);let r=await i.chromium.launch(),c=await r.newContext(),I=await c.newPage();e=await w.initWithSignIn({page:I,context:c,browser:r}),await e.createSatellite({kind:n});let y=await e.copySatelliteID();o=await p.initWithEmulatorLogin({satelliteId:y,command:t?.command})}),v.afterAll(async()=>{let i=await Promise.allSettled([e.close(),o.close({cleanUp:t?.cleanUp??!0})]);if(i.find(({status:r})=>r==="rejected"))throw console.error(i),new Error("Failed to close test suite!")}),()=>({consolePage:e,cliPage:o})};import{assertNonNullish as W}from"@dfinity/utils";import{test as N}from"@playwright/test";import{readJunoConfig as V}from"@junobuild/config-loader";var D="juno.config",J={filename:D},L=async n=>await V({...J,config:e=>typeof e=="function"?e(n):e}),C=async n=>{try{return{ok:await L(n)}}catch(t){return{err:t}}};var It=()=>{let n,t;return N.beforeAll(async()=>{let e=await C({mode:"development"});if("err"in e)throw new Error("Failed to read config");let{ok:o}=e,i=o.satellite.ids?.development;W(i),n=i,t=await p.initWithoutLogin({satelliteId:n})}),()=>({satelliteId:n,cliPage:t})};export{p as CliPage,w as ConsolePage,h as SatellitePage,ut as initEmulatorSuite,It as initSatelliteSuite,a as testIds};
@@ -7,6 +7,8 @@ interface EmulatorSuitePages {
7
7
  }
8
8
  export declare const initEmulatorSuite: ({ satelliteKind, cli }: {
9
9
  satelliteKind: "website" | "application";
10
- cli?: CliContextPageParams;
10
+ cli?: CliContextPageParams & {
11
+ cleanUp?: boolean;
12
+ };
11
13
  }) => (() => EmulatorSuitePages);
12
14
  export {};
@@ -4,4 +4,5 @@ export declare class SatellitePage extends BrowserPage {
4
4
  title: string;
5
5
  }): Promise<void>;
6
6
  assertScreenshot(): Promise<void>;
7
+ assertContainText(text: string): Promise<void>;
7
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@junobuild/emulator-playwright",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "A Playwright library to simplify the integration of the Juno Console and CLI in E2E tests.",
5
5
  "license": "MIT",
6
6
  "repository": {