-
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.
feat: fail build when netlify form detected (#2512)
* feat: verify no netlify forms * test: ensure build is failed when netlify forms detected * chore: format with prettier * feat: make verification passive by outputing warning * feat: include static content for forms verification * test: skip forms verification test until we are failing the build * feat: also verify no netlify forms for APP_PAGE * Update tests/integration/netlify-forms.test.ts Co-authored-by: Michal Piechowiak <[email protected]> --------- Co-authored-by: orinokai <[email protected]> Co-authored-by: Michal Piechowiak <[email protected]>
- Loading branch information
1 parent
62ab214
commit 195b8b2
Showing
11 changed files
with
134 additions
and
7 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
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
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
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,12 @@ | ||
export const metadata = { | ||
title: 'Netlify Forms', | ||
description: 'Test for verifying Netlify Forms', | ||
} | ||
|
||
export default function RootLayout({ children }) { | ||
return ( | ||
<html lang="en"> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
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 Page() { | ||
return ( | ||
<form data-netlify="true"> | ||
<button type="submit">Send</button> | ||
</form> | ||
) | ||
} |
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 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/image-types/global" /> | ||
|
||
// NOTE: This file should not be edited | ||
// see https://nextjs.org/docs/basic-features/typescript for more information. |
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,10 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
output: 'standalone', | ||
eslint: { | ||
ignoreDuringBuilds: true, | ||
}, | ||
generateBuildId: () => 'build-id', | ||
} | ||
|
||
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,19 @@ | ||
{ | ||
"name": "netlify-forms", | ||
"version": "0.1.0", | ||
"private": true, | ||
"scripts": { | ||
"postinstall": "next build", | ||
"dev": "next dev", | ||
"build": "next build" | ||
}, | ||
"dependencies": { | ||
"@netlify/functions": "^2.7.0", | ||
"next": "latest", | ||
"react": "18.2.0", | ||
"react-dom": "18.2.0" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "18.2.75" | ||
} | ||
} |
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,23 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["dom", "dom.iterable", "esnext"], | ||
"allowJs": true, | ||
"skipLibCheck": true, | ||
"strict": false, | ||
"noEmit": true, | ||
"incremental": true, | ||
"esModuleInterop": true, | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"jsx": "preserve", | ||
"plugins": [ | ||
{ | ||
"name": "next" | ||
} | ||
] | ||
}, | ||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], | ||
"exclude": ["node_modules"] | ||
} |
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
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,32 @@ | ||
import { getLogger } from 'lambda-local' | ||
import { v4 } from 'uuid' | ||
import { beforeEach, expect, it, vi } from 'vitest' | ||
import { type FixtureTestContext } from '../utils/contexts.js' | ||
import { createFixture, runPlugin } from '../utils/fixture.js' | ||
import { generateRandomObjectID, startMockBlobStore } from '../utils/helpers.js' | ||
|
||
getLogger().level = 'alert' | ||
|
||
beforeEach<FixtureTestContext>(async (ctx) => { | ||
// set for each test a new deployID and siteID | ||
ctx.deployID = generateRandomObjectID() | ||
ctx.siteID = v4() | ||
vi.stubEnv('SITE_ID', ctx.siteID) | ||
vi.stubEnv('DEPLOY_ID', ctx.deployID) | ||
vi.stubEnv('NETLIFY_PURGE_API_TOKEN', 'fake-token') | ||
// hide debug logs in tests | ||
// vi.spyOn(console, 'debug').mockImplementation(() => {}) | ||
|
||
await startMockBlobStore(ctx) | ||
}) | ||
|
||
// test skipped until we actually start failing builds - right now we are just showing a warning | ||
it.skip<FixtureTestContext>('should fail build when netlify forms are used', async (ctx) => { | ||
await createFixture('netlify-forms', ctx) | ||
|
||
const runPluginPromise = runPlugin(ctx) | ||
|
||
await expect(runPluginPromise).rejects.toThrow( | ||
'@netlify/plugin-next@5 does not support Netlify Forms', | ||
) | ||
}) |