)
}
diff --git a/test/integration/middleware/core/test/index.test.js b/test/integration/middleware/core/test/index.test.js
index d85a53826ad6..0d53fca1c9ff 100644
--- a/test/integration/middleware/core/test/index.test.js
+++ b/test/integration/middleware/core/test/index.test.js
@@ -488,6 +488,17 @@ function rewriteTests(log, locale = '') {
const element = await browser.elementByCss('.title')
expect(await element.text()).toEqual('About Bypassed Page')
})
+
+ it(`${locale} should not call middleware with shallow push`, async () => {
+ const browser = await webdriver(context.appPort, '/rewrites')
+ await browser.elementByCss('#link-to-shallow-push').click()
+ await browser.waitForCondition(
+ 'new URL(window.location.href).searchParams.get("path") === "rewrite-me-without-hard-navigation"'
+ )
+ await expect(async () => {
+ await browser.waitForElementByCss('.refreshed', 500)
+ }).rejects.toThrow()
+ })
}
function redirectTests(locale = '') {
diff --git a/test/production/reading-request-body-in-middleware/index.test.ts b/test/production/reading-request-body-in-middleware/index.test.ts
index 0f1d61ccfa92..9e64502d8665 100644
--- a/test/production/reading-request-body-in-middleware/index.test.ts
+++ b/test/production/reading-request-body-in-middleware/index.test.ts
@@ -16,7 +16,11 @@ describe('reading request body in middleware', () => {
return new Response('No body', { status: 400 });
}
- const json = await request.json();
+ let json;
+
+ if (!request.nextUrl.searchParams.has("no_reading")) {
+ json = await request.json();
+ }
if (request.nextUrl.searchParams.has("next")) {
const res = NextResponse.next();
@@ -141,4 +145,30 @@ describe('reading request body in middleware', () => {
})
expect(response.headers.get('x-from-root-middleware')).toEqual('1')
})
+
+ it('passes the body to the api endpoint when no body is consumed on middleware', async () => {
+ const response = await fetchViaHTTP(
+ next.url,
+ '/api/hi',
+ {
+ next: '1',
+ no_reading: '1',
+ },
+ {
+ method: 'POST',
+ headers: {
+ 'content-type': 'application/json',
+ },
+ body: JSON.stringify({
+ foo: 'bar',
+ }),
+ }
+ )
+ expect(response.status).toEqual(200)
+ expect(await response.json()).toEqual({
+ foo: 'bar',
+ api: true,
+ })
+ expect(response.headers.get('x-from-root-middleware')).toEqual('1')
+ })
})