diff --git a/e2e/infra/infra.ts b/e2e/infra/infra.ts index e606820c..16a1f4d0 100644 --- a/e2e/infra/infra.ts +++ b/e2e/infra/infra.ts @@ -61,7 +61,6 @@ export async function deployE2EInfrastructure({ return { waitForFrontDoor, testInfo: { - resourceGroup, frontdoorUrl, functionAppUrl: `https://${functionAppHost}`, websiteUrl: website.url, diff --git a/e2e/infra/scripts/deploy.ts b/e2e/infra/scripts/deploy.ts index 713f5a64..e1e2be0c 100644 --- a/e2e/infra/scripts/deploy.ts +++ b/e2e/infra/scripts/deploy.ts @@ -1,5 +1,5 @@ import { createResourceGroup, removeResourceGroup } from '../resourceGroup' -import { writeTestInfo } from '../../shared/testInfo' +import { addTestInfo, initTestInfo } from '../../shared/testInfo' import { deployE2EInfrastructure, DeployE2EInfrastructureOptions, DeployE2EInfrastructureResult } from '../infra' import { destroyTestInfo } from '../destroyTestInfo' @@ -10,6 +10,8 @@ function getId() { async function main() { const resourceGroup = await createResourceGroup() + initTestInfo(resourceGroup) + const results: DeployE2EInfrastructureResult[] = [] try { @@ -32,11 +34,11 @@ async function main() { const result = await deployE2EInfrastructure(variant) results.push(result) + + addTestInfo(result.testInfo) } await Promise.all(results.map((r) => r.waitForFrontDoor())) - - writeTestInfo(results.map((r) => r.testInfo)) } catch (error) { for (const result of results) { await destroyTestInfo(result.testInfo) diff --git a/e2e/infra/scripts/destroy.ts b/e2e/infra/scripts/destroy.ts index 31386731..dc4d1ab7 100644 --- a/e2e/infra/scripts/destroy.ts +++ b/e2e/infra/scripts/destroy.ts @@ -5,15 +5,11 @@ import { destroyTestInfo } from '../destroyTestInfo' async function main() { const testInfo = readTestInfo() - const resourceGroups = new Set(testInfo.map((t) => t.resourceGroup)) - - for (const info of testInfo) { + for (const info of testInfo.tests) { await destroyTestInfo(info) } - for (const resourceGroup of resourceGroups) { - await removeResourceGroup(resourceGroup) - } + await removeResourceGroup(testInfo.resourceGroup) deleteTestInfo() } diff --git a/e2e/playwright.config.ts b/e2e/playwright.config.ts index 12de3a40..a96de04b 100644 --- a/e2e/playwright.config.ts +++ b/e2e/playwright.config.ts @@ -20,7 +20,7 @@ const config: Config = { expect: { timeout: isCi ? 100_000 : 30_000, }, - projects: testInfo.map((info) => ({ + projects: testInfo.tests.map((info) => ({ use: { name: info.frontdoorUrl, baseURL: info.frontdoorUrl, diff --git a/e2e/scripts/mockTests.ts b/e2e/scripts/mockTests.ts index 0fb4e654..5267e4f0 100644 --- a/e2e/scripts/mockTests.ts +++ b/e2e/scripts/mockTests.ts @@ -12,7 +12,7 @@ async function main() { throw new Error('API_URL is not set') } - for (const info of testInfo) { + for (const info of testInfo.tests) { const agentPath = `${info.routePrefix}/${info.agentDownloadPath}` const resultPath = `${info.routePrefix}/${info.getResultPath}` const host = info.functionAppUrl diff --git a/e2e/shared/testInfo.ts b/e2e/shared/testInfo.ts index 2622267c..6e880622 100644 --- a/e2e/shared/testInfo.ts +++ b/e2e/shared/testInfo.ts @@ -2,7 +2,6 @@ import * as fs from 'fs' import path from 'path' export interface TestInfo { - resourceGroup: string functionAppUrl: string websiteUrl: string frontdoorUrl: string @@ -13,13 +12,37 @@ export interface TestInfo { routePrefix: string } +export interface TestMetadata { + resourceGroup: string + tests: TestInfo[] +} + const filePath = path.join(__dirname, '..', 'test-info.json') -export function writeTestInfo(info: TestInfo[]) { +export function initTestInfo(resourceGroup: string) { + if (fs.existsSync(filePath)) { + throw new Error('Test info file already exists') + } + + writeTestInfo({ + tests: [], + resourceGroup, + }) +} + +export function addTestInfo(testInfo: TestInfo) { + const infos = readTestInfo() + + infos.tests.push(testInfo) + + writeTestInfo(infos) +} + +export function writeTestInfo(info: TestMetadata) { fs.writeFileSync(filePath, JSON.stringify(info)) } -export function readTestInfo(): TestInfo[] { +export function readTestInfo(): TestMetadata { if (!fs.existsSync(filePath)) { throw new Error('Test info file does not exist') } diff --git a/e2e/tests/pwTest.ts b/e2e/tests/pwTest.ts index 509e0b11..8163c44d 100644 --- a/e2e/tests/pwTest.ts +++ b/e2e/tests/pwTest.ts @@ -6,7 +6,7 @@ import invariant from 'tiny-invariant' export const test = baseTest.extend<{ azureTestInfo: TestInfo }>({ azureTestInfo: async ({ baseURL }, use) => { const testInfo = readTestInfo() - const project = testInfo.find((info) => info.frontdoorUrl === baseURL) + const project = testInfo.tests.find((info) => info.frontdoorUrl === baseURL) invariant(project, 'project is required') diff --git a/e2e/tests/setup.ts b/e2e/tests/setup.ts index 04ee6cdc..6934d34b 100644 --- a/e2e/tests/setup.ts +++ b/e2e/tests/setup.ts @@ -9,7 +9,7 @@ export default async function setup(config: FullConfig) { const targets = config.projects.map((p) => ({ name: p.name, url: p.use.baseURL, - testInfo: testInfo.find((info) => info.frontdoorUrl === p.use.baseURL), + testInfo: testInfo.tests.find((info) => info.frontdoorUrl === p.use.baseURL), headless: p.use.headless, }))