From c433a5f96bb8543cc468ef6bc2b9410df22fc8c0 Mon Sep 17 00:00:00 2001 From: JunichiSugiura Date: Wed, 14 Aug 2024 15:10:13 +0200 Subject: [PATCH] Target preview keychain when running playwright on ci --- .github/workflows/test.yml | 6 +++++- examples/starknet-react-next/package.json | 3 ++- .../starknet-react-next/playwright.config.ts | 12 +++++++++-- examples/starknet-react-next/src/app/page.tsx | 20 +++++++++++++------ package.json | 10 +++++----- pnpm-lock.yaml | 3 +++ turbo.json | 6 ++---- 7 files changed, 41 insertions(+), 19 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d5cc5fa9c..5c74043c2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -76,7 +76,11 @@ jobs: - name: Install Playwright Browsers run: pnpm example:next e2e:deps - name: Run Playwright tests - run: pnpm e2e:ci + run: | + cat <examples/starknet-react-next/.env + BRANCH_NAME=${{ github.head_ref }} + EOF + pnpm e2e:ci - uses: actions/upload-artifact@v4 if: always() with: diff --git a/examples/starknet-react-next/package.json b/examples/starknet-react-next/package.json index ce964701a..898803d1a 100644 --- a/examples/starknet-react-next/package.json +++ b/examples/starknet-react-next/package.json @@ -5,7 +5,7 @@ "scripts": { "dev": "next dev -p 3002", "build": "next build", - "e2e:deps": "npx playwright install --with-deps", + "e2e:deps": "pnpm playwright install --with-deps", "e2e": "playwright test", "e2e:ui": "pnpm e2e --ui", "start": "next start -p 3002", @@ -32,6 +32,7 @@ "@types/react": "^18.2.21", "@types/react-dom": "^18.2.7", "autoprefixer": "^10.4.18", + "dotenv": "^16.4.5", "eslint": "^8.23.0", "eslint-config-next": "^12.2.5", "postcss": "^8.4.35", diff --git a/examples/starknet-react-next/playwright.config.ts b/examples/starknet-react-next/playwright.config.ts index 3a31323cb..bc72b8987 100644 --- a/examples/starknet-react-next/playwright.config.ts +++ b/examples/starknet-react-next/playwright.config.ts @@ -1,5 +1,13 @@ import { defineConfig, devices } from "@playwright/test"; -import { KEYCHAIN_URL } from "components/providers/StarknetProvider"; +import dotenv from "dotenv"; +import path from "path"; + +dotenv.config({ path: path.resolve(__dirname, ".env") }); +console.log("!!!!!!!!!!!!!!!!!", process.env.CI); + +const CI_BASE_URL = process.env.BRANCH_NAME + ? `https://cartridge-starknet-react-next-git-${process.env.BRANCH_NAME}.preview.cartridge.gg` + : "https://cartridge-starknet-react-next.preview.cartridge.gg"; export default defineConfig({ testDir: "./tests", @@ -8,7 +16,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/package.json b/package.json index 7348edbe2..d679a66c4 100644 --- a/package.json +++ b/package.json @@ -4,11 +4,11 @@ "private": true, "scripts": { "preinstall": "npx only-allow pnpm", - "build": "turbo build", - "dev": "turbo dev", - "e2e": "turbo dev e2e", - "e2e:ui": "turbo dev e2e:ui", - "e2e:ci": "turbo e2e", + "build": "turbo build:deps build", + "dev": "turbo build:deps dev", + "e2e": "turbo build:deps dev e2e", + "e2e:ui": "turbo build:deps dev e2e:ui", + "e2e:ci": "turbo build:deps e2e", "lint": "turbo lint", "format": "turbo format", "format:check": "turbo format:check", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index df1ac6e18..a3cb8374d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -103,6 +103,9 @@ importers: autoprefixer: specifier: ^10.4.18 version: 10.4.19(postcss@8.4.38) + dotenv: + specifier: ^16.4.5 + version: 16.4.5 eslint: specifier: ^8.23.0 version: 8.57.0 diff --git a/turbo.json b/turbo.json index 2c25c1f85..f01643634 100644 --- a/turbo.json +++ b/turbo.json @@ -12,15 +12,13 @@ }, "dev": { "persistent": true, - "dependsOn": ["^build:deps", "^dev"], + "dependsOn": ["^build:deps"], "outputs": [".next/**", "!.next/cache/**"] }, "lint": {}, "format": {}, "format:check": {}, - "e2e": { - "persistent": true - }, + "e2e": {}, "e2e:ui": { "persistent": true }