Skip to content

Commit

Permalink
test: add a case for interop with oher build plugins / integrations
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh committed Jun 26, 2024
1 parent 7e2b9e1 commit 4345795
Show file tree
Hide file tree
Showing 20 changed files with 197 additions and 0 deletions.
56 changes: 56 additions & 0 deletions tests/e2e/with-integrations.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { expect } from '@playwright/test'
import { test } from '../utils/playwright-helpers.js'

test('Renders the Home page correctly', async ({ page, withIntegrations }) => {
await page.goto(withIntegrations.url)

expect(page.locator('body')).toHaveText('Hello World')
})

test.describe('Should clear stale functions produced by previous builds by @netlify/plugin-nextjs', () => {
test('Serverless functions', async ({ page, withIntegrations }) => {
const response1 = await page.goto(new URL('/test/serverless/v4', withIntegrations.url).href)
expect(response1?.status()).toBe(404)

const response2 = await page.goto(new URL('/test/serverless/v5', withIntegrations.url).href)
expect(response2?.status()).toBe(404)
})

test('Edge functions', async ({ page, withIntegrations }) => {
const response1 = await page.goto(new URL('/test/edge/v4', withIntegrations.url).href)
expect(response1?.status()).toBe(404)

const response2 = await page.goto(new URL('/test/edge/v5', withIntegrations.url).href)
expect(response2?.status()).toBe(404)
})
})

test.describe('Should keep functions produced by other build plugins', () => {
test('Serverless functions', async ({ page, withIntegrations }) => {
const response1 = await page.goto(
new URL('/test/serverless/integration-with-json-config', withIntegrations.url).href,
)
expect(response1?.status()).toBe(200)
expect(await response1?.text()).toBe('Hello from /test/serverless/integration-with-json-config')

const response2 = await page.goto(
new URL('/test/serverless/integration-with-json-config', withIntegrations.url).href,
)
expect(response2?.status()).toBe(200)
expect(await response2?.text()).toBe('Hello from /test/serverless/integration-with-json-config')
})

test('Edge functions', async ({ page, withIntegrations }) => {
const response1 = await page.goto(
new URL('/test/edge/integration-in-manifest', withIntegrations.url).href,
)
expect(response1?.status()).toBe(200)
expect(await response1?.text()).toBe('Hello from /test/edge/integration-in-manifest')

const response2 = await page.goto(
new URL('/test/edge/integration-not-in-manifest', withIntegrations.url).href,
)
expect(response2?.status()).toBe(200)
expect(await response2?.text()).toBe('Hello from /test/edge/integration-not-in-manifest')
})
})
2 changes: 2 additions & 0 deletions tests/fixtures/with-integrations/netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[[plugins]]
package = "/plugins/create-other-functions"
8 changes: 8 additions & 0 deletions tests/fixtures/with-integrations/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
eslint: {
ignoreDuringBuilds: true,
},
}

module.exports = nextConfig
13 changes: 13 additions & 0 deletions tests/fixtures/with-integrations/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "with-integrations",
"version": "0.1.0",
"private": true,
"scripts": {
"build": "next build"
},
"dependencies": {
"next": "latest",
"react": "18.2.0",
"react-dom": "18.2.0"
}
}
7 changes: 7 additions & 0 deletions tests/fixtures/with-integrations/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Home() {
return (
<main>
<h1>Hello World</h1>
</main>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function handler() {
return new Response('Hello from /test/edge/integration-in-manifest', { status: 200 })
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function handler() {
return new Response('Hello from /test/edge/integration-not-in-manifest', { status: 200 })
}

export const config = {
path: '/test/edge/integration-not-in-manifest',
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"functions": [
{
"function": "next-runtime-v4",
"name": "next-runtime-v4",
"path": "/test/edge/v4",
"generator": "@netlify/[email protected]"
},
{
"function": "next-runtime-v5",
"name": "next-runtime-v5",
"path": "/test/edge/v5",
"generator": "@netlify/[email protected]"
},
{
"function": "integration-in-manifest",
"name": "integration-in-manifest",
"path": "/test/edge/integration-in-manifest",
"generator": "@netlify/[email protected]"
}
],
"layers": [],
"version": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default function handler() {
return new Response('Hello from edge functions generated by @netlify/plugin-nextjs@4', {
status: 200,
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default function handler() {
return new Response('Hello from edge functions generated by @netlify/plugin-nextjs@5', {
status: 200,
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function handler() {
return new Response('Hello from /test/serverless/integration-with-json-config', { status: 200 })
}

export const config = {
path: '/test/serverless/integration-with-json-config',
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"config": {
"name": "Some integration",
"generator": "@netlify/[email protected]"
},
"version": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function handler() {
return new Response('Hello from integration generated serverless function', { status: 200 })
}

export const config = {
path: '/test/serverless/integration-with-json-config',
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"config": {
"generator": "@netlify/[email protected]"
},
"version": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function handler() {
return new Response('Hello from edge functions generated by @netlify/plugin-nextjs@5', {
status: 200,
})
}

export const config = {
path: '/test/serverless/v4',
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"config": {
"generator": "@netlify/[email protected]"
},
"version": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function handler() {
return new Response('Hello from edge functions generated by @netlify/plugin-nextjs@5', {
status: 200,
})
}

export const config = {
path: '/test/serverless/v5',
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { cp } = require('node:fs/promises')
const { join } = require('node:path')

exports.onPreBuild = async function onPreBuild({
constants: { INTERNAL_FUNCTIONS_SRC, INTERNAL_EDGE_FUNCTIONS_SRC },
}) {
// copying functions:
// - mocked functions to represent stale function produced by @netlify/plugin-nextjs (specified by `generator`) for v4 and v5 of runtime
// - mocked functions to represent functions produced by other build plugins (either specified by `generator` or missing `generator` metadata)
await Promise.all([
cp(join(__dirname, 'edge-functions'), INTERNAL_EDGE_FUNCTIONS_SRC, { recursive: true }),
cp(join(__dirname, 'functions-internal'), INTERNAL_FUNCTIONS_SRC, { recursive: true }),
])
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name: 'simulate-integration'
1 change: 1 addition & 0 deletions tests/utils/create-e2e-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ export const fixtureFactories = {
createE2EFixture('cli-before-regional-blobs-support', {
expectedCliVersion: '17.21.1',
}),
withIntegrations: () => createE2EFixture('with-integrations'),
yarnMonorepoWithPnpmLinker: () =>
createE2EFixture('yarn-monorepo-with-pnpm-linker', {
packageManger: 'berry',
Expand Down

0 comments on commit 4345795

Please sign in to comment.