Skip to content

Commit aa2d3b5

Browse files
authored
fix(e2e): skip middleware placement test on nextjs 16+ (#7758)
1 parent 6c94da0 commit aa2d3b5

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

.changeset/flat-eggs-stick.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

integration/tests/middleware-placement.test.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ function parseSemverMajor(range?: string): number | undefined {
1515
return match ? Number.parseInt(match[0], 10) : undefined;
1616
}
1717

18+
function isCanaryVersion(version?: string | null): boolean {
19+
return Boolean(version && version.includes('canary'));
20+
}
21+
1822
/**
1923
* Detects the installed Next.js version for a given application.
2024
* Reads the version from node_modules/next/package.json to ensure
@@ -114,7 +118,7 @@ test.describe('next start - invalid middleware at root on src/ @quickstart', ()
114118
test('Does not display misplaced middleware error on Next 16+', async ({ page, context }) => {
115119
const { version } = await detectNext(app);
116120
const major = parseSemverMajor(version) ?? 0;
117-
test.skip(major < 16, 'Only applicable on Next 16+');
121+
test.skip(major < 16, 'Only applicable on Next 16+.');
118122
const u = createTestUtils({ app, page, context });
119123
await u.page.goToAppHome();
120124
expect(app.serveOutput).not.toContain('Clerk: clerkMiddleware() was not run');
@@ -142,11 +146,26 @@ test.describe('next start - invalid middleware inside app on src/ @quickstart',
142146
page,
143147
context,
144148
}) => {
149+
const { version } = await detectNext(app);
150+
const major = parseSemverMajor(version) ?? 0;
151+
const isCanary = isCanaryVersion(version);
152+
// Next 16 stable still shows this warning, only canary changed behavior
153+
test.skip(major >= 16 && isCanary, 'Middleware detection is smarter in Next 16 canary.');
145154
const u = createTestUtils({ app, page, context });
146155
await u.page.goToAppHome();
147156
expect(app.serveOutput).not.toContain('Your Middleware exists at ./src/middleware.(ts|js)');
148157
expect(app.serveOutput).toContain(
149158
'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',
150159
);
151160
});
161+
162+
test('Does not display misplaced middleware error on Next 16 canary', async ({ page, context }) => {
163+
const { version } = await detectNext(app);
164+
const major = parseSemverMajor(version) ?? 0;
165+
const isCanary = isCanaryVersion(version);
166+
test.skip(major < 16 || !isCanary, 'Only applicable on Next 16 canary.');
167+
const u = createTestUtils({ app, page, context });
168+
await u.page.goToAppHome();
169+
expect(app.serveOutput).not.toContain('Clerk: clerkMiddleware() was not run');
170+
});
152171
});

0 commit comments

Comments
 (0)