Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add basic tests for stream renderers w/ full HTML doc #416

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions test/compat/stream-node.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,41 @@ describe('renderToPipeableStream', () => {
'</div>'
]);
});

it('should render full html documents', async () => {
const { Suspender, suspended } = createSuspender();

const sink = createSink();
const { pipe } = renderToPipeableStream(
<html lang="en">
<head>
<meta charSet="utf-8" />
</head>
<body>
<div>
<Suspense fallback="loading...">
<Suspender />
</Suspense>
</div>
</body>
</html>,
{
onShellReady: () => {
pipe(sink.stream);
}
}
);
suspended.resolve();

const result = await sink.promise;

expect(result).to.deep.equal([
'<html lang="en"><head><meta charset="utf-8"/></head><body><div><!--preact-island:54-->loading...<!--/preact-island:54--></div>',
'<div hidden>',
createInitScript(),
createSubtree('54', '<p>it works</p>'),
'</div>',
'</body></html>'
]);
});
});
36 changes: 34 additions & 2 deletions test/compat/stream.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,43 @@ describe('renderToReadableStream', () => {
const result = await sink.promise;

expect(result).to.deep.equal([
'<div><!--preact-island:54-->loading...<!--/preact-island:54--></div>',
'<div><!--preact-island:63-->loading...<!--/preact-island:63--></div>',
'<div hidden>',
createInitScript(),
createSubtree('54', '<p>it works</p>'),
createSubtree('63', '<p>it works</p>'),
'</div>'
]);
});

it('should render full html documents', async () => {
const { Suspender, suspended } = createSuspender();

const stream = renderToReadableStream(
<html lang="en">
<head>
<meta charSet="utf-8" />
</head>
<body>
<div>
<Suspense fallback="loading...">
<Suspender />
</Suspense>
</div>
</body>
</html>
);
const sink = createSink(stream);
suspended.resolve();

const result = await sink.promise;

expect(result).to.deep.equal([
'<html lang="en"><head><meta charset="utf-8"/></head><body><div><!--preact-island:70-->loading...<!--/preact-island:70--></div>',
'<div hidden>',
createInitScript(),
createSubtree('70', '<p>it works</p>'),
'</div>',
'</body></html>'
]);
});
});
Loading