Add conditional checks for E2E and billing tests (#34)

* Add conditional checks for E2E and billing tests

Added a conditional check to only run the End-to-End (E2E) workflow if the environment variable ENABLE_E2E_JOB is set to true. Also added a similar check in the Playwright configuration for running billing tests only if the ENABLE_BILLING_TESTS environment variable is 'true'. This will allow more control over the tests run in different environments.
This commit is contained in:
Giancarlo Buomprisco
2024-06-12 16:51:28 +08:00
committed by GitHub
parent cbd8941c37
commit ca5e02f509
3 changed files with 24 additions and 4 deletions

View File

@@ -49,11 +49,13 @@ jobs:
name: ⚫️ Test name: ⚫️ Test
timeout-minutes: 8 timeout-minutes: 8
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: ${{ vars.ENABLE_E2E_JOB == 'true' }}
env: env:
SUPABASE_SERVICE_ROLE_KEY: ${{ secrets.SUPABASE_SERVICE_ROLE_KEY }} SUPABASE_SERVICE_ROLE_KEY: ${{ secrets.SUPABASE_SERVICE_ROLE_KEY }}
SUPABASE_DB_WEBHOOK_SECRET: ${{ secrets.SUPABASE_DB_WEBHOOK_SECRET }} SUPABASE_DB_WEBHOOK_SECRET: ${{ secrets.SUPABASE_DB_WEBHOOK_SECRET }}
STRIPE_SECRET_KEY: ${{ secrets.STRIPE_SECRET_KEY }} STRIPE_SECRET_KEY: ${{ secrets.STRIPE_SECRET_KEY }}
STRIPE_WEBHOOK_SECRET: ${{ secrets.STRIPE_WEBHOOK_SECRET }} STRIPE_WEBHOOK_SECRET: ${{ secrets.STRIPE_WEBHOOK_SECRET }}
ENABLE_BILLING_TESTS: ${{ vars.ENABLE_BILLING_TESTS }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
@@ -106,14 +108,16 @@ jobs:
run: | run: |
docker run --add-host=host.docker.internal:host-gateway --rm -it --name=stripe -d stripe/stripe-cli:latest listen --forward-to http://host.docker.internal:3000/api/billing/webhook --skip-verify --api-key "$STRIPE_SECRET_KEY" --log-level debug & docker run --add-host=host.docker.internal:host-gateway --rm -it --name=stripe -d stripe/stripe-cli:latest listen --forward-to http://host.docker.internal:3000/api/billing/webhook --skip-verify --api-key "$STRIPE_SECRET_KEY" --log-level debug &
- name: Production Build (test env) - name: Run Next.js Production Build (test env)
run: pnpm --filter web build:test run: pnpm --filter web build:test
- name: Next.js Server - name: Run Next.js Server
run: pnpm --filter web start:test & run: pnpm --filter web start:test &
- name: Run Playwright tests - name: Run Playwright tests
run: pnpm run test run: |
echo "Running Playwright tests. Billing tests enabled: $ENABLE_BILLING_TESTS"
pnpm run test
- name: Run Supabase tests - name: Run Supabase tests
run: pnpm --filter web supabase:test run: pnpm --filter web supabase:test

View File

@@ -1,5 +1,18 @@
import { defineConfig, devices } from '@playwright/test'; import { defineConfig, devices } from '@playwright/test';
const enableBillingTests = process.env.ENABLE_BILLING_TESTS === 'true';
const testIgnore: string[] = [];
if (!enableBillingTests) {
console.log(
`Billing tests are disabled. To enable them, set the environment variable ENABLE_BILLING_TESTS=true.`,
`Current value: "${process.env.ENABLE_BILLING_TESTS}"`
);
testIgnore.push('*-billing.spec.ts');
}
/** /**
* Read environment variables from file. * Read environment variables from file.
* https://github.com/motdotla/dotenv * https://github.com/motdotla/dotenv
@@ -20,6 +33,8 @@ export default defineConfig({
workers: process.env.CI ? 1 : undefined, workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ /* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html', reporter: 'html',
/* Ignore billing tests if the environment variable is not set. */
testIgnore,
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: { use: {
/* Base URL to use in actions like `await page.goto('/')`. */ /* Base URL to use in actions like `await page.goto('/')`. */

View File

@@ -36,7 +36,8 @@
"NEXT_PUBLIC_BASELIME_KEY", "NEXT_PUBLIC_BASELIME_KEY",
"NEXT_PUBLIC_SUPABASE_URL", "NEXT_PUBLIC_SUPABASE_URL",
"NEXT_PUBLIC_SUPABASE_ANON_KEY", "NEXT_PUBLIC_SUPABASE_ANON_KEY",
"SUPABASE_SERVICE_ROLE_KEY" "SUPABASE_SERVICE_ROLE_KEY",
"ENABLE_BILLING_TESTS"
], ],
"tasks": { "tasks": {
"topo": { "topo": {