From e3e8dd3262fe413387a170e275f2aebf15e34e9d Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Tue, 10 Dec 2019 21:01:28 +0800 Subject: [PATCH] feat add hydrating header meta testing --- test/hydration/index.js | 21 +++++++++++++++++++ .../head-meta-hydrate-duplicate/_after.html | 1 + .../_after_head.html | 4 ++++ .../head-meta-hydrate-duplicate/_before.html | 1 + .../_before_head.html | 4 ++++ .../head-meta-hydrate-duplicate/_config.js | 6 ++++++ .../head-meta-hydrate-duplicate/main.svelte | 8 +++++++ 7 files changed, 45 insertions(+) create mode 100644 test/hydration/samples/head-meta-hydrate-duplicate/_after.html create mode 100644 test/hydration/samples/head-meta-hydrate-duplicate/_after_head.html create mode 100644 test/hydration/samples/head-meta-hydrate-duplicate/_before.html create mode 100644 test/hydration/samples/head-meta-hydrate-duplicate/_before_head.html create mode 100644 test/hydration/samples/head-meta-hydrate-duplicate/_config.js create mode 100644 test/hydration/samples/head-meta-hydrate-duplicate/main.svelte diff --git a/test/hydration/index.js b/test/hydration/index.js index a0bfd6de4b98..f57a0cdc1aca 100644 --- a/test/hydration/index.js +++ b/test/hydration/index.js @@ -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 { diff --git a/test/hydration/samples/head-meta-hydrate-duplicate/_after.html b/test/hydration/samples/head-meta-hydrate-duplicate/_after.html new file mode 100644 index 000000000000..3e5b375f0a59 --- /dev/null +++ b/test/hydration/samples/head-meta-hydrate-duplicate/_after.html @@ -0,0 +1 @@ +
Just a dummy page.
\ No newline at end of file diff --git a/test/hydration/samples/head-meta-hydrate-duplicate/_after_head.html b/test/hydration/samples/head-meta-hydrate-duplicate/_after_head.html new file mode 100644 index 000000000000..bb85df70c2a1 --- /dev/null +++ b/test/hydration/samples/head-meta-hydrate-duplicate/_after_head.html @@ -0,0 +1,4 @@ +Some Title + + + \ No newline at end of file diff --git a/test/hydration/samples/head-meta-hydrate-duplicate/_before.html b/test/hydration/samples/head-meta-hydrate-duplicate/_before.html new file mode 100644 index 000000000000..3e5b375f0a59 --- /dev/null +++ b/test/hydration/samples/head-meta-hydrate-duplicate/_before.html @@ -0,0 +1 @@ +
Just a dummy page.
\ No newline at end of file diff --git a/test/hydration/samples/head-meta-hydrate-duplicate/_before_head.html b/test/hydration/samples/head-meta-hydrate-duplicate/_before_head.html new file mode 100644 index 000000000000..bb85df70c2a1 --- /dev/null +++ b/test/hydration/samples/head-meta-hydrate-duplicate/_before_head.html @@ -0,0 +1,4 @@ +Some Title + + + \ No newline at end of file diff --git a/test/hydration/samples/head-meta-hydrate-duplicate/_config.js b/test/hydration/samples/head-meta-hydrate-duplicate/_config.js new file mode 100644 index 000000000000..4c9a573caa8b --- /dev/null +++ b/test/hydration/samples/head-meta-hydrate-duplicate/_config.js @@ -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); + } +}; diff --git a/test/hydration/samples/head-meta-hydrate-duplicate/main.svelte b/test/hydration/samples/head-meta-hydrate-duplicate/main.svelte new file mode 100644 index 000000000000..1a8b125dd2cf --- /dev/null +++ b/test/hydration/samples/head-meta-hydrate-duplicate/main.svelte @@ -0,0 +1,8 @@ + + Some Title + + + + + +
Just a dummy page.
\ No newline at end of file