Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4bcb34f

Browse filesBrowse files
mrstorkpieh
andauthored
test: use branch/alias deploys for e2e test suite to enable automatic deploy cleanup (#2752)
* test: use branch/alias deploys for e2e test suite to allow automatic cleanup * chore: deletion is now automated by the system * chore: use constant for deploy alias * test: fix deploy url regex * test: use deploy preview for test url * chore: leverage regex named capture groups for deploy id and site name * test: use branch/alias deploys for vercel tests * chore: remove unused import * test: remove trailing slashes from deploy urls * chore: format with prettier * test: skip og image integration test in windows --------- Co-authored-by: Michal Piechowiak <misiek.piechowiak@gmail.com>
1 parent 8e852ca commit 4bcb34f
Copy full SHA for 4bcb34f

File tree

Expand file treeCollapse file tree

5 files changed

+39
-35
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+39
-35
lines changed

‎tests/e2e/export.test.ts

Copy file name to clipboardExpand all lines: tests/e2e/export.test.ts
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { expect, type Locator } from '@playwright/test'
2-
import { nextVersionSatisfies } from '../utils/next-version-helpers.mjs'
32
import { test } from '../utils/playwright-helpers.js'
43

54
const expectImageWasLoaded = async (locator: Locator) => {

‎tests/integration/wasm.test.ts

Copy file name to clipboardExpand all lines: tests/integration/wasm.test.ts
+11-5Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { getLogger } from 'lambda-local'
2+
import { platform } from 'node:process'
23
import { v4 } from 'uuid'
34
import { beforeEach, describe, expect, test, vi } from 'vitest'
45
import { type FixtureTestContext } from '../utils/contexts.js'
@@ -52,11 +53,16 @@ describe.each([
5253
expect(og.headers['content-type']).toBe('image/png')
5354
})
5455

55-
test<FixtureTestContext>('should work in app route with node runtime', async (ctx) => {
56-
const ogNode = await invokeFunction(ctx, { url: '/og-node' })
57-
expect(ogNode.statusCode).toBe(200)
58-
expect(ogNode.headers['content-type']).toBe('image/png')
59-
})
56+
// on Node 18.20.6 on Windows, there seems to be an issue with OG image generation in this scenario
57+
// that is reproducible with `next start` even outside of Netlify context
58+
test.skipIf(platform === 'win32')<FixtureTestContext>(
59+
'should work in app route with node runtime',
60+
async (ctx) => {
61+
const ogNode = await invokeFunction(ctx, { url: '/og-node' })
62+
expect(ogNode.statusCode).toBe(200)
63+
expect(ogNode.headers['content-type']).toBe('image/png')
64+
},
65+
)
6066

6167
test<FixtureTestContext>('should work in middleware', async (ctx) => {
6268
const origin = new LocalServer()

‎tests/netlify-deploy.ts

Copy file name to clipboardExpand all lines: tests/netlify-deploy.ts
+13-11Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,11 @@ export class NextDeployInstance extends NextInstance {
129129
const deployTitle = process.env.GITHUB_SHA
130130
? `${testName} - ${process.env.GITHUB_SHA}`
131131
: testName
132+
const deployAlias = 'vercel-next-e2e'
132133

133134
const deployRes = await execa(
134135
'npx',
135-
['netlify', 'deploy', '--build', '--message', deployTitle ?? ''],
136+
['netlify', 'deploy', '--build', '--message', deployTitle ?? '', '--alias', deployAlias],
136137
{
137138
cwd: this.testDir,
138139
reject: false,
@@ -146,22 +147,23 @@ export class NextDeployInstance extends NextInstance {
146147
}
147148

148149
try {
149-
const [url] = new RegExp(/https:.+\.netlify\.app/gm).exec(deployRes.stdout) || []
150-
if (!url) {
151-
throw new Error('Could not extract the URL from the build logs')
150+
const deployUrlRegex = new RegExp(
151+
/https:\/\/app\.netlify\.com\/sites\/(?<siteName>.+)\/deploys\/(?<deployID>[0-9a-f]+)/gm,
152+
).exec(deployRes.stdout)
153+
const [buildLogsUrl] = deployUrlRegex || []
154+
const { deployID, siteName } = deployUrlRegex?.groups || {}
155+
156+
if (!deployID) {
157+
throw new Error('Could not extract DeployID from the build logs')
152158
}
153-
const [deployID] = new URL(url).host.split('--')
154-
this._url = url
159+
160+
this._url = `https://${deployID}--${siteName}.netlify.app`
155161
this._parsedUrl = new URL(this._url)
156162
this._deployId = deployID
157163
this._shouldDeleteDeploy = !process.env.NEXT_TEST_SKIP_CLEANUP
158164
this._cliOutput = deployRes.stdout + deployRes.stderr
159-
require('console').log(`Deployment URL: ${this._url}`)
160165

161-
const [buildLogsUrl] =
162-
new RegExp(/https:\/\/app\.netlify\.com\/sites\/.+\/deploys\/[0-9a-f]+/gm).exec(
163-
deployRes.stdout,
164-
) || []
166+
require('console').log(`Deployment URL: ${this._url}`)
165167
if (buildLogsUrl) {
166168
require('console').log(`Logs: ${buildLogsUrl}`)
167169
}

‎tests/utils/create-e2e-fixture.ts

Copy file name to clipboardExpand all lines: tests/utils/create-e2e-fixture.ts
+15-6Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { setNextVersionInFixture } from './next-version-helpers.mjs'
1515
const DEFAULT_SITE_ID = 'ee859ce9-44a7-46be-830b-ead85e445e53'
1616
export const SITE_ID = process.env.NETLIFY_SITE_ID ?? DEFAULT_SITE_ID
1717
const NEXT_VERSION = process.env.NEXT_VERSION || 'latest'
18+
const NETLIFY_DEPLOY_ALIAS = 'next-e2e-tests'
1819

1920
export interface DeployResult {
2021
deployID: string
@@ -268,7 +269,7 @@ async function deploySite(
268269
console.log(`🚀 Building and deploying site...`)
269270

270271
const outputFile = 'deploy-output.txt'
271-
let cmd = `npx netlify deploy --build --site ${siteId}`
272+
let cmd = `npx netlify deploy --build --site ${siteId} --alias ${NETLIFY_DEPLOY_ALIAS}`
272273

273274
if (packagePath) {
274275
cmd += ` --filter ${packagePath}`
@@ -278,12 +279,20 @@ async function deploySite(
278279
await execaCommand(cmd, { cwd: siteDir, all: true }).pipeAll?.(join(siteDir, outputFile))
279280
const output = await readFile(join(siteDir, outputFile), 'utf-8')
280281

281-
const [url] = new RegExp(/https:.+\.netlify\.app/gm).exec(output) || []
282-
if (!url) {
283-
throw new Error('Could not extract the URL from the build logs')
282+
const { siteName, deployID } =
283+
new RegExp(/app\.netlify\.com\/sites\/(?<siteName>.+)\/deploys\/(?<deployID>[0-9a-f]+)/gm).exec(
284+
output,
285+
)?.groups || {}
286+
287+
if (!deployID) {
288+
throw new Error('Could not extract DeployID from the build logs')
289+
}
290+
291+
return {
292+
url: `https://${deployID}--${siteName}.netlify.app`,
293+
deployID,
294+
logs: output,
284295
}
285-
const [deployID] = new URL(url).host.split('--')
286-
return { url, deployID, logs: output }
287296
}
288297

289298
export async function deleteDeploy(deployID?: string): Promise<void> {

‎tools/e2e/cleanup-deploys.ts

Copy file name to clipboardExpand all lines: tools/e2e/cleanup-deploys.ts
-12Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.