Skip to content

Commit 39511ed

Browse files
committed
test: ensure build is failed when netlify forms detected
1 parent bbccdf7 commit 39511ed

File tree

8 files changed

+121
-2
lines changed

8 files changed

+121
-2
lines changed
Lines changed: 12 additions & 0 deletions
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+
}
Lines changed: 7 additions & 0 deletions
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+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference types="next" />
2+
/// <reference types="next/image-types/global" />
3+
4+
// NOTE: This file should not be edited
5+
// see https://nextjs.org/docs/basic-features/typescript for more information.
Lines changed: 10 additions & 0 deletions
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
Lines changed: 19 additions & 0 deletions
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+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"compilerOptions": {
3+
"lib": [
4+
"dom",
5+
"dom.iterable",
6+
"esnext"
7+
],
8+
"allowJs": true,
9+
"skipLibCheck": true,
10+
"strict": false,
11+
"noEmit": true,
12+
"incremental": true,
13+
"esModuleInterop": true,
14+
"module": "esnext",
15+
"moduleResolution": "node",
16+
"resolveJsonModule": true,
17+
"isolatedModules": true,
18+
"jsx": "preserve",
19+
"plugins": [
20+
{
21+
"name": "next"
22+
}
23+
]
24+
},
25+
"include": [
26+
"next-env.d.ts",
27+
"**/*.ts",
28+
"**/*.tsx",
29+
".next/types/**/*.ts"
30+
],
31+
"exclude": [
32+
"node_modules"
33+
]
34+
}

tests/integration/advanced-api-routes.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { getLogger } from 'lambda-local'
22
import { v4 } from 'uuid'
3-
import { beforeEach, vi, it, expect } from 'vitest'
4-
import { createFixture, runPlugin, type FixtureTestContext } from '../utils/fixture.js'
3+
import { beforeEach, expect, it, vi } from 'vitest'
4+
import { type FixtureTestContext } from '../utils/contexts.js'
5+
import { createFixture, runPlugin } from '../utils/fixture.js'
56
import { generateRandomObjectID, startMockBlobStore } from '../utils/helpers.js'
67

78
getLogger().level = 'alert'
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { getLogger } from 'lambda-local'
2+
import { v4 } from 'uuid'
3+
import { beforeEach, expect, it, vi } from 'vitest'
4+
import { type FixtureTestContext } from '../utils/contexts.js'
5+
import { createFixture, runPlugin } from '../utils/fixture.js'
6+
import { generateRandomObjectID, startMockBlobStore } from '../utils/helpers.js'
7+
8+
getLogger().level = 'alert'
9+
10+
beforeEach<FixtureTestContext>(async (ctx) => {
11+
// set for each test a new deployID and siteID
12+
ctx.deployID = generateRandomObjectID()
13+
ctx.siteID = v4()
14+
vi.stubEnv('SITE_ID', ctx.siteID)
15+
vi.stubEnv('DEPLOY_ID', ctx.deployID)
16+
vi.stubEnv('NETLIFY_PURGE_API_TOKEN', 'fake-token')
17+
// hide debug logs in tests
18+
// vi.spyOn(console, 'debug').mockImplementation(() => {})
19+
20+
await startMockBlobStore(ctx)
21+
})
22+
23+
it<FixtureTestContext>('test', async (ctx) => {
24+
await createFixture('netlify-forms', ctx)
25+
26+
const runPluginPromise = runPlugin(ctx)
27+
28+
await expect(runPluginPromise).rejects.toThrow(
29+
'@netlify/plugin-next@5 does not support Netlify Forms',
30+
)
31+
})

0 commit comments

Comments
 (0)