Skip to content

Commit

Permalink
Setup Playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
JunichiSugiura committed Aug 7, 2024
1 parent 27751cc commit 653223d
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 5 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# name: End-to-End tests
# on:
# push:
# branches: [main]
# pull_request:
# branches: [main]
# jobs:
# test:
# timeout-minutes: 60
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-node@v4
# with:
# node-version: lts/*
# - name: Install dependencies
# run: npm install -g pnpm && pnpm install
# - name: Install Playwright Browsers
# run: pnpm exec playwright install --with-deps
# - name: Run Playwright tests
# run: pnpm exec playwright test
# - uses: actions/upload-artifact@v4
# if: always()
# with:
# name: playwright-report
# path: playwright-report/
# retention-days: 30
5 changes: 5 additions & 0 deletions examples/starknet-react-next/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
2 changes: 2 additions & 0 deletions examples/starknet-react-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"scripts": {
"dev": "next dev -p 3002",
"build": "next build",
"test": "playwright test",
"start": "next start -p 3002",
"lint": "next lint",
"format": "prettier --write ."
Expand All @@ -23,6 +24,7 @@
},
"devDependencies": {
"@cartridge/tsconfig": "workspace:^",
"@playwright/test": "^1.44.1",
"@types/node": "^20.6.0",
"@types/react": "^18.2.21",
"@types/react-dom": "^18.2.7",
Expand Down
33 changes: 33 additions & 0 deletions examples/starknet-react-next/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { defineConfig, devices } from "@playwright/test";

export default defineConfig({
testDir: "./tests",
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: "html",
use: {
baseURL: "http://localhost:3002",
trace: "on-first-retry",
},
projects: [
{
name: "chromium",
use: { ...devices["Desktop Chrome"] },
},
// {
// name: "firefox",
// use: { ...devices["Desktop Firefox"] },
// },
// {
// name: "webkit",
// use: { ...devices["Desktop Safari"] },
// },
],
webServer: {
command: "cd ../../ && pnpm dev",
url: "http://localhost:3002",
reuseExistingServer: !process.env.CI,
},
});
44 changes: 44 additions & 0 deletions examples/starknet-react-next/tests/example.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { test, expect, CDPSession } from "@playwright/test";

let client: CDPSession;
let authenticatorId: string;

test.beforeEach(async ({ page }) => {
client = await page.context().newCDPSession(page);
await client.send("WebAuthn.enable");
const result = await client.send("WebAuthn.addVirtualAuthenticator", {
options: {
protocol: "ctap2",
transport: "internal",
hasResidentKey: true,
hasUserVerification: true,
isUserVerified: true,
automaticPresenceSimulation: true,
},
});
authenticatorId = result.authenticatorId;

await page.goto("/");
});

test("has title", async ({ page }) => {
await expect(page).toHaveTitle(/StarkNet ❤️ React/);
});

test.describe("Connect", () => {
test.describe("Log in", () => {
test("should allow me to login and connect to Controller", async ({
page,
}) => {
await page.getByRole("button", { name: "Connect" }).click();
const modal = page.frameLocator("#cartridge-modal");
await expect(
modal.getByText("Play with Cartridge Controller"),
).toBeVisible();
await modal.getByPlaceholder("Username").fill("test-0");
await modal.getByRole("button", { name: "LOG IN" }).click();

await expect(page.getByText("Address: ")).toBeVisible();
});
});
});
49 changes: 44 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 653223d

Please sign in to comment.