-
Notifications
You must be signed in to change notification settings - Fork 402
test(nextjs): E2E tests for middleware file placement #5037
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0281b07
test(nextjs): E2E tests for middleware file placement
panteliselef 4b8c0ec
cleanup
panteliselef 70c6699
Merge branch 'main' into elef/e2e-middleware-placement
panteliselef 02e2780
Merge branch 'main' into elef/e2e-middleware-placement
panteliselef File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| --- | ||
| --- |
This file contains hidden or 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 hidden or 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 hidden or 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,99 @@ | ||
| import { expect, test } from '@playwright/test'; | ||
|
|
||
| import type { Application } from '../models/application'; | ||
| import { appConfigs } from '../presets'; | ||
| import { createTestUtils } from '../testUtils'; | ||
|
|
||
| const middlewareFileContents = ` | ||
| import { clerkMiddleware } from '@clerk/nextjs/server'; | ||
| export default clerkMiddleware(); | ||
|
|
||
| export const config = { | ||
| matcher: ['/((?!.*\\..*|_next).*)', '/', '/(api|trpc)(.*)'], | ||
| }; | ||
| `; | ||
|
|
||
| const commonSetup = appConfigs.next.appRouterQuickstart.clone().removeFile('src/middleware.ts'); | ||
alexcarpenter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| test.describe('next start - missing middleware @quickstart', () => { | ||
alexcarpenter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| test.describe.configure({ mode: 'parallel' }); | ||
| let app: Application; | ||
|
|
||
| test.beforeAll(async () => { | ||
| app = await commonSetup.commit(); | ||
| await app.setup(); | ||
| await app.withEnv(appConfigs.envs.withEmailCodesQuickstart); | ||
| await app.build(); | ||
| await app.serve(); | ||
| }); | ||
|
|
||
| test.afterAll(async () => { | ||
| await app.teardown(); | ||
| }); | ||
|
|
||
| test('Display error for missing middleware', async ({ page, context }) => { | ||
| const u = createTestUtils({ app, page, context }); | ||
| await u.page.goToAppHome(); | ||
|
|
||
| expect(app.serveOutput).toContain('Your Middleware exists at ./src/middleware.(ts|js)'); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe('next start - invalid middleware at root on src/ @quickstart', () => { | ||
| test.describe.configure({ mode: 'parallel' }); | ||
| let app: Application; | ||
|
|
||
| test.beforeAll(async () => { | ||
| app = await commonSetup.addFile('middleware.ts', () => middlewareFileContents).commit(); | ||
| await app.setup(); | ||
| await app.withEnv(appConfigs.envs.withEmailCodesQuickstart); | ||
| await app.build(); | ||
| await app.serve(); | ||
| }); | ||
|
|
||
| test.afterAll(async () => { | ||
| await app.teardown(); | ||
| }); | ||
|
|
||
| test('Display suggestion for moving middleware to from `./middleware.ts` to `./src/middleware.ts`', async ({ | ||
| page, | ||
| context, | ||
| }) => { | ||
| const u = createTestUtils({ app, page, context }); | ||
| await u.page.goToAppHome(); | ||
|
|
||
| expect(app.serveOutput).not.toContain('Your Middleware exists at ./src/middleware.(ts|js)'); | ||
| expect(app.serveOutput).toContain( | ||
| 'Clerk: clerkMiddleware() was not run, your middleware file might be misplaced. Move your middleware file to ./src/middleware.ts. Currently located at ./middleware.ts', | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe('next start - invalid middleware inside app on src/ @quickstart', () => { | ||
| test.describe.configure({ mode: 'parallel' }); | ||
| let app: Application; | ||
|
|
||
| test.beforeAll(async () => { | ||
| app = await commonSetup.addFile('src/app/middleware.ts', () => middlewareFileContents).commit(); | ||
| await app.setup(); | ||
| await app.withEnv(appConfigs.envs.withEmailCodesQuickstart); | ||
| await app.build(); | ||
| await app.serve(); | ||
| }); | ||
|
|
||
| test.afterAll(async () => { | ||
| await app.teardown(); | ||
| }); | ||
|
|
||
| test('Display suggestion for moving middleware to from `./src/app/middleware.ts` to `./src/middleware.ts`', async ({ | ||
| page, | ||
| context, | ||
| }) => { | ||
| const u = createTestUtils({ app, page, context }); | ||
| await u.page.goToAppHome(); | ||
| expect(app.serveOutput).not.toContain('Your Middleware exists at ./src/middleware.(ts|js)'); | ||
| expect(app.serveOutput).toContain( | ||
| 'Clerk: clerkMiddleware() was not run, your middleware file might be misplaced. Move your middleware file to ./src/middleware.ts. Currently located at ./src/app/middleware.ts', | ||
| ); | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.