Skip to content

Commit

Permalink
feat add hydrating header meta testing
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhauhau committed Jan 10, 2020
1 parent 3d9655a commit e3e8dd3
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/hydration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>Just a dummy page.</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<title>Some Title</title>
<link rel="canonical" href="/">
<meta name="description" content="some description">
<meta name="keywords" content="some keywords">
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>Just a dummy page.</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<title>Some Title</title>
<link rel="canonical" href="/">
<meta name="description" content="some description">
<meta name="keywords" content="some keywords">
6 changes: 6 additions & 0 deletions test/hydration/samples/head-meta-hydrate-duplicate/_config.js
Original file line number Diff line number Diff line change
@@ -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);
}
};
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit e3e8dd3

Please sign in to comment.