-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add a case for interop with oher build plugins / integrations
- Loading branch information
Showing
20 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[[plugins]] | ||
package = "/plugins/create-other-functions" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} |
3 changes: 3 additions & 0 deletions
3
...th-integrations/plugins/create-other-functions/edge-functions/integration-in-manifest.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }) | ||
} |
7 changes: 7 additions & 0 deletions
7
...ntegrations/plugins/create-other-functions/edge-functions/integration-not-in-manifest.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
} |
24 changes: 24 additions & 0 deletions
24
tests/fixtures/with-integrations/plugins/create-other-functions/edge-functions/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
5 changes: 5 additions & 0 deletions
5
...rations/plugins/create-other-functions/edge-functions/next-runtime-v4/next-runtime-v4.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}) | ||
} |
5 changes: 5 additions & 0 deletions
5
...tures/with-integrations/plugins/create-other-functions/edge-functions/next-runtime-v5.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}) | ||
} |
7 changes: 7 additions & 0 deletions
7
...grations/plugins/create-other-functions/functions-internal/integration-no-json-config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
} |
7 changes: 7 additions & 0 deletions
7
...tions/plugins/create-other-functions/functions-internal/integration-with-json-config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"config": { | ||
"name": "Some integration", | ||
"generator": "@netlify/[email protected]" | ||
}, | ||
"version": 1 | ||
} |
7 changes: 7 additions & 0 deletions
7
...ations/plugins/create-other-functions/functions-internal/integration-with-json-config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
} |
6 changes: 6 additions & 0 deletions
6
...ns/plugins/create-other-functions/functions-internal/next-runtime-v4/next-runtime-v4.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"config": { | ||
"generator": "@netlify/[email protected]" | ||
}, | ||
"version": 1 | ||
} |
9 changes: 9 additions & 0 deletions
9
...ons/plugins/create-other-functions/functions-internal/next-runtime-v4/next-runtime-v4.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
} |
6 changes: 6 additions & 0 deletions
6
.../with-integrations/plugins/create-other-functions/functions-internal/next-runtime-v5.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"config": { | ||
"generator": "@netlify/[email protected]" | ||
}, | ||
"version": 1 | ||
} |
9 changes: 9 additions & 0 deletions
9
...s/with-integrations/plugins/create-other-functions/functions-internal/next-runtime-v5.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/fixtures/with-integrations/plugins/create-other-functions/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }), | ||
]) | ||
} |
1 change: 1 addition & 0 deletions
1
tests/fixtures/with-integrations/plugins/create-other-functions/manifest.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
name: 'simulate-integration' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters