From 2727131c7019be298f81de11f7f323b92a1511a5 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 5 Mar 2024 17:34:46 -0800 Subject: [PATCH] fix: test env vars --- .env.example | 2 ++ package.json | 3 ++- playwright.config.ts | 2 ++ tests/shared/constants/index.ts | 14 +++++++++++--- tests/subscribe.spec.ts | 2 +- yarn.lock | 5 +++++ 6 files changed, 23 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index 94985fe2..900b0d7d 100644 --- a/.env.example +++ b/.env.example @@ -4,3 +4,5 @@ VITE_PROJECT_ID="54..." VITE_VAPID_KEY="BdV...." VITE_SENTRY_DSN="https://96..." VITE_MIXPANEL_TOKEN="8dj...." +TEST_DAPP_PROJECT_ID="" +TEST_DAPP_PROJECT_SECRET="" diff --git a/package.json b/package.json index 88a514ab..05034125 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,7 @@ "workbox-core": "^6.5.4", "workbox-precaching": "^6.5.4", "workbox-routing": "^6.5.4", - "workbox-window": "^6.5.4" + "workbox-window": "^6.5.4", + "dotenv": "16.3.1" } } diff --git a/playwright.config.ts b/playwright.config.ts index 4b9f3ca7..d9405b88 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -1,4 +1,6 @@ +import { config } from 'dotenv' import { defineConfig, devices } from '@playwright/test' +config({ path: './.env' }) const baseURL = 'http://localhost:5173' diff --git a/tests/shared/constants/index.ts b/tests/shared/constants/index.ts index 5f250db1..e5c16296 100644 --- a/tests/shared/constants/index.ts +++ b/tests/shared/constants/index.ts @@ -9,12 +9,20 @@ export const DEFAULT_SESSION_PARAMS: SessionParams = { accept: true } +function getRequiredEnvVar(name: string): string { + const value = process.env[name] + if (!value) { + throw new Error(`Missing required environment variable: ${name}`) + } + return value +} + export const CUSTOM_TEST_DAPP = { description: 'Test description', icons: ['https://i.imgur.com/q9QDRXc.png'], name: 'Notify Swift Integration Tests Prod', appDomain: 'wc-notify-swift-integration-tests-prod.pages.dev', - projectSecret: process.env['TEST_DAPP_PROJECT_SECRET'], - projectId: process.env['TEST_DAPP_PROJECT_ID'], - messageType: 'f173f231-a45c-4dc0-aa5d-956eb04f7360' + projectSecret: getRequiredEnvVar('TEST_DAPP_PROJECT_SECRET'), + projectId: getRequiredEnvVar('TEST_DAPP_PROJECT_ID'), + notificationType: 'f173f231-a45c-4dc0-aa5d-956eb04f7360' } as const diff --git a/tests/subscribe.spec.ts b/tests/subscribe.spec.ts index beaeac06..b6413249 100644 --- a/tests/subscribe.spec.ts +++ b/tests/subscribe.spec.ts @@ -130,7 +130,7 @@ test('it should subscribe, receive messages and unsubscribe', async ({ accounts: [`eip155:1:${address}`], body: 'Test Body', title: 'Test Title', - type: CUSTOM_TEST_DAPP.messageType, + type: CUSTOM_TEST_DAPP.notificationType, url: CUSTOM_TEST_DAPP.appDomain, icon: CUSTOM_TEST_DAPP.icons[0], projectId: CUSTOM_TEST_DAPP.projectId, diff --git a/yarn.lock b/yarn.lock index b3dcd9d6..a1aade64 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4899,6 +4899,11 @@ domain-browser@^4.22.0: resolved "https://registry.npmjs.org/domain-browser/-/domain-browser-4.22.0.tgz" integrity sha512-IGBwjF7tNk3cwypFNH/7bfzBcgSCbaMOD3GsaY1AU/JRrnHnYgEM0+9kQt52iZxjNsjBtJYtao146V+f8jFZNw== +dotenv@16.3.1: + version "16.3.1" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.3.1.tgz#369034de7d7e5b120972693352a3bf112172cc3e" + integrity sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ== + duplexify@^4.1.2: version "4.1.2" resolved "https://registry.npmjs.org/duplexify/-/duplexify-4.1.2.tgz"