Skip to content

Commit

Permalink
Merge branch 'main' into test-fail-prepare-script-if-fixture-prep-fails
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh authored Feb 3, 2025
2 parents 6758465 + 4bcb34f commit f7c9dc8
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 35 deletions.
1 change: 0 additions & 1 deletion tests/e2e/export.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { expect, type Locator } from '@playwright/test'
import { nextVersionSatisfies } from '../utils/next-version-helpers.mjs'
import { test } from '../utils/playwright-helpers.js'

const expectImageWasLoaded = async (locator: Locator) => {
Expand Down
16 changes: 11 additions & 5 deletions tests/integration/wasm.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getLogger } from 'lambda-local'
import { platform } from 'node:process'
import { v4 } from 'uuid'
import { beforeEach, describe, expect, test, vi } from 'vitest'
import { type FixtureTestContext } from '../utils/contexts.js'
Expand Down Expand Up @@ -52,11 +53,16 @@ describe.each([
expect(og.headers['content-type']).toBe('image/png')
})

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

test<FixtureTestContext>('should work in middleware', async (ctx) => {
const origin = new LocalServer()
Expand Down
24 changes: 13 additions & 11 deletions tests/netlify-deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,11 @@ export class NextDeployInstance extends NextInstance {
const deployTitle = process.env.GITHUB_SHA
? `${testName} - ${process.env.GITHUB_SHA}`
: testName
const deployAlias = 'vercel-next-e2e'

const deployRes = await execa(
'npx',
['netlify', 'deploy', '--build', '--message', deployTitle ?? ''],
['netlify', 'deploy', '--build', '--message', deployTitle ?? '', '--alias', deployAlias],
{
cwd: this.testDir,
reject: false,
Expand All @@ -146,22 +147,23 @@ export class NextDeployInstance extends NextInstance {
}

try {
const [url] = new RegExp(/https:.+\.netlify\.app/gm).exec(deployRes.stdout) || []
if (!url) {
throw new Error('Could not extract the URL from the build logs')
const deployUrlRegex = new RegExp(
/https:\/\/app\.netlify\.com\/sites\/(?<siteName>.+)\/deploys\/(?<deployID>[0-9a-f]+)/gm,
).exec(deployRes.stdout)
const [buildLogsUrl] = deployUrlRegex || []
const { deployID, siteName } = deployUrlRegex?.groups || {}

if (!deployID) {
throw new Error('Could not extract DeployID from the build logs')
}
const [deployID] = new URL(url).host.split('--')
this._url = url

this._url = `https://${deployID}--${siteName}.netlify.app`
this._parsedUrl = new URL(this._url)
this._deployId = deployID
this._shouldDeleteDeploy = !process.env.NEXT_TEST_SKIP_CLEANUP
this._cliOutput = deployRes.stdout + deployRes.stderr
require('console').log(`Deployment URL: ${this._url}`)

const [buildLogsUrl] =
new RegExp(/https:\/\/app\.netlify\.com\/sites\/.+\/deploys\/[0-9a-f]+/gm).exec(
deployRes.stdout,
) || []
require('console').log(`Deployment URL: ${this._url}`)
if (buildLogsUrl) {
require('console').log(`Logs: ${buildLogsUrl}`)
}
Expand Down
21 changes: 15 additions & 6 deletions tests/utils/create-e2e-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { setNextVersionInFixture } from './next-version-helpers.mjs'
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'
const NETLIFY_DEPLOY_ALIAS = 'next-e2e-tests'

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

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

if (packagePath) {
cmd += ` --filter ${packagePath}`
Expand All @@ -278,12 +279,20 @@ 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:.+\.netlify\.app/gm).exec(output) || []
if (!url) {
throw new Error('Could not extract the URL from the build logs')
const { siteName, deployID } =
new RegExp(/app\.netlify\.com\/sites\/(?<siteName>.+)\/deploys\/(?<deployID>[0-9a-f]+)/gm).exec(
output,
)?.groups || {}

if (!deployID) {
throw new Error('Could not extract DeployID from the build logs')
}

return {
url: `https://${deployID}--${siteName}.netlify.app`,
deployID,
logs: output,
}
const [deployID] = new URL(url).host.split('--')
return { url, deployID, logs: output }
}

export async function deleteDeploy(deployID?: string): Promise<void> {
Expand Down
12 changes: 0 additions & 12 deletions tools/e2e/cleanup-deploys.ts

This file was deleted.

0 comments on commit f7c9dc8

Please sign in to comment.