Skip to content

Commit 3f27a9a

Browse files
committed
test: add e2e test for pre-frameworks api
1 parent 869e448 commit 3f27a9a

File tree

7 files changed

+81
-1
lines changed

7 files changed

+81
-1
lines changed

src/build/plugin-context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export class PluginContext {
180180
#useFrameworksAPI: typeof this.useFrameworksAPI | null = null
181181
get useFrameworksAPI(): boolean {
182182
if (this.#useFrameworksAPI === null) {
183-
// Defining RegExp pattern in edge function inline config is only supported since 29.50.5
183+
// Defining RegExp pattern in edge function inline config is only supported since Build 29.50.5 / CLI 17.32.1
184184
const REQUIRED_BUILD_VERSION = '>=29.50.5'
185185
this.#useFrameworksAPI = satisfies(this.buildVersion, REQUIRED_BUILD_VERSION, {
186186
includePrerelease: true,
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { expect } from '@playwright/test'
2+
import { test } from '../utils/playwright-helpers.js'
3+
4+
test('should serve 404 page when requesting non existing page (no matching route) if site is deployed with CLI not supporting frameworks API', async ({
5+
page,
6+
cliBeforeFrameworksAPISupport,
7+
}) => {
8+
// 404 page is built and uploaded to blobs at build time
9+
// when Next.js serves 404 it will try to fetch it from the blob store
10+
// if request handler function is unable to get from blob store it will
11+
// fail request handling and serve 500 error.
12+
// This implicitly tests that request handler function is able to read blobs
13+
// that are uploaded as part of site deploy.
14+
// This also tests if edge middleware is working.
15+
16+
const response = await page.goto(new URL('non-existing', cliBeforeFrameworksAPISupport.url).href)
17+
const headers = response?.headers() || {}
18+
expect(response?.status()).toBe(404)
19+
20+
expect(await page.textContent('h1')).toBe('404')
21+
22+
expect(headers['netlify-cdn-cache-control']).toBe(
23+
'no-cache, no-store, max-age=0, must-revalidate',
24+
)
25+
expect(headers['cache-control']).toBe('no-cache,no-store,max-age=0,must-revalidate')
26+
27+
expect(headers['x-hello-from-middleware']).toBe('hello')
28+
})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { NextResponse } from 'next/server'
2+
3+
export function middleware() {
4+
const response: NextResponse = NextResponse.next()
5+
6+
response.headers.set('x-hello-from-middleware', 'hello')
7+
8+
return response
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/** @type {import('next').NextConfig} */
2+
const nextConfig = {
3+
eslint: {
4+
ignoreDuringBuilds: true,
5+
},
6+
}
7+
8+
module.exports = nextConfig
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "old-cli",
3+
"version": "0.1.0",
4+
"private": true,
5+
"scripts": {
6+
"postinstall": "next build",
7+
"dev": "next dev",
8+
"build": "next build"
9+
},
10+
"dependencies": {
11+
"next": "latest",
12+
"netlify-cli": "17.32.0",
13+
"react": "^18.2.0",
14+
"react-dom": "^18.2.0"
15+
}
16+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export default function Home({ ssr }) {
2+
return (
3+
<main>
4+
<div data-testid="smoke">SSR: {ssr ? 'yes' : 'no'}</div>
5+
</main>
6+
)
7+
}
8+
9+
export const getServerSideProps = async () => {
10+
return {
11+
props: {
12+
ssr: true,
13+
},
14+
}
15+
}

tests/utils/create-e2e-fixture.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,10 @@ export const fixtureFactories = {
358358
createE2EFixture('cli-before-regional-blobs-support', {
359359
expectedCliVersion: '17.21.1',
360360
}),
361+
cliBeforeFrameworksAPISupport: () =>
362+
createE2EFixture('cli-before-frameworks-api-support', {
363+
expectedCliVersion: '17.32.0',
364+
}),
361365
yarnMonorepoWithPnpmLinker: () =>
362366
createE2EFixture('yarn-monorepo-with-pnpm-linker', {
363367
packageManger: 'berry',

0 commit comments

Comments
 (0)