-
Notifications
You must be signed in to change notification settings - Fork 26.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
220 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
test/integration/react-streaming-and-server-components/switchable-runtime/next.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const withReact18 = require('../../react-18/test/with-react-18') | ||
|
||
module.exports = withReact18({ | ||
reactStrictMode: true, | ||
experimental: { | ||
serverComponents: true, | ||
// runtime: 'edge', | ||
}, | ||
}) |
9 changes: 9 additions & 0 deletions
9
test/integration/react-streaming-and-server-components/switchable-runtime/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"private": true, | ||
"scripts": { | ||
"lnext": "node -r ../../react-18/test/require-hook.js ../../../../packages/next/dist/bin/next", | ||
"dev": "yarn lnext dev", | ||
"build": "yarn lnext build", | ||
"start": "yarn lnext start" | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
.../integration/react-streaming-and-server-components/switchable-runtime/pages-manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"/_app": "pages/_app.js", | ||
"/_error": "pages/_error.js", | ||
"/edge-rsc": "pages/edge-rsc.js", | ||
"/static": "pages/static.js", | ||
"/node-rsc": "pages/node-rsc.js", | ||
"/node": "pages/node.js", | ||
"/edge": "pages/edge.js" | ||
} |
18 changes: 18 additions & 0 deletions
18
...gration/react-streaming-and-server-components/switchable-runtime/pages/edge-rsc.server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import getRuntime from '../utils/runtime' | ||
import getTime from '../utils/time' | ||
|
||
export default function Page() { | ||
return ( | ||
<div> | ||
This is a SSR RSC page. | ||
<br /> | ||
{'Runtime: ' + getRuntime()} | ||
<br /> | ||
{'Time: ' + getTime()} | ||
</div> | ||
) | ||
} | ||
|
||
export const config = { | ||
runtime: 'edge', | ||
} |
18 changes: 18 additions & 0 deletions
18
test/integration/react-streaming-and-server-components/switchable-runtime/pages/edge.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import getRuntime from '../utils/runtime' | ||
import getTime from '../utils/time' | ||
|
||
export default function Page() { | ||
return ( | ||
<div> | ||
This is a SSR page. | ||
<br /> | ||
{'Runtime: ' + getRuntime()} | ||
<br /> | ||
{'Time: ' + getTime()} | ||
</div> | ||
) | ||
} | ||
|
||
export const config = { | ||
runtime: 'edge', | ||
} |
18 changes: 18 additions & 0 deletions
18
...gration/react-streaming-and-server-components/switchable-runtime/pages/node-rsc.server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import getRuntime from '../utils/runtime' | ||
import getTime from '../utils/time' | ||
|
||
export default function Page() { | ||
return ( | ||
<div> | ||
This is a static RSC page. | ||
<br /> | ||
{'Runtime: ' + getRuntime()} | ||
<br /> | ||
{'Time: ' + getTime()} | ||
</div> | ||
) | ||
} | ||
|
||
export const config = { | ||
runtime: 'nodejs', | ||
} |
18 changes: 18 additions & 0 deletions
18
test/integration/react-streaming-and-server-components/switchable-runtime/pages/node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import getRuntime from '../utils/runtime' | ||
import getTime from '../utils/time' | ||
|
||
export default function Page() { | ||
return ( | ||
<div> | ||
This is a static page. | ||
<br /> | ||
{'Runtime: ' + getRuntime()} | ||
<br /> | ||
{'Time: ' + getTime()} | ||
</div> | ||
) | ||
} | ||
|
||
export const config = { | ||
runtime: 'nodejs', | ||
} |
14 changes: 14 additions & 0 deletions
14
test/integration/react-streaming-and-server-components/switchable-runtime/pages/static.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import getRuntime from '../utils/runtime' | ||
import getTime from '../utils/time' | ||
|
||
export default function Page() { | ||
return ( | ||
<div> | ||
This is a static page. | ||
<br /> | ||
{'Runtime: ' + getRuntime()} | ||
<br /> | ||
{'Time: ' + getTime()} | ||
</div> | ||
) | ||
} |
3 changes: 3 additions & 0 deletions
3
test/integration/react-streaming-and-server-components/switchable-runtime/utils/runtime.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function getRuntime() { | ||
return process.version ? `Node.js ${process.version}` : 'Edge/Browser' | ||
} |
3 changes: 3 additions & 0 deletions
3
test/integration/react-streaming-and-server-components/switchable-runtime/utils/time.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function getTime() { | ||
return Date.now() | ||
} |
101 changes: 101 additions & 0 deletions
101
test/integration/react-streaming-and-server-components/test/switchable-runtime.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* eslint-env jest */ | ||
|
||
import { join } from 'path' | ||
import { | ||
File, | ||
nextBuild as _nextBuild, | ||
nextStart as _nextStart, | ||
} from 'next-test-utils' | ||
|
||
import { findPort, killApp, renderViaHTTP } from 'next-test-utils' | ||
|
||
const nodeArgs = ['-r', join(__dirname, '../../react-18/test/require-hook.js')] | ||
|
||
const appDir = join(__dirname, '../switchable-runtime') | ||
// const nextConfig = new File(join(appDir, 'next.config.js')) | ||
|
||
async function nextBuild(dir, options) { | ||
return await _nextBuild(dir, [], { | ||
...options, | ||
stdout: true, | ||
stderr: true, | ||
nodeArgs, | ||
}) | ||
} | ||
|
||
async function nextStart(dir, port) { | ||
return await _nextStart(dir, port, { | ||
stdout: true, | ||
stderr: true, | ||
nodeArgs, | ||
}) | ||
} | ||
|
||
async function testRoute(appPort, url, { isStatic, isEdge }) { | ||
const html1 = await renderViaHTTP(appPort, url) | ||
const renderedAt1 = +html1.match(/Time: (\d+)/)[1] | ||
expect(html1).toContain(`Runtime: ${isEdge ? 'Edge' : 'Node.js'}`) | ||
|
||
const html2 = await renderViaHTTP(appPort, url) | ||
const renderedAt2 = +html2.match(/Time: (\d+)/)[1] | ||
expect(html2).toContain(`Runtime: ${isEdge ? 'Edge' : 'Node.js'}`) | ||
|
||
if (isStatic) { | ||
// Should not be re-rendered, some timestamp should be returned. | ||
expect(renderedAt1).toBe(renderedAt2) | ||
} else { | ||
// Should be re-rendered. | ||
expect(renderedAt1).toBeLessThan(renderedAt2) | ||
} | ||
} | ||
|
||
describe('Without global runtime configuration', () => { | ||
const context = { appDir } | ||
|
||
beforeAll(async () => { | ||
// error500Page.write(page500) | ||
context.appPort = await findPort() | ||
const { stderr } = await nextBuild(context.appDir) | ||
context.stderr = stderr | ||
context.server = await nextStart(context.appDir, context.appPort) | ||
}) | ||
afterAll(async () => { | ||
// error500Page.delete() | ||
await killApp(context.server) | ||
}) | ||
|
||
it('should build /static as a static page with the nodejs runtime', async () => { | ||
await testRoute(context.appPort, '/static', { | ||
isStatic: true, | ||
isEdge: false, | ||
}) | ||
}) | ||
|
||
it('should build /node as a static page with the nodejs runtime', async () => { | ||
await testRoute(context.appPort, '/node', { | ||
isStatic: true, | ||
isEdge: false, | ||
}) | ||
}) | ||
|
||
it('should build /node-rsc as a static page with the nodejs runtime', async () => { | ||
await testRoute(context.appPort, '/node-rsc', { | ||
isStatic: true, | ||
isEdge: false, | ||
}) | ||
}) | ||
|
||
it('should build /edge as a dynamic page with the edge runtime', async () => { | ||
await testRoute(context.appPort, '/edge', { | ||
isStatic: false, | ||
isEdge: true, | ||
}) | ||
}) | ||
|
||
it('should build /edge-rsc as a dynamic page with the edge runtime', async () => { | ||
await testRoute(context.appPort, '/edge-rsc', { | ||
isStatic: false, | ||
isEdge: true, | ||
}) | ||
}) | ||
}) |