Skip to content

Commit

Permalink
chore: allow e2e fixtures to override site id
Browse files Browse the repository at this point in the history
  • Loading branch information
serhalp committed Jul 2, 2024
1 parent 287177a commit a8d8fca
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions tests/utils/create-e2e-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import { cpus } from 'os'
import pLimit from 'p-limit'
import { setNextVersionInFixture } from './next-version-helpers.mjs'

// This is the netlify testing application
export const SITE_ID = process.env.NETLIFY_SITE_ID ?? 'ee859ce9-44a7-46be-830b-ead85e445e53'
// https://app.netlify.com/sites/next-runtime-testing
const DEFAULT_SITE_ID = 'ee859ce9-44a7-46be-830b-ead85e445e53'
export const SITE_ID = process.env.NETLIFY_SITE_ID ?? DEFAULT_SITE_ID
const NEXT_VERSION = process.env.NEXT_VERSION || 'latest'

export interface DeployResult {
Expand All @@ -39,6 +40,10 @@ interface E2EConfig {
* Some fixtures might pin to non-latest CLI versions. This is used to verify the used CLI version matches expected one
*/
expectedCliVersion?: string
/**
* Site ID to deploy to. Defaults to the `NETLIFY_SITE_ID` environment variable or a default site.
*/
siteId?: string
}

/**
Expand Down Expand Up @@ -258,12 +263,12 @@ async function verifyFixture(isolatedFixtureRoot: string, { expectedCliVersion }

async function deploySite(
isolatedFixtureRoot: string,
{ packagePath, cwd = '' }: E2EConfig,
{ packagePath, cwd = '', siteId = SITE_ID }: E2EConfig,
): Promise<DeployResult> {
console.log(`🚀 Building and deploying site...`)

const outputFile = 'deploy-output.txt'
let cmd = `npx ntl deploy --build --site ${SITE_ID}`
let cmd = `npx ntl deploy --build --site ${siteId}`

if (packagePath) {
cmd += ` --filter ${packagePath}`
Expand All @@ -273,7 +278,7 @@ async function deploySite(
await execaCommand(cmd, { cwd: siteDir, all: true }).pipeAll?.(join(siteDir, outputFile))
const output = await readFile(join(siteDir, outputFile), 'utf-8')

const [url] = new RegExp(/https:.+runtime-testing\.netlify\.app/gm).exec(output) || []
const [url] = new RegExp(/https:.+\.netlify\.app/gm).exec(output) || []
if (!url) {
throw new Error('Could not extract the URL from the build logs')
}
Expand Down

0 comments on commit a8d8fca

Please sign in to comment.