MCPcopy
hub / github.com/vercel/next.js / runTests

Function runTests

test/e2e/middleware-general/test/index.test.ts:106–858  ·  view source on GitHub ↗
({ i18n }: { i18n?: boolean })

Source from the content-addressed store, hash-verified

104 }
105
106 function runTests({ i18n }: { i18n?: boolean }) {
107 it('should not treat as _next/data request with just header', async () => {
108 const res = await next.fetch('/redirect-to-somewhere', {
109 redirect: 'manual',
110 headers: {
111 'x-nextjs-data': '1',
112 },
113 })
114
115 expect(res.status).toBe(307)
116 expect(res.headers.get('Location')).toContain('/somewhere')
117 expect(res.headers.get('x-nextjs-redirect')).toBe(null)
118 })
119
120 if (isNodeMiddleware) {
121 it('should be able to use node builtins with node runtime', async () => {
122 const res = await next.fetch('/test-node-fs')
123 expect(res.status).toBe(200)
124
125 const body = await res.json()
126 expect(body.dependencies || body.devDependencies).toBeTruthy()
127 })
128
129 if (isNextStart) {
130 it('should have added middleware in functions manifest', async () => {
131 const { functions } = await next.readJSON(
132 '.next/server/functions-config-manifest.json'
133 )
134
135 expect(functions['/_middleware']).toEqual({
136 runtime: 'nodejs',
137 matchers: [
138 {
139 regexp: '^.*$',
140 originalSource: '/:path*',
141 },
142 ],
143 })
144 })
145 }
146 }
147
148 it('should handle 404 on fallback: false route correctly', async () => {
149 const res = await next.fetch('/ssg-fallback-false/first')
150 expect(res.status).toBe(200)
151 expect(await res.text()).toContain('blog')
152
153 const res2 = await next.fetch('/ssg-fallback-false/non-existent')
154 expect(res2.status).toBe(404)
155 })
156
157 it('should work with notFound: true correctly', async () => {
158 const browser = await next.browser('/ssr-page')
159 await browser.eval('window.next.router.push("/ssg/not-found-1")')
160
161 await check(
162 () => browser.eval('document.documentElement.innerHTML'),
163 /This page could not be found/

Callers 1

index.test.tsFile · 0.70

Calls 15

checkFunction · 0.90
fetchViaHTTPFunction · 0.90
joinFunction · 0.90
waitForFunction · 0.90
webdriverFunction · 0.85
readMiddlewareJSONFunction · 0.85
readMiddlewareErrorFunction · 0.85
readJSONMethod · 0.80
browserMethod · 0.80
evalMethod · 0.80
elementByCssMethod · 0.80
readFileSyncMethod · 0.80

Tested by

no test coverage detected