feat add hydrating header meta testing

pull/4082/head
Tan Li Hau 6 years ago
parent 3d9655a2a1
commit e3e8dd3262

@ -67,8 +67,16 @@ describe('hydration', () => {
}
const target = window.document.body;
const head = window.document.head;
target.innerHTML = fs.readFileSync(`${cwd}/_before.html`, 'utf-8');
let before_head;
try {
before_head = fs.readFileSync(`${cwd}/_before_head.html`, 'utf-8');
head.innerHTML = before_head;
} catch (err) {}
const snapshot = config.snapshot ? config.snapshot(target) : {};
const component = new SvelteComponent({
@ -88,6 +96,19 @@ describe('hydration', () => {
}
}
if (before_head) {
try {
assert.htmlEqual(head.innerHTML, fs.readFileSync(`${cwd}/_after_head.html`, 'utf-8'));
} catch (error) {
if (shouldUpdateExpected()) {
fs.writeFileSync(`${cwd}/_after_head.html`, head.innerHTML);
console.log(`Updated ${cwd}/_after_head.html.`);
} else {
throw error;
}
}
}
if (config.test) {
config.test(assert, target, snapshot, component, window);
} else {

@ -0,0 +1,4 @@
<title>Some Title</title>
<link rel="canonical" href="/">
<meta name="description" content="some description">
<meta name="keywords" content="some keywords">

@ -0,0 +1,4 @@
<title>Some Title</title>
<link rel="canonical" href="/">
<meta name="description" content="some description">
<meta name="keywords" content="some keywords">

@ -0,0 +1,6 @@
export default {
test({ assert, component, target, window }) {
console.log(window.document.querySelectorAll('meta'));
assert.equal(window.document.querySelectorAll('meta').length, 2);
}
};

@ -0,0 +1,8 @@
<svelte:head>
<title>Some Title</title>
<link rel="canonical" href="/">
<meta name="description" content="some description">
<meta name="keywords" content="some keywords">
</svelte:head>
<div>Just a dummy page.</div>
Loading…
Cancel
Save