()
| 12 | }) |
| 13 | |
| 14 | function runTests() { |
| 15 | const routes = [ |
| 16 | // app client components pages |
| 17 | '/app/client', |
| 18 | '/app/client-edge', |
| 19 | // app sever components pages |
| 20 | '/app/server', |
| 21 | '/app/server-edge', |
| 22 | // app routes |
| 23 | '/app/route', |
| 24 | '/app/route-edge', |
| 25 | // pages/api |
| 26 | '/api/default', |
| 27 | '/api/default-edge', |
| 28 | '/api/server-only', |
| 29 | '/api/server-only-edge', |
| 30 | '/api/mixed', |
| 31 | ] |
| 32 | |
| 33 | for (const route of routes) { |
| 34 | it(`should render routes marked with restriction marks without errors ${route}`, async () => { |
| 35 | const { status } = await next.fetch(route) |
| 36 | expect([route, status]).toEqual([route, 200]) |
| 37 | }) |
| 38 | } |
| 39 | |
| 40 | it('should render installed react-server condition for middleware', async () => { |
| 41 | const json = await next.fetch('/middleware').then((res) => res.json()) |
| 42 | expect(json.React).toContain('version') // basic react-server export |
| 43 | expect(json.React).not.toContain('useEffect') // no client api export |
| 44 | }) |
| 45 | |
| 46 | // This is for backward compatibility, don't change react usage in existing pages/api |
| 47 | it('should contain client react exports for pages api', async () => { |
| 48 | async function verifyReactExports(route, isEdge) { |
| 49 | const json = await next.fetch(route).then((res) => res.json()) |
| 50 | // contain all react-server and default condition exports |
| 51 | expect(json.React).toContain('version') |
| 52 | expect(json.React).toContain('useEffect') |
| 53 | |
| 54 | // contain react-dom-server default condition exports |
| 55 | expect(json.ReactDomServer).toContain('version') |
| 56 | expect(json.ReactDomServer).toContain('renderToString') |
| 57 | expect(json.ReactDomServer).toContain('renderToStaticMarkup') |
| 58 | if (isEdge) { |
| 59 | expect(json.ReactDomServer).toContain('renderToReadableStream') |
| 60 | } else if (isNextDeploy) { |
| 61 | // Deploy mode can expose either server stream API depending on runtime |
| 62 | // and bundling path, so accept both for non-edge pages/api coverage. |
| 63 | expect( |
| 64 | json.ReactDomServer.some( |
| 65 | (name) => |
| 66 | name === 'renderToPipeableStream' || |
| 67 | name === 'renderToReadableStream' |
| 68 | ) |
| 69 | ).toBe(true) |
| 70 | } else { |
| 71 | expect(json.ReactDomServer).toContain('renderToPipeableStream') |
no test coverage detected