From 873ed3fe4445b1b9e0434649e43fe4b903f16a6a Mon Sep 17 00:00:00 2001 From: JunichiSugiura Date: Tue, 13 Aug 2024 19:02:33 +0200 Subject: [PATCH] Target preview keychain when running playwright on ci --- .github/workflows/test.yml | 2 ++ .../starknet-react-next/playwright.config.ts | 5 +++-- examples/starknet-react-next/src/app/page.tsx | 20 ++++++++++++------ .../components/providers/StarknetProvider.tsx | 21 +++++++++---------- package.json | 2 +- turbo.json | 4 +++- 6 files changed, 33 insertions(+), 21 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d5cc5fa9c..3043fda9e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -76,6 +76,8 @@ jobs: - name: Install Playwright Browsers run: pnpm example:next e2e:deps - name: Run Playwright tests + env: + BRANCH_NAME: ${{ github.head_ref }} run: pnpm e2e:ci - uses: actions/upload-artifact@v4 if: always() diff --git a/examples/starknet-react-next/playwright.config.ts b/examples/starknet-react-next/playwright.config.ts index 3a31323cb..c208f2c9b 100644 --- a/examples/starknet-react-next/playwright.config.ts +++ b/examples/starknet-react-next/playwright.config.ts @@ -1,5 +1,6 @@ import { defineConfig, devices } from "@playwright/test"; -import { KEYCHAIN_URL } from "components/providers/StarknetProvider"; + +const CI_BASE_URL = `https://cartridge-starknet-react-next-git-${process.env.BRANCH_NAME}.preview.cartridge.gg`; export default defineConfig({ testDir: "./tests", @@ -8,7 +9,7 @@ export default defineConfig({ retries: process.env.CI ? 2 : 0, reporter: process.env.CI ? "dot" : "list", use: { - baseURL: process.env.CI ? KEYCHAIN_URL : "http://localhost:3002", + baseURL: process.env.CI ? CI_BASE_URL : "http://localhost:3002", trace: "on-first-retry", }, projects: [ diff --git a/examples/starknet-react-next/src/app/page.tsx b/examples/starknet-react-next/src/app/page.tsx index d6791dec8..0f241a3bd 100644 --- a/examples/starknet-react-next/src/app/page.tsx +++ b/examples/starknet-react-next/src/app/page.tsx @@ -1,4 +1,4 @@ -'use client' +"use client"; import { TransferEth } from "components/TransferEth"; import { ConnectWallet } from "components/ConnectWallet"; @@ -13,8 +13,8 @@ import { useEffect, useState } from "react"; export default function Home() { const [debug, setDebug] = useState(false); useEffect(() => { - setDebug(!!new URLSearchParams(window.location.search).get("debug")) - }, []) + setDebug(!!new URLSearchParams(window.location.search).get("debug")); + }, []); return (
@@ -28,9 +28,17 @@ export default function Home() { {debug && (

Keychain URL: {KEYCHAIN_URL}

-

NEXT_PUBLIC_VERCEL_ENV: {String(process.env.NEXT_PUBLIC_VERCEL_ENV)}

-

NEXT_PUBLIC_VERCEL_BRANCH_URL: {String(process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL)}

-

NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL: {String(process.env.NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL)}

+

+ NEXT_PUBLIC_VERCEL_ENV: {String(process.env.NEXT_PUBLIC_VERCEL_ENV)} +

+

+ NEXT_PUBLIC_VERCEL_BRANCH_URL:{" "} + {String(process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL)} +

+

+ NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL:{" "} + {String(process.env.NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL)} +

)} diff --git a/examples/starknet-react-next/src/components/providers/StarknetProvider.tsx b/examples/starknet-react-next/src/components/providers/StarknetProvider.tsx index cf96f37dd..ca8268c0e 100644 --- a/examples/starknet-react-next/src/components/providers/StarknetProvider.tsx +++ b/examples/starknet-react-next/src/components/providers/StarknetProvider.tsx @@ -25,16 +25,6 @@ const ETH_TOKEN_ADDRESS = // const PAPER_TOKEN_ADDRESS = // "0x0410466536b5ae074f7fea81e5533b8134a9fa08b3dd077dd9db08f64997d113"; -export const KEYCHAIN_URL = !process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL || - process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL.split(".")[0] === - "cartridge-starknet-react-next" - ? process.env.XFRAME_URL - : "https://" + - (process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL ?? "").replace( - "cartridge-starknet-react-next", - "keychain", - ); - const cartridge = new CartridgeConnector( [ { @@ -61,7 +51,16 @@ const cartridge = new CartridgeConnector( }, ], { - url: KEYCHAIN_URL, + url: + !process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL || + process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL.split(".")[0] === + "cartridge-starknet-react-next" + ? process.env.XFRAME_URL + : "https://" + + (process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL ?? "").replace( + "cartridge-starknet-react-next", + "keychain", + ), rpc: process.env.NEXT_PUBLIC_RPC_SEPOLIA, paymaster: { caller: shortString.encodeShortString("ANY_CALLER"), diff --git a/package.json b/package.json index 7348edbe2..690e1e163 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "dev": "turbo dev", "e2e": "turbo dev e2e", "e2e:ui": "turbo dev e2e:ui", - "e2e:ci": "turbo e2e", + "e2e:ci": "turbo e2e:ci", "lint": "turbo lint", "format": "turbo format", "format:check": "turbo format:check", diff --git a/turbo.json b/turbo.json index 2c25c1f85..fac4d0514 100644 --- a/turbo.json +++ b/turbo.json @@ -12,16 +12,18 @@ }, "dev": { "persistent": true, - "dependsOn": ["^build:deps", "^dev"], + "dependsOn": ["^build:deps"], "outputs": [".next/**", "!.next/cache/**"] }, "lint": {}, "format": {}, "format:check": {}, "e2e": { + "dependsOn": ["^build:deps"], "persistent": true }, "e2e:ui": { + "dependsOn": ["^build:deps"], "persistent": true } }