Unverified Commit 8b5df172 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

test: Fix immutable static asset deployment tests (#95550)

1. The env var ended up having a different name than I foresaw months
ago. Now `next.assetToken` is correctly `undefined` if the deployment
used immutable static assets.
2. `expect(searchParams.get(...)).toBe(undefined)` was failing because
`.get()` returns null for unknown keys

Failures:
-
https://github.com/vercel/next.js/actions/runs/28831699621/job/85515363446
-
https://github.com/vercel/next.js/actions/runs/28831699621/job/85515363310
parent bd770878
import { isNextDeploy, nextTestSetup } from 'e2e-utils' import { isNextDeploy, nextTestSetup } from 'e2e-utils'
import fs from 'fs-extra' import fs from 'fs-extra'
import { join } from 'path' import path from 'path'
describe('app dir - next-image', () => { describe('app dir - next-image', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
...@@ -10,7 +10,7 @@ describe('app dir - next-image', () => { ...@@ -10,7 +10,7 @@ describe('app dir - next-image', () => {
describe('ssr content', () => { describe('ssr content', () => {
if (!isNextDeploy) { if (!isNextDeploy) {
it('should handle HEAD requests for uncached images', async () => { it('should handle HEAD requests for uncached images', async () => {
const imagesDir = join(next.testDir, '.next/cache/images') const imagesDir = path.join(next.testDir, '.next/cache/images')
await fs.remove(imagesDir).catch(() => {}) await fs.remove(imagesDir).catch(() => {})
const $ = await next.render$('/') const $ = await next.render$('/')
......
...@@ -12,13 +12,15 @@ describe('app dir - workers', () => { ...@@ -12,13 +12,15 @@ describe('app dir - workers', () => {
}) })
function beforePageLoad(page: Page) { function beforePageLoad(page: Page) {
// TODO fix deployment id for webpack // TODO Webpack doesn't pass the ?dpl query param for the worker chunk request.
if (isTurbopack && (isNextDeploy || isNextStart)) { if (isTurbopack && (isNextDeploy || isNextStart)) {
page.on('request', (request) => { page.on('request', (request) => {
const url = request.url() const url = request.url()
if (url.includes('/_next/')) { if (url.includes('/_next/')) {
let parsed = new URL(url, next.url) let parsed = new URL(url, next.url)
expect(parsed.searchParams.get('dpl')).toBe(next.assetToken) expect(parsed.searchParams.get('dpl') ?? undefined).toBe(
next.assetToken
)
} }
}) })
} }
......
...@@ -310,7 +310,7 @@ export class NextInstance { ...@@ -310,7 +310,7 @@ export class NextInstance {
? // since we can't get the build id as a build artifact, ? // since we can't get the build id as a build artifact,
// add it in build logs // add it in build logs
{ {
'post-build': `node -e 'console.log("BUILD" + "_ID: " + fs.readFileSync("${this.distDir}/BUILD_ID") + "\\nDEPLOYMENT" + "_ID: " + process.env.NEXT_DEPLOYMENT_ID + "\\nNEXT_SUPPORTS_IMMUTABLE" + "_ASSETS: " + (process.env.NEXT_SUPPORTS_IMMUTABLE_ASSETS ? 1 : 0))'`, 'post-build': `node -e 'console.log("BUILD" + "_ID: " + fs.readFileSync("${this.distDir}/BUILD_ID") + "\\nDEPLOYMENT" + "_ID: " + process.env.NEXT_DEPLOYMENT_ID + "\\nNEXT_SUPPORTS_IMMUTABLE" + "_ASSETS: " + (process.env.VERCEL_IMMUTABLE_STATIC_FILES_ENABLED ? 1 : 0))'`,
} }
: {}), : {}),
...pkgScripts, ...pkgScripts,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment