Skip to content

Commit 128458d

Browse files
committed
chore(e2e): show size increase, manifest hash
1 parent 581a96e commit 128458d

3 files changed

Lines changed: 48 additions & 16 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<!DOCTYPE html><html lang="en" q:render="static-ssr" q:route="/" q:container="paused" q:runtime="2" q:base="/build/" q:locale="" q:manifest-hash="[manifest]" q:instance="[instance]" :><head :><link rel="modulepreload" href="/build/q-xxxxxxxx.js" :><script async type="module" src="/build/q-xxxxxxxx.js" :></script><link rel="modulepreload" href="/build/q-xxxxxxxx.js" :><link rel="preload" href="/assets/xxxxxxxx-bundle-graph.json" as="fetch" crossorigin="anonymous" :><script type="module" async crossorigin="anonymous" :>let b=fetch("/assets/xxxxxxxx-bundle-graph.json");import("/build/q-xxxxxxxx.js").then(({l})=>l("/build/",b));</script><link rel="modulepreload" href="/build/q-xxxxxxxx.js" :><meta : charset="utf-8"><meta : name="viewport" content="width=device-width, initial-scale=1.0"><link : rel="canonical" href="https://snapshot.qwik.dev/"><title :="r5_0">Qwik Router SSG Snapshot</title><meta name="description" content="Deterministic SSG snapshot fixture" :="r5_1"><style :="ji2uyl-0" q:style="ji2uyl-0">@layer qwik{@supports selector(html:active-view-transition-type(type)){html:active-view-transition-type(qwik-navigation){:root{view-transition-name:none}}}@supports not selector(html:active-view-transition-type(type)){:root{view-transition-name:none}}}</style></head><body :><main :="q1_2"><h1 :>SSG Snapshot Fixture</h1><p : id="tags">routeLoader$ | useResource$ | useSignal</p><section : id="loader-json">{&quot;heading&quot;:&quot;SSG Snapshot Fixture&quot;,&quot;stats&quot;:[2,3,5,8],&quot;tags&quot;:[&quot;routeLoader$&quot;,&quot;useResource$&quot;,&quot;useSignal&quot;],&quot;profile&quot;:{&quot;name&quot;:&quot;router-state&quot;,&quot;status&quot;:&quot;stable&quot;}}</section><section : id="summary-json">{&quot;total&quot;:18,&quot;selectedCount&quot;:2,&quot;clicks&quot;:2}</section><section :="q1_0" id="resource-json">{&quot;headline&quot;:&quot;router-state:stable&quot;,&quot;selected&quot;:[&quot;alpha&quot;,&quot;beta&quot;],&quot;weighted&quot;:[2,6,15,32],&quot;summary&quot;:{&quot;total&quot;:18,&quot;selectedCount&quot;:2,&quot;clicks&quot;:2}}</section></main><script q-d:qinit="q-xxxxxxxx.js#_run#1" q-d:qrouterpopstate="q-xxxxxxxx.js#_run#2" q:p="3" :="Fn_1" q-d:qcinit="q-xxxxxxxx.js#_run#4"></script>[state omitted]
1+
<!DOCTYPE html><html lang="en" q:render="static-ssr" q:route="/" q:container="paused" q:runtime="2" q:base="/build/" q:locale="" q:manifest-hash="MANIFEST_HASH" q:instance="[instance]" :><head :><link rel="modulepreload" href="/build/q-xxxxxxxx.js" :><script async type="module" src="/build/q-xxxxxxxx.js" :></script><link rel="modulepreload" href="/build/q-xxxxxxxx.js" :><link rel="preload" href="/assets/xxxxxxxx-bundle-graph.json" as="fetch" crossorigin="anonymous" :><script type="module" async crossorigin="anonymous" :>let b=fetch("/assets/xxxxxxxx-bundle-graph.json");import("/build/q-xxxxxxxx.js").then(({l})=>l("/build/",b));</script><link rel="modulepreload" href="/build/q-xxxxxxxx.js" :><meta : charset="utf-8"><meta : name="viewport" content="width=device-width, initial-scale=1.0"><link : rel="canonical" href="https://snapshot.qwik.dev/"><title :="r5_0">Qwik Router SSG Snapshot</title><meta name="description" content="Deterministic SSG snapshot fixture" :="r5_1"><style :="ji2uyl-0" q:style="ji2uyl-0">@layer qwik{@supports selector(html:active-view-transition-type(type)){html:active-view-transition-type(qwik-navigation){:root{view-transition-name:none}}}@supports not selector(html:active-view-transition-type(type)){:root{view-transition-name:none}}}</style></head><body :><main :="q1_2"><h1 :>SSG Snapshot Fixture</h1><p : id="tags">routeLoader$ | useResource$ | useSignal</p><section : id="loader-json">{&quot;heading&quot;:&quot;SSG Snapshot Fixture&quot;,&quot;stats&quot;:[2,3,5,8],&quot;tags&quot;:[&quot;routeLoader$&quot;,&quot;useResource$&quot;,&quot;useSignal&quot;],&quot;profile&quot;:{&quot;name&quot;:&quot;router-state&quot;,&quot;status&quot;:&quot;stable&quot;}}</section><section : id="summary-json">{&quot;total&quot;:18,&quot;selectedCount&quot;:2,&quot;clicks&quot;:2}</section><section :="q1_0" id="resource-json">{&quot;headline&quot;:&quot;router-state:stable&quot;,&quot;selected&quot;:[&quot;alpha&quot;,&quot;beta&quot;],&quot;weighted&quot;:[2,6,15,32],&quot;summary&quot;:{&quot;total&quot;:18,&quot;selectedCount&quot;:2,&quot;clicks&quot;:2}}</section></main><script q-d:qinit="q-xxxxxxxx.js#_run#1" q-d:qrouterpopstate="q-xxxxxxxx.js#_run#2" q:p="3" :="Fn_1" q-d:qcinit="q-xxxxxxxx.js#_run#4"></script>[state omitted]
22
[vnode map omitted]
33
<script type="module" async="true" q:type="preload" :>window.addEventListener('load',f=>{f=_=>import("/build/q-xxxxxxxx.js").then(({p})=>p(["q-xxxxxxxx.js","q-xxxxxxxx.js","q-xxxxxxxx.js","q-xxxxxxxx.js","q-xxxxxxxx.js","q-xxxxxxxx.js","q-xxxxxxxx.js"]));try{requestIdleCallback(f,{timeout:2000})}catch(e){setTimeout(f,200)}})</script><script q:func="qwik/json" :>document["qFuncs_xxxxxx"]=[()=>{((w,h)=>{if(!w._qcs){w._qcs=!0;const s=h.state?._qRouterScroll;if(s){h.scrollRestoration="manual";w.scrollTo(s.x,s.y);}document.dispatchEvent(new Event("qcinit"));}})(window,history);},(p0)=>p0.url.href,(p0)=>p0.value.heading]</script><script :>(window._qwikEv||(window._qwikEv=[])).push("d:qinit","d:qrouterpopstate","d:qcinit")</script></body></html>

e2e/qwik-e2e/apps/qwikrouter-ssg-snapshot/expected.state.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
{string} "frontmatter"
4141
Object 0
4242
{string} "manifestHash"
43-
{string} "[manifest]"
43+
{string} "MANIFEST_HASH"
4444
]
4545
{number} 1
4646
Map [

e2e/qwik-e2e/tests/qwikrouter/ssg-snapshot.e2e.ts

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,26 @@ test.describe('router ssg snapshot', () => {
2828
const state = extractState(html);
2929
expect(state).not.toBeNull();
3030

31-
const normalizedHtml = normalizeHtml(html);
31+
const manifestHash = extractManifestHash(html);
32+
const normalizedHtml = normalizeHtml(html, manifestHash);
3233
const normalizedState = normalizeStateDump(
33-
_dumpState(JSON.parse(state!) as unknown[], false, '', null)
34+
_dumpState(JSON.parse(state!) as unknown[], false, '', null),
35+
manifestHash
3436
);
3537

3638
if (process.env.UPDATE_SSG_SNAPSHOT === '1') {
3739
await writeFile(expectedHtmlPath, normalizedHtml, 'utf-8');
3840
await writeFile(expectedStatePath, normalizedState, 'utf-8');
3941
}
4042

41-
expect(normalizedHtml).toEqual(
42-
(await readFile(expectedHtmlPath, 'utf-8')).replace(/\r\n/g, '\n')
43-
);
44-
expect(normalizedState).toEqual(
45-
(await readFile(expectedStatePath, 'utf-8')).replace(/\r\n/g, '\n')
46-
);
43+
const expectedHtml = (await readFile(expectedHtmlPath, 'utf-8')).replace(/\r\n/g, '\n');
44+
const expectedState = (await readFile(expectedStatePath, 'utf-8')).replace(/\r\n/g, '\n');
45+
46+
warnIfSizeChanged('readable state dump', expectedState, normalizedState);
47+
warnIfSizeChanged('HTML', expectedHtml, normalizedHtml);
48+
49+
expect(normalizedState).toEqual(expectedState);
50+
expect(normalizedHtml).toEqual(expectedHtml);
4751
});
4852
});
4953

@@ -104,31 +108,59 @@ async function buildFixtureApp() {
104108
);
105109
}
106110

107-
function normalizeHtml(html: string) {
108-
return html
111+
function extractManifestHash(html: string): string | null {
112+
const match = html.match(/q:manifest-hash="([^"]*)"/);
113+
return match ? match[1] : null;
114+
}
115+
116+
function normalizeHtml(html: string, manifestHash: string | null) {
117+
let result = html;
118+
if (manifestHash) {
119+
result = result.replaceAll(manifestHash, 'MANIFEST_HASH');
120+
}
121+
result = result
109122
.replace(/\r\n/g, '\n')
110123
.replace(/ q:version="[^"]*"/g, '')
111124
.replace(/ q:instance="[^"]*"/g, ' q:instance="[instance]"')
112-
.replace(/ q:manifest-hash="[^"]*"/g, ' q:manifest-hash="[manifest]"')
113125
.replace(/\/assets\/[A-Za-z0-9_-]+-bundle-graph\.json/g, '/assets/xxxxxxxx-bundle-graph.json')
114126
.replace(/q-[A-Za-z0-9_-]+\.(js|css)/g, 'q-xxxxxxxx.$1')
115127
.replace(/qFuncs_[A-Za-z0-9_-]+/g, 'qFuncs_xxxxxx')
116128
.replace(/<script type="qwik\/state"[^>]*>[\s\S]*?<\/script>/, '[state omitted]\n')
117129
.replace(/<script type="qwik\/vnode"[^>]*>[\s\S]*?<\/script>/, '[vnode map omitted]\n');
130+
return result;
118131
}
119132

120133
function extractState(html: string) {
121134
const match = html.match(/<script type="qwik\/state"[^>]*>([\s\S]*?)<\/script>/);
122135
return match ? match[1] : null;
123136
}
124137

125-
function normalizeStateDump(stateDump: string) {
126-
return stateDump
138+
function normalizeStateDump(stateDump: string, manifestHash: string | null) {
139+
let result = stateDump
127140
.replace(/\r\n/g, '\n')
128-
.replace(/manifestHash"\n\s+\{string\} "[^"]+"/g, 'manifestHash"\n {string} "[manifest]"')
141+
.replace(/manifestHash"\n\s+\{string\} "[^"]+"/g, 'manifestHash"\n {string} "MANIFEST_HASH"')
129142
.replace(/qFuncs_[A-Za-z0-9_-]+/g, 'qFuncs_xxxxxx')
130143
.replace(/q-[A-Za-z0-9_-]+\.(js|css)/g, 'q-xxxxxxxx.$1')
131144
.replaceAll(/RootRef .*/g, 'RootRef [omitted]')
132145
.replaceAll(/QRL ".*"/g, 'QRL "[omitted]"')
133146
.replace(/^\(\d+ chars\)$/m, '');
147+
if (manifestHash) {
148+
result = result.replaceAll(manifestHash, 'MANIFEST_HASH');
149+
}
150+
return result;
151+
}
152+
153+
function warnIfSizeChanged(label: string, expected: string, actual: string) {
154+
const expectedLen = expected.length;
155+
const actualLen = actual.length;
156+
if (expectedLen === 0) {
157+
return;
158+
}
159+
const pct = Math.abs(actualLen - expectedLen) / expectedLen;
160+
if (pct > 0.01) {
161+
console.error(
162+
`\n\n[ssg-snapshot] ${label} size changed by ${(pct * 100).toFixed(1)}%: ` +
163+
`${expectedLen}${actualLen} chars`
164+
);
165+
}
134166
}

0 commit comments

Comments
 (0)