Skip to content

Commit da5eb0b

Browse files
committed
test: add integration test for complete event
1 parent 5c2f1ea commit da5eb0b

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

tests/integration.basic.test.js

+63
Original file line numberDiff line numberDiff line change
@@ -624,3 +624,66 @@ tap.test('integration - 103 early hints disabled', async (t) => {
624624

625625
await server.close();
626626
});
627+
628+
tap.test(
629+
'integration - 103 early hints used to build a document head',
630+
async (t) => {
631+
t.plan(1);
632+
const header = new PodletServer({
633+
name: 'header',
634+
assets: {
635+
js: '/header/bar.js',
636+
css: '/header/bar.css',
637+
},
638+
});
639+
const footer = new PodletServer({
640+
name: 'footer',
641+
assets: {
642+
js: '/footer/bar.js',
643+
css: '/footer/bar.css',
644+
},
645+
});
646+
647+
const service = await Promise.all([header.listen(), footer.listen()]);
648+
649+
const client = new Client({ name: 'podiumClient' });
650+
651+
const headerClient = client.register(service[0].options);
652+
const footerClient = client.register(service[1].options);
653+
654+
const incoming = new HttpIncoming({ headers });
655+
656+
incoming.hints.once('complete', ({ js, css }) => {
657+
const documentHead = `
658+
<html>
659+
<head>
660+
${css.map((style) => style.toHTML()).join('')}
661+
${js.map((script) => script.toHTML()).join('')}
662+
</head>
663+
<body>
664+
`;
665+
666+
t.equal(
667+
documentHead.trim().replace(/>\s*</g, '><'),
668+
`<html>
669+
<head>
670+
<link href="/header/bar.css" type="text/css" rel="stylesheet">
671+
<link href="/footer/bar.css" type="text/css" rel="stylesheet">
672+
<script src="/header/bar.js"></script>
673+
<script src="/footer/bar.js"></script>
674+
</head>
675+
<body>`
676+
.trim()
677+
.replace(/>\s*</g, '><'),
678+
);
679+
t.end();
680+
});
681+
682+
await Promise.all([
683+
headerClient.fetch(incoming),
684+
footerClient.fetch(incoming),
685+
]);
686+
687+
await Promise.all([header.close(), footer.close()]);
688+
},
689+
);

0 commit comments

Comments
 (0)