Skip to content

Commit b72698c

Browse files
committed
test(hydrate): add hydrate tests to end-to-end test app
1 parent ce17750 commit b72698c

File tree

7 files changed

+189
-2
lines changed

7 files changed

+189
-2
lines changed

test/end-to-end/package-lock.json

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/end-to-end/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
"build": "node ../../bin/stencil build --docs",
1010
"start": "node ../../bin/stencil build --debug --watch --dev --serve",
1111
"test": "node ../../bin/stencil test --ci --e2e --spec --screenshot --debug",
12-
"test.dist": "npm run build && node test-end-to-end-dist.js",
12+
"test.dist": "npm run build && node test-end-to-end-dist.js && node test-end-to-end-hydrate.js",
1313
"test.e2e": "node ../../bin/stencil test --e2e",
14+
"test.hydrate": "node test-end-to-end-hydrate.js",
1415
"test.screenshot": "node ../../bin/stencil test --e2e --debug --screenshot",
1516
"test.spec": "node ../../bin/stencil test --spec --debug",
1617
"jest": "jest --coverage"
@@ -30,6 +31,7 @@
3031
"lodash-es": "^4.17.15",
3132
"rollup-plugin-css-only": "^2.1.0",
3233
"rollup-plugin-node-builtins": "^2.1.2",
33-
"video.js": "^7.8.4"
34+
"video.js": "^7.8.4",
35+
"why-is-node-running": "^2.2.0"
3436
}
3537
}

test/end-to-end/src/components.d.ts

+13
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ export namespace Components {
4343
}
4444
interface PathAliasCmp {
4545
}
46+
interface PrerenderCmp {
47+
}
4648
interface PropCmp {
4749
"first": string;
4850
"lastName": string;
@@ -140,6 +142,12 @@ declare global {
140142
prototype: HTMLPathAliasCmpElement;
141143
new (): HTMLPathAliasCmpElement;
142144
};
145+
interface HTMLPrerenderCmpElement extends Components.PrerenderCmp, HTMLStencilElement {
146+
}
147+
var HTMLPrerenderCmpElement: {
148+
prototype: HTMLPrerenderCmpElement;
149+
new (): HTMLPrerenderCmpElement;
150+
};
143151
interface HTMLPropCmpElement extends Components.PropCmp, HTMLStencilElement {
144152
}
145153
var HTMLPropCmpElement: {
@@ -184,6 +192,7 @@ declare global {
184192
"listen-cmp": HTMLListenCmpElement;
185193
"method-cmp": HTMLMethodCmpElement;
186194
"path-alias-cmp": HTMLPathAliasCmpElement;
195+
"prerender-cmp": HTMLPrerenderCmpElement;
187196
"prop-cmp": HTMLPropCmpElement;
188197
"slot-cmp": HTMLSlotCmpElement;
189198
"slot-cmp-container": HTMLSlotCmpContainerElement;
@@ -227,6 +236,8 @@ declare namespace LocalJSX {
227236
}
228237
interface PathAliasCmp {
229238
}
239+
interface PrerenderCmp {
240+
}
230241
interface PropCmp {
231242
"first"?: string;
232243
"lastName"?: string;
@@ -258,6 +269,7 @@ declare namespace LocalJSX {
258269
"listen-cmp": ListenCmp;
259270
"method-cmp": MethodCmp;
260271
"path-alias-cmp": PathAliasCmp;
272+
"prerender-cmp": PrerenderCmp;
261273
"prop-cmp": PropCmp;
262274
"slot-cmp": SlotCmp;
263275
"slot-cmp-container": SlotCmpContainer;
@@ -282,6 +294,7 @@ declare module "@stencil/core" {
282294
"listen-cmp": LocalJSX.ListenCmp & JSXBase.HTMLAttributes<HTMLListenCmpElement>;
283295
"method-cmp": LocalJSX.MethodCmp & JSXBase.HTMLAttributes<HTMLMethodCmpElement>;
284296
"path-alias-cmp": LocalJSX.PathAliasCmp & JSXBase.HTMLAttributes<HTMLPathAliasCmpElement>;
297+
"prerender-cmp": LocalJSX.PrerenderCmp & JSXBase.HTMLAttributes<HTMLPrerenderCmpElement>;
285298
"prop-cmp": LocalJSX.PropCmp & JSXBase.HTMLAttributes<HTMLPropCmpElement>;
286299
"slot-cmp": LocalJSX.SlotCmp & JSXBase.HTMLAttributes<HTMLSlotCmpElement>;
287300
"slot-cmp-container": LocalJSX.SlotCmpContainer & JSXBase.HTMLAttributes<HTMLSlotCmpContainerElement>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
:host {
2+
display: block;
3+
border: 2px solid black;
4+
border-radius: 10px;
5+
margin: 80px auto;
6+
padding: 40px 20px;
7+
max-width: 320px;
8+
text-align: center;
9+
font-size: 24px;
10+
font-weight: bold;
11+
background: #047aff;
12+
color: white;
13+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans',
14+
'Helvetica Neue', sans-serif;
15+
}
16+
17+
@media (max-width: 320px) {
18+
:host {
19+
background: maroon;
20+
font-family: 'Courier New', Courier, monospace;
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { Component, h } from '@stencil/core';
2+
import styles from './prerender-cmp.css';
3+
4+
@Component({
5+
tag: 'prerender-cmp',
6+
styles,
7+
shadow: true,
8+
})
9+
export class PrerenderCmp {
10+
render() {
11+
return [
12+
<div>a</div>,
13+
<div>b</div>,
14+
<div>
15+
<div>c</div>
16+
<div>
17+
{[
18+
<div>d</div>,
19+
<div>
20+
{[
21+
<div>e</div>,
22+
<div>f</div>,
23+
<div>g</div>,
24+
<div>h</div>,
25+
<div>i</div>,
26+
<div>j</div>,
27+
<div>k</div>,
28+
<div>l</div>,
29+
]}
30+
</div>,
31+
]}
32+
</div>
33+
</div>,
34+
<a href="/some-link">Some Link</a>
35+
];
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# prerender-cmp
2+
3+
4+
5+
<!-- Auto Generated Below -->
6+
7+
8+
----------------------------------------------
9+
10+
*Built with [StencilJS](https://stenciljs.com/)*
+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
const whyIsNodeRunning = require('why-is-node-running');
2+
const hydrate = require('./hydrate');
3+
const mockDoc = require('../../mock-doc');
4+
5+
async function main() {
6+
const html = `
7+
<html>
8+
<head><title>End To End</title></head>
9+
<body>
10+
<prerender-cmp></prerender-cmp>
11+
</body>
12+
</html>
13+
`;
14+
const opts = {
15+
prettyHtml: true,
16+
};
17+
const results = await hydrate.renderToString(html, opts);
18+
19+
console.log(results);
20+
21+
if (results.diagnostics.length > 0) {
22+
results.diagnostics.forEach(d => {
23+
console.error(`🧨 ${d.header}`);
24+
console.error(`🧨 ${d.messageText}`);
25+
});
26+
throw new Error(`validated test/end-to-end/hydrate errors!!`);
27+
}
28+
29+
if (results.hydratedCount !== 1) {
30+
throw new Error(`invalid hydratedCount: ${results.hydratedCount}`);
31+
}
32+
if (results.components.length !== 1 || results.components[0].tag !== 'prerender-cmp') {
33+
throw new Error(`invalid components: ${results.components}`);
34+
}
35+
if (results.httpStatus !== 200) {
36+
throw new Error(`invalid httpStatus: ${results.httpStatus}`);
37+
}
38+
if (results.anchors.length !== 1 || results.anchors[0].href !== `https://hydrate.stenciljs.com/some-link`) {
39+
throw new Error(`invalid anchors: ${results.anchors}`);
40+
}
41+
if (results.url !== `https://hydrate.stenciljs.com/`) {
42+
throw new Error(`invalid url: ${results.url}`);
43+
}
44+
if (results.title !== `End To End`) {
45+
throw new Error(`invalid title`);
46+
}
47+
if (typeof results.html !== `string`) {
48+
throw new Error(`missing html`);
49+
}
50+
51+
const doc = mockDoc.createDocument(results.html);
52+
if (doc.title !== 'End To End') {
53+
throw new Error(`invalid doc.title: ${doc.title}`);
54+
}
55+
if (!doc.documentElement.classList.contains('hydrated')) {
56+
throw new Error(`missing html hydrated`);
57+
}
58+
const cmp = doc.querySelector('prerender-cmp');
59+
if (!cmp) {
60+
throw new Error(`missing prerender-cmp`);
61+
}
62+
63+
clearTimeout(tmr);
64+
65+
console.log('🛁 validated test/end-to-end/hydrate\n');
66+
}
67+
68+
const tmr = setTimeout(() => {
69+
console.error(`validated test/end-to-end/hydrate timeout!`);
70+
process.exit(1);
71+
}, 10000);
72+
73+
main()
74+
.then(() => {
75+
whyIsNodeRunning();
76+
})
77+
.catch(e => {
78+
clearTimeout(tmr);
79+
console.error('🧨 ' + e + ' 🧨');
80+
process.exit(1);
81+
});

0 commit comments

Comments
 (0)