Skip to content

Commit a964c7a

Browse files
committed
test: add forms workaround test
1 parent f868c81 commit a964c7a

File tree

7 files changed

+89
-7
lines changed

7 files changed

+89
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export const metadata = {
2+
title: 'Netlify Forms',
3+
description: 'Test for verifying Netlify Forms',
4+
}
5+
6+
export default function RootLayout({ children }) {
7+
return (
8+
<html lang="en">
9+
<body>{children}</body>
10+
</html>
11+
)
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function Page() {
2+
return (
3+
<form data-netlify="true">
4+
<button type="submit">Send</button>
5+
</form>
6+
)
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/** @type {import('next').NextConfig} */
2+
const nextConfig = {
3+
output: 'standalone',
4+
eslint: {
5+
ignoreDuringBuilds: true,
6+
},
7+
generateBuildId: () => 'build-id',
8+
}
9+
10+
module.exports = nextConfig
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "netlify-forms",
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+
"@netlify/functions": "^2.7.0",
12+
"next": "latest",
13+
"react": "18.2.0",
14+
"react-dom": "18.2.0"
15+
},
16+
"devDependencies": {
17+
"@types/react": "18.2.75"
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<form name="contact" netlify></form>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"compilerOptions": {
3+
"lib": ["dom", "dom.iterable", "esnext"],
4+
"allowJs": true,
5+
"skipLibCheck": true,
6+
"strict": false,
7+
"noEmit": true,
8+
"incremental": true,
9+
"esModuleInterop": true,
10+
"module": "esnext",
11+
"moduleResolution": "node",
12+
"resolveJsonModule": true,
13+
"isolatedModules": true,
14+
"jsx": "preserve",
15+
"plugins": [
16+
{
17+
"name": "next"
18+
}
19+
]
20+
},
21+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
22+
"exclude": ["node_modules"]
23+
}

tests/integration/netlify-forms.test.ts

+17-7
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,29 @@ beforeEach<FixtureTestContext>(async (ctx) => {
1414
vi.stubEnv('SITE_ID', ctx.siteID)
1515
vi.stubEnv('DEPLOY_ID', ctx.deployID)
1616
vi.stubEnv('NETLIFY_PURGE_API_TOKEN', 'fake-token')
17-
// hide debug logs in tests
18-
// vi.spyOn(console, 'debug').mockImplementation(() => {})
17+
vi.resetModules()
1918

2019
await startMockBlobStore(ctx)
2120
})
2221

23-
// test skipped until we actually start failing builds - right now we are just showing a warning
24-
it.skip<FixtureTestContext>('should fail build when netlify forms are used', async (ctx) => {
22+
it<FixtureTestContext>('should warn when netlify forms are used', async (ctx) => {
23+
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
24+
2525
await createFixture('netlify-forms', ctx)
2626

27-
const runPluginPromise = runPlugin(ctx)
27+
const runPluginPromise = await runPlugin(ctx)
2828

29-
await expect(runPluginPromise).rejects.toThrow(
30-
'@netlify/plugin-next@5 does not support Netlify Forms',
29+
expect(warn).toBeCalledWith(
30+
'@netlify/plugin-next@5 does not support Netlify Forms. Refer to https://ntl.fyi/next-runtime-forms-migration for migration example.',
3131
)
3232
})
33+
34+
it<FixtureTestContext>('should not warn when netlify forms are used with workaround', async (ctx) => {
35+
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
36+
37+
await createFixture('netlify-forms-workaround', ctx)
38+
39+
const runPluginPromise = await runPlugin(ctx)
40+
41+
expect(warn).not.toBeCalled()
42+
})

0 commit comments

Comments
 (0)