From 4dece9031b1e86d3dfe4876d350dd764116349e2 Mon Sep 17 00:00:00 2001 From: gregory maertens Date: Tue, 13 Jun 2023 10:16:40 +0200 Subject: [PATCH 1/2] Allow confuring using DEPLOY_URL instead of DEPLOY_PRIME_URL Based on the work from Truebill:stevehollaar/deploy-url Added comments from PR preview Default to DEPLOY_PRIME_URL if not set or invalid environment variable setting. --- manifest.yml | 7 +++++++ src/onSuccess.js | 12 ++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/manifest.yml b/manifest.yml index adefa252..49b401fa 100644 --- a/manifest.yml +++ b/manifest.yml @@ -46,3 +46,10 @@ inputs: # NOTE: does not execute Netlify API redirects or functions - name: postBuild description: Run tests against the built static site + + # See Netlify docs for available values: + # https://docs.netlify.com/configure-builds/environment-variables/#deploy-urls-and-metadata + - name: deployUrlEnvVar + description: The Netlify environment variable containing the URL Cypress should set as the baseUrl to test + default: DEPLOY_PRIME_URL if not set or invalid value + diff --git a/src/onSuccess.js b/src/onSuccess.js index c19e221c..ea882745 100644 --- a/src/onSuccess.js +++ b/src/onSuccess.js @@ -18,10 +18,10 @@ module.exports = async ({ utils, inputs, constants }) => { const isLocal = constants.IS_LOCAL const siteName = process.env.SITE_NAME - const deployPrimeUrl = process.env.DEPLOY_PRIME_URL + const deployUrl = process.env[onSuccessInputs.deployUrlEnvVar] || process.env.DEPLOY_PRIME_URL; debug('onSuccess against %o', { siteName, - deployPrimeUrl, + deployUrl, isLocal, }) @@ -36,8 +36,8 @@ module.exports = async ({ utils, inputs, constants }) => { const errorCallback = utils.build.failPlugin.bind(utils.build) const summaryCallback = utils.status.show.bind(utils.status) - if (!deployPrimeUrl) { - return errorCallback('Missing DEPLOY_PRIME_URL') + if (!deployUrl) { + return errorCallback('Missing Deploy URL. Please set a valid Netlify environment variable to pull the deploy URL from to set as the baseUrl in your cypress configuration. For example, set deployUrlEnvVar to DEPLOY_PRIME_URL.\nSee https://docs.netlify.com/configure-builds/environment-variables/#deploy-urls-and-metadata for more details on which ENVs can be used') } const browser = onSuccessInputs.browser || DEFAULT_BROWSER @@ -69,9 +69,9 @@ module.exports = async ({ utils, inputs, constants }) => { const configFile = onSuccessInputs.configFile - console.log('testing deployed url %s', deployPrimeUrl) + console.log('testing deployed url %s', deployUrl) const results = await runCypressTests( - deployPrimeUrl, + deployUrl, record, spec, group, From 55c436d392ffbf97b6f9fab46050a814207a33dc Mon Sep 17 00:00:00 2001 From: gregory maertens Date: Tue, 13 Jun 2023 19:26:36 +0200 Subject: [PATCH 2/2] PR review changes --- manifest.yml | 2 +- src/onSuccess.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/manifest.yml b/manifest.yml index 49b401fa..c254c5c1 100644 --- a/manifest.yml +++ b/manifest.yml @@ -51,5 +51,5 @@ inputs: # https://docs.netlify.com/configure-builds/environment-variables/#deploy-urls-and-metadata - name: deployUrlEnvVar description: The Netlify environment variable containing the URL Cypress should set as the baseUrl to test - default: DEPLOY_PRIME_URL if not set or invalid value + default: DEPLOY_PRIME_URL diff --git a/src/onSuccess.js b/src/onSuccess.js index ea882745..d3b24187 100644 --- a/src/onSuccess.js +++ b/src/onSuccess.js @@ -18,7 +18,7 @@ module.exports = async ({ utils, inputs, constants }) => { const isLocal = constants.IS_LOCAL const siteName = process.env.SITE_NAME - const deployUrl = process.env[onSuccessInputs.deployUrlEnvVar] || process.env.DEPLOY_PRIME_URL; + const deployUrl = onSuccessInputs.deployUrlEnvVar ? process.env[onSuccessInputs.deployUrlEnvVar] : process.env.DEPLOY_PRIME_URL; debug('onSuccess against %o', { siteName, deployUrl,