({ i18n }: { i18n?: boolean })
| 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/ |
no test coverage detected