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

Function runTests

test/e2e/module-layer/module-layer.test.ts:14–111  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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')

Callers 1

Calls 8

verifyReactExportsFunction · 0.85
thenMethod · 0.80
itFunction · 0.50
expectFunction · 0.50
fetchMethod · 0.45
jsonMethod · 0.45
parseMethod · 0.45
readFileMethod · 0.45

Tested by

no test coverage detected