Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
5d1d674a
Unverified
Commit
5d1d674a
authored
Mar 12, 2024
by
Ethan Arrowood
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add more test coverage
parent
303969a0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
102 additions
and
11 deletions
+102
-11
node-web-streams-helper.test.ts
...t/src/server/stream-utils/node-web-streams-helper.test.ts
+102
-10
node-web-streams-helper.ts
...s/next/src/server/stream-utils/node-web-streams-helper.ts
+0
-1
No files found.
packages/next/src/server/stream-utils/node-web-streams-helper.test.ts
View file @
5d1d674a
...
...
@@ -6,6 +6,7 @@ import {
streamFromString
,
streamToString
,
type
ReactReadableStream
,
type
ContinueStreamOptions
,
}
from
'./node-web-streams-helper'
async
function
processReadableStream
(
...
...
@@ -36,6 +37,8 @@ async function assertEntireReadableStream(
actual
.
set
(
value
,
i
)
i
+=
value
.
length
;({
done
,
value
}
=
await
reader
.
read
())
console
.
log
(
new
TextDecoder
().
decode
(
actual
))
}
expect
(
actual
).
toStrictEqual
(
expected
)
}
...
...
@@ -291,7 +294,7 @@ describe('node-web-stream-helpers', () => {
describe
(
'pages router'
,
()
=>
{
const
defaultSuffix
=
'<suffix>suffix</suffix>'
// values hardcoded based on usage of `continueFizzStream` in `server/render.tsx`
const
defaultOptionsFactory
=
()
=>
({
const
defaultOptionsFactory
:
()
=>
ContinueStreamOptions
=
()
=>
({
isStaticGeneration
:
true
,
// always true
serverInsertedHTMLToHead
:
false
,
// always false
validateRootLayout
:
undefined
,
// always undefined
...
...
@@ -316,22 +319,94 @@ describe('node-web-stream-helpers', () => {
'<suffix>suffix</suffix>'
+
// suffix next
'</body></html>'
// and then closing tags last
)
assertEntireReadableStream
(
output
,
expected
)
await
assertEntireReadableStream
(
output
,
expected
)
})
it
(
'should inject closing html and body tags'
,
async
()
=>
{
const
input
:
ReactReadableStream
=
createMockReadableStream
({
input
:
`<html><head><title>My Website</title></head><body><div><h1>My Website</h1></div>`
,
byteCount
:
8
,
})
const
output
=
await
continueFizzStream
(
input
,
defaultOptionsFactory
())
const
expected
=
encoder
.
encode
(
'<server-html>Server HTML</server-html>'
+
// server-inserted happens first
'<html><head><title>My Website</title></head><body><div><h1>My Website</h1></div>'
+
// react content
'<data>inlined data</data>'
+
// inlined-data stream next
'<suffix>suffix</suffix>'
+
// suffix next
'</body></html>'
// and then closing tags last
)
await
assertEntireReadableStream
(
output
,
expected
)
})
it
(
'should detect close tags in suffix'
,
async
()
=>
{
const
input
:
ReactReadableStream
=
defaultReactReadableStreamFactory
()
const
options
=
defaultOptionsFactory
()
options
.
suffix
=
defaultSuffix
+
'</body></html>'
const
output
=
await
continueFizzStream
(
input
,
options
)
const
expected
=
encoder
.
encode
(
'<server-html>Server HTML</server-html>'
+
// server-inserted happens first
'<html><head><title>My Website</title></head><body><div><h1>My Website</h1></div>'
+
// react content
'<data>inlined data</data>'
+
// inlined-data stream next
'<suffix>suffix</suffix>'
+
// suffix next
'</body></html>'
// and then closing tags last
)
await
assertEntireReadableStream
(
output
,
expected
)
})
})
describe
(
'app router'
,
()
=>
{
// values set based on usage of `continueFizzStream` in `server/app-render.tsx`
const
defaultOptionsFactory
=
()
=>
({
const
defaultOptionsFactory
:
()
=>
ContinueStreamOptions
=
()
=>
({
inlinedDataStream
:
defaultInlinedDataStreamFactory
(),
getServerInsertedHTML
:
defaultGetServerInsertedHTMLFactory
(),
serverInsertedHTMLToHead
:
true
,
// always true
isStaticGeneration
:
true
,
// not always true, impacts `allReady` being awaited
})
it
(
'should continue fizz stream operation using default arguments'
,
async
()
=>
{
const
options
=
{
...
defaultOptionsFactory
(),
isStaticGeneration
:
true
,
// not always true, but impacts `allReady` being awaited
}
const
input
:
ReactReadableStream
=
defaultReactReadableStreamFactory
()
let
allReadyAwaited
=
false
input
.
allReady
=
setImmediate
().
then
(()
=>
{
allReadyAwaited
=
true
})
expect
(
allReadyAwaited
).
toBe
(
false
)
const
output
=
await
continueFizzStream
(
input
,
defaultOptionsFactory
())
expect
(
allReadyAwaited
).
toBe
(
true
)
const
expected
=
encoder
.
encode
(
'<html><head><title>My Website</title>'
+
// start react content
'<server-html>Server HTML</server-html>'
+
// server-inserted before end of `</head>` tag
'</head><body><div><h1>My Website</h1></div>'
+
// remaining react content
'<data>inlined data</data>'
+
// inlined data next
'</body></html>'
// closing tags last
)
await
assertEntireReadableStream
(
output
,
expected
)
})
it
(
'should inject closing html and body tags'
,
async
()
=>
{
const
input
:
ReactReadableStream
=
createMockReadableStream
({
input
:
`<html><head><title>My Website</title></head><body><div><h1>My Website</h1></div>`
,
byteCount
:
8
,
})
let
allReadyAwaited
=
false
input
.
allReady
=
setImmediate
().
then
(()
=>
{
allReadyAwaited
=
true
})
expect
(
allReadyAwaited
).
toBe
(
false
)
const
output
=
await
continueFizzStream
(
input
,
defaultOptionsFactory
())
expect
(
allReadyAwaited
).
toBe
(
true
)
const
expected
=
encoder
.
encode
(
'<html><head><title>My Website</title>'
+
// start react content
'<server-html>Server HTML</server-html>'
+
// server-inserted before end of `</head>` tag
'</head><body><div><h1>My Website</h1></div>'
+
// remaining react content
'<data>inlined data</data>'
+
// inlined data next
'</body></html>'
// closing tags last
)
await
assertEntireReadableStream
(
output
,
expected
)
})
it
(
'should not await `allReady` when isStaticGeneration is false'
,
async
()
=>
{
const
options
=
defaultOptionsFactory
()
options
.
isStaticGeneration
=
false
const
input
:
ReactReadableStream
=
defaultReactReadableStreamFactory
()
let
allReadyAwaited
=
false
...
...
@@ -340,7 +415,7 @@ describe('node-web-stream-helpers', () => {
})
expect
(
allReadyAwaited
).
toBe
(
false
)
const
output
=
await
continueFizzStream
(
input
,
options
)
expect
(
allReadyAwaited
).
toBe
(
true
)
expect
(
allReadyAwaited
).
toBe
(
false
)
// allReady should not get awaited
const
expected
=
encoder
.
encode
(
'<html><head><title>My Website</title>'
+
// start react content
'<server-html>Server HTML</server-html>'
+
// server-inserted before end of `</head>` tag
...
...
@@ -348,9 +423,26 @@ describe('node-web-stream-helpers', () => {
'<data>inlined data</data>'
+
// inlined data next
'</body></html>'
// closing tags last
)
assertEntireReadableStream
(
output
,
expected
)
await
assertEntireReadableStream
(
output
,
expected
)
})
it
(
'dev mode should validate existence of html and body tags'
,
async
()
=>
{
const
options
=
defaultOptionsFactory
()
options
.
validateRootLayout
=
true
const
input
:
ReactReadableStream
=
createMockReadableStream
({
input
:
`<head><title>My Website</title></head><div><h1>My Website</h1></div>`
,
byteCount
:
8
,
})
const
output
=
await
continueFizzStream
(
input
,
options
)
const
expected
=
encoder
.
encode
(
'<head><title>My Website</title>'
+
// start react content
'<server-html>Server HTML</server-html>'
+
// server-inserted before end of `</head>` tag
'</head><div><h1>My Website</h1></div>'
+
// remaining react content
'<data>inlined data</data>'
+
// inlined data next
'<script>self.__next_root_layout_missing_tags=["html","body"]</script>'
+
// missing tags script
'</body></html>'
// closing tags last
)
await
assertEntireReadableStream
(
output
,
expected
)
})
it
.
todo
(
'dev mode - (validateRootLayout = true)'
)
})
})
describe
(
'continueDynamicPrerender'
,
()
=>
{})
...
...
packages/next/src/server/stream-utils/node-web-streams-helper.ts
View file @
5d1d674a
...
...
@@ -538,7 +538,6 @@ export async function continueFizzStream(
// If we're generating static HTML and there's an `allReady` promise on the
// stream, we need to wait for it to resolve before continuing.
if
(
isStaticGeneration
&&
'allReady'
in
renderStream
)
{
console
.
log
(
'🧪'
)
await
renderStream
.
allReady
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment