Skip to content

Commit

Permalink
feat: fail build when netlify forms detected without workaround (#2539)
Browse files Browse the repository at this point in the history
* feat: fail build when netlify forms detected without workaround

* test: update forms tests

* feat: check env var before verifying netlify forms
  • Loading branch information
orinokai authored Jul 29, 2024
1 parent f02ef88 commit 56fef5f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/build/verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ export async function verifyNetlifyFormsWorkaround(ctx: PluginContext) {

export function verifyNetlifyForms(ctx: PluginContext, html: string) {
if (
!verifications.has('netlifyForms') &&
process.env.NETLIFY_NEXT_VERIFY_FORMS !== '0' &&
process.env.NETLIFY_NEXT_VERIFY_FORMS?.toUpperCase() !== 'FALSE' &&
!verifications.has('netlifyFormsWorkaround') &&
formDetectionRegex.test(html)
) {
console.warn(
ctx.failBuild(
'@netlify/plugin-nextjs@5 requires migration steps to support Netlify Forms. Refer to https://ntl.fyi/next-runtime-forms-migration for migration example.',
)
verifications.add('netlifyForms')
}
}
12 changes: 6 additions & 6 deletions tests/integration/netlify-forms.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@ beforeEach<FixtureTestContext>(async (ctx) => {
await startMockBlobStore(ctx)
})

it<FixtureTestContext>('should warn when netlify forms are used', async (ctx) => {
it<FixtureTestContext>('should fail build when netlify forms are used', async (ctx) => {
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})

await createFixture('netlify-forms', ctx)

const runPluginPromise = await runPlugin(ctx)
const runPluginPromise = runPlugin(ctx)

expect(warn).toBeCalledWith(
await expect(runPluginPromise).rejects.toThrow(
'@netlify/plugin-nextjs@5 requires migration steps to support Netlify Forms. Refer to https://ntl.fyi/next-runtime-forms-migration for migration example.',
)
})

it<FixtureTestContext>('should not warn when netlify forms are used with workaround', async (ctx) => {
it<FixtureTestContext>('should not fail build when netlify forms are used with workaround', async (ctx) => {
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})

await createFixture('netlify-forms-workaround', ctx)

const runPluginPromise = await runPlugin(ctx)
const runPluginPromise = runPlugin(ctx)

expect(warn).not.toBeCalled()
await expect(runPluginPromise).resolves
})

0 comments on commit 56fef5f

Please sign in to comment.