Unverified Commit e5926d3d authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Fix buildManifest.js deployment tests (#88806)

When `NEXT_DEPLOYMENT_ID` is set (and thus skew protection is enabled), then these pages router manifests are actually on a different path (so that the output paths doesn't change with the build id anymore)

Fixup for https://github.com/vercel/next.js/pull/88641
parent f1908dad
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
describe('invalid-static-asset-404-app-asset-prefix', () => { describe('invalid-static-asset-404-app-asset-prefix', () => {
const { next, isNextDev } = nextTestSetup({ const { next, isNextDeploy } = nextTestSetup({
files: __dirname, files: __dirname,
nextConfig: { nextConfig: {
assetPrefix: '/assets', assetPrefix: '/assets',
...@@ -9,9 +9,9 @@ describe('invalid-static-asset-404-app-asset-prefix', () => { ...@@ -9,9 +9,9 @@ describe('invalid-static-asset-404-app-asset-prefix', () => {
}) })
it('should return correct output with status 200 on valid asset path', async () => { it('should return correct output with status 200 on valid asset path', async () => {
const buildManifestPath = `/assets/_next/static/${ const buildManifestPath = isNextDeploy
isNextDev ? 'development' : next.buildId ? '/assets/_next/static/_buildManifest.js'
}/_buildManifest.js` : `/assets/_next/static/${next.buildId}/_buildManifest.js`
const res = await next.fetch(buildManifestPath) const res = await next.fetch(buildManifestPath)
expect(res.status).toBe(200) expect(res.status).toBe(200)
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
describe('invalid-static-asset-404-app-base-path', () => { describe('invalid-static-asset-404-app-base-path', () => {
const { next, isNextDev } = nextTestSetup({ const { next, isNextDeploy } = nextTestSetup({
files: __dirname, files: __dirname,
nextConfig: { nextConfig: {
basePath: '/base', basePath: '/base',
...@@ -9,9 +9,9 @@ describe('invalid-static-asset-404-app-base-path', () => { ...@@ -9,9 +9,9 @@ describe('invalid-static-asset-404-app-base-path', () => {
}) })
it('should return correct output with status 200 on valid asset path', async () => { it('should return correct output with status 200 on valid asset path', async () => {
const buildManifestPath = `/base/_next/static/${ const buildManifestPath = isNextDeploy
isNextDev ? 'development' : next.buildId ? '/base/_next/static/_buildManifest.js'
}/_buildManifest.js` : `/base/_next/static/${next.buildId}/_buildManifest.js`
const res = await next.fetch(buildManifestPath) const res = await next.fetch(buildManifestPath)
expect(res.status).toBe(200) expect(res.status).toBe(200)
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
describe('invalid-static-asset-404-app', () => { describe('invalid-static-asset-404-app', () => {
const { next, isNextDev } = nextTestSetup({ const { next, isNextDeploy } = nextTestSetup({
files: __dirname, files: __dirname,
}) })
it('should return correct output with status 200 on valid asset path', async () => { it('should return correct output with status 200 on valid asset path', async () => {
const buildManifestPath = `/_next/static/${ const buildManifestPath = isNextDeploy
isNextDev ? 'development' : next.buildId ? '/_next/static/_buildManifest.js'
}/_buildManifest.js` : `/_next/static/${next.buildId}/_buildManifest.js`
const res = await next.fetch(buildManifestPath) const res = await next.fetch(buildManifestPath)
expect(res.status).toBe(200) expect(res.status).toBe(200)
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
describe('invalid-static-asset-404-pages-asset-prefix', () => { describe('invalid-static-asset-404-pages-asset-prefix', () => {
const { next, isNextDev } = nextTestSetup({ const { next, isNextDeploy } = nextTestSetup({
files: __dirname, files: __dirname,
nextConfig: { nextConfig: {
assetPrefix: '/assets', assetPrefix: '/assets',
...@@ -9,9 +9,9 @@ describe('invalid-static-asset-404-pages-asset-prefix', () => { ...@@ -9,9 +9,9 @@ describe('invalid-static-asset-404-pages-asset-prefix', () => {
}) })
it('should return correct output with status 200 on valid asset path', async () => { it('should return correct output with status 200 on valid asset path', async () => {
const buildManifestPath = `/assets/_next/static/${ const buildManifestPath = isNextDeploy
isNextDev ? 'development' : next.buildId ? '/assets/_next/static/_buildManifest.js'
}/_buildManifest.js` : `/assets/_next/static/${next.buildId}/_buildManifest.js`
const res = await next.fetch(buildManifestPath) const res = await next.fetch(buildManifestPath)
expect(res.status).toBe(200) expect(res.status).toBe(200)
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
describe('invalid-static-asset-404-pages-base-path', () => { describe('invalid-static-asset-404-pages-base-path', () => {
const { next, isNextDev } = nextTestSetup({ const { next, isNextDeploy } = nextTestSetup({
files: __dirname, files: __dirname,
nextConfig: { nextConfig: {
basePath: '/base', basePath: '/base',
...@@ -9,9 +9,9 @@ describe('invalid-static-asset-404-pages-base-path', () => { ...@@ -9,9 +9,9 @@ describe('invalid-static-asset-404-pages-base-path', () => {
}) })
it('should return correct output with status 200 on valid asset path', async () => { it('should return correct output with status 200 on valid asset path', async () => {
const buildManifestPath = `/base/_next/static/${ const buildManifestPath = isNextDeploy
isNextDev ? 'development' : next.buildId ? '/base/_next/static/_buildManifest.js'
}/_buildManifest.js` : `/base/_next/static/${next.buildId}/_buildManifest.js`
const res = await next.fetch(buildManifestPath) const res = await next.fetch(buildManifestPath)
expect(res.status).toBe(200) expect(res.status).toBe(200)
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
describe('invalid-static-asset-404-pages', () => { describe('invalid-static-asset-404-pages', () => {
const { next, isNextDev } = nextTestSetup({ const { next, isNextDeploy } = nextTestSetup({
files: __dirname, files: __dirname,
}) })
it('should return correct output with status 200 on valid asset path', async () => { it('should return correct output with status 200 on valid asset path', async () => {
const buildManifestPath = `/_next/static/${ const buildManifestPath = isNextDeploy
isNextDev ? 'development' : next.buildId ? '/_next/static/_buildManifest.js'
}/_buildManifest.js` : `/_next/static/${next.buildId}/_buildManifest.js`
const res = await next.fetch(buildManifestPath) const res = await next.fetch(buildManifestPath)
expect(res.status).toBe(200) expect(res.status).toBe(200)
......
...@@ -4,22 +4,14 @@ ...@@ -4,22 +4,14 @@
import { join } from 'path' import { join } from 'path'
import webdriver from 'next-webdriver' import webdriver from 'next-webdriver'
import { fetchViaHTTP } from 'next-test-utils' import { fetchViaHTTP } from 'next-test-utils'
import { createNext, FileRef } from 'e2e-utils' import { FileRef, isNextDeploy, nextTestSetup } from 'e2e-utils'
import { NextInstance } from 'e2e-utils'
const itif = (condition: boolean) => (condition ? it : it.skip) const itif = (condition: boolean) => (condition ? it : it.skip)
const isModeDeploy = process.env.NEXT_TEST_MODE === 'deploy'
describe('Middleware custom matchers i18n', () => { describe('Middleware custom matchers i18n', () => {
let next: NextInstance const { next } = nextTestSetup({
beforeAll(async () => {
next = await createNext({
files: new FileRef(join(__dirname, '../app')), files: new FileRef(join(__dirname, '../app')),
}) })
})
afterAll(() => next.destroy())
it.each(['/hello', '/en/hello', '/nl-NL/hello', '/nl-NL/about'])( it.each(['/hello', '/en/hello', '/nl-NL/hello', '/nl-NL/about'])(
'should match %s', 'should match %s',
...@@ -41,7 +33,7 @@ describe('Middleware custom matchers i18n', () => { ...@@ -41,7 +33,7 @@ describe('Middleware custom matchers i18n', () => {
// FIXME: // FIXME:
// See https://linear.app/vercel/issue/EC-160/header-value-set-on-middleware-is-not-propagated-on-client-request-of // See https://linear.app/vercel/issue/EC-160/header-value-set-on-middleware-is-not-propagated-on-client-request-of
itif(!isModeDeploy).each(['hello', 'en_hello', 'nl-NL_hello', 'nl-NL_about'])( itif(!isNextDeploy).each(['hello', 'en_hello', 'nl-NL_hello', 'nl-NL_about'])(
'should match has query on client routing %s', 'should match has query on client routing %s',
async (id) => { async (id) => {
const browser = await webdriver(next.url, '/routes') const browser = await webdriver(next.url, '/routes')
...@@ -56,10 +48,7 @@ describe('Middleware custom matchers i18n', () => { ...@@ -56,10 +48,7 @@ describe('Middleware custom matchers i18n', () => {
}) })
describe('Middleware custom matchers with root', () => { describe('Middleware custom matchers with root', () => {
let next: NextInstance const { next, isNextDeploy } = nextTestSetup({
beforeAll(async () => {
next = await createNext({
files: { files: {
pages: new FileRef(join(__dirname, '../app', 'pages')), pages: new FileRef(join(__dirname, '../app', 'pages')),
'next.config.js': new FileRef( 'next.config.js': new FileRef(
...@@ -84,13 +73,12 @@ describe('Middleware custom matchers with root', () => { ...@@ -84,13 +73,12 @@ describe('Middleware custom matchers with root', () => {
}`, }`,
}, },
}) })
})
afterAll(() => next.destroy())
it('should not match', async () => { it('should not match', async () => {
const res = await fetchViaHTTP( const res = await next.fetch(
next.url, isNextDeploy
`/_next/static/${next.buildId}/_buildManifest.js` ? '/_next/static/_buildManifest.js'
: `/_next/static/${next.buildId}/_buildManifest.js`
) )
expect(res.status).toBe(200) expect(res.status).toBe(200)
expect(res.headers.get('x-from-middleware')).toBeFalsy() expect(res.headers.get('x-from-middleware')).toBeFalsy()
......
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