From 0c56c9bb8f372b2e7afaf2c60ad9398286614458 Mon Sep 17 00:00:00 2001 From: Chris Raible Date: Tue, 7 Jan 2025 20:03:39 -0800 Subject: [PATCH] Fixed browser tests running in docker compose (#21974) ref https://linear.app/ghost/issue/ENG-1968/get-browser-tests-working-in-docker - When running browser tests in docker compose, the `stripe listen` command was not outputting the API key from the environment, because it's expecting that you've already run `stripe login` to authenticate with stripe. It only outputs the API key in the command line in CI. - This isn't convenient/practical to do in docker, and it's much easier to supply the API key as an environment variable, so this changes the logic to use the API key from the command line when running in docker _or_ CI. --- compose.yml | 2 ++ ghost/core/test/e2e-browser/fixtures/ghost-test.js | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/compose.yml b/compose.yml index 16382d1560..cd68a04918 100644 --- a/compose.yml +++ b/compose.yml @@ -13,6 +13,8 @@ services: volumes: - .:/home/ghost tty: true + env_file: + - .env depends_on: - mysql - redis diff --git a/ghost/core/test/e2e-browser/fixtures/ghost-test.js b/ghost/core/test/e2e-browser/fixtures/ghost-test.js index 6f60df27c1..b23e0cb389 100644 --- a/ghost/core/test/e2e-browser/fixtures/ghost-test.js +++ b/ghost/core/test/e2e-browser/fixtures/ghost-test.js @@ -11,7 +11,10 @@ const Stripe = require('stripe').Stripe; const configUtils = require('../../utils/configUtils'); const startWebhookServer = (port) => { - const command = `stripe listen --forward-connect-to http://127.0.0.1:${port}/members/webhooks/stripe/ ${process.env.CI ? `--api-key ${process.env.STRIPE_SECRET_KEY}` : ''}`.trim(); + const isCI = process.env.CI; + const isDocker = process.env.COMPOSE_PROFILES === 'full'; + const stripeSecretKey = process.env.STRIPE_SECRET_KEY; + const command = `stripe listen --forward-connect-to http://127.0.0.1:${port}/members/webhooks/stripe/ ${isDocker || isCI ? `--api-key ${stripeSecretKey}` : ''}`.trim(); const webhookServer = spawn(command.split(' ')[0], command.split(' ').slice(1)); // Adding event listeners here seems to prevent heisenbug where webhooks aren't received @@ -22,7 +25,10 @@ const startWebhookServer = (port) => { }; const getWebhookSecret = async () => { - const command = `stripe listen --print-secret ${process.env.CI ? `--api-key ${process.env.STRIPE_SECRET_KEY}` : ''}`.trim(); + const isCI = process.env.CI; + const isDocker = process.env.COMPOSE_PROFILES === 'full'; + const stripeSecretKey = process.env.STRIPE_SECRET_KEY; + const command = `stripe listen --print-secret ${isDocker || isCI ? `--api-key ${stripeSecretKey}` : ''}`.trim(); const webhookSecret = (await promisify(exec)(command)).stdout; return webhookSecret.toString().trim(); };