diff --git a/test/hydration/index.ts b/test/hydration/index.ts index f3e2c9ea0a..6071f25434 100644 --- a/test/hydration/index.ts +++ b/test/hydration/index.ts @@ -106,6 +106,13 @@ describe('hydration', () => { } } + if (config.snapshot) { + const snapshot_after = config.snapshot(target); + for (const s in snapshot_after) { + assert.equal(snapshot_after[s], snapshot[s], `Expected snapshot key "${s}" to have same value/reference`); + } + } + if (config.test) { config.test(assert, target, snapshot, component, window); } else { diff --git a/test/hydration/samples/basic/_config.js b/test/hydration/samples/basic/_config.js index 81d01322e4..2eda07648c 100644 --- a/test/hydration/samples/basic/_config.js +++ b/test/hydration/samples/basic/_config.js @@ -6,12 +6,5 @@ export default { h1, text: h1.childNodes[0] }; - }, - - test(assert, target, snapshot) { - const h1 = target.querySelector('h1'); - - assert.equal(h1, snapshot.h1); - assert.equal(h1.childNodes[0], snapshot.text); } }; diff --git a/test/hydration/samples/binding-input/_config.js b/test/hydration/samples/binding-input/_config.js index ac3a6be43a..7656417cf0 100644 --- a/test/hydration/samples/binding-input/_config.js +++ b/test/hydration/samples/binding-input/_config.js @@ -10,13 +10,8 @@ export default { }; }, - async test(assert, target, snapshot, component, window) { + async test(assert, target, _, component, window) { const input = target.querySelector('input'); - const p = target.querySelector('p'); - - assert.equal(input, snapshot.input); - assert.equal(p, snapshot.p); - input.value = 'everybody'; await input.dispatchEvent(new window.Event('input')); diff --git a/test/hydration/samples/claim-comment/_after.html b/test/hydration/samples/claim-comment/_after.html index 3029a9dd64..246decf236 100644 --- a/test/hydration/samples/claim-comment/_after.html +++ b/test/hydration/samples/claim-comment/_after.html @@ -1 +1,3 @@
+p + diff --git a/test/hydration/samples/claim-comment/_before.html b/test/hydration/samples/claim-comment/_before.html index 736fb4602d..729e1409b7 100644 --- a/test/hydration/samples/claim-comment/_before.html +++ b/test/hydration/samples/claim-comment/_before.html @@ -1 +1,3 @@ +p + diff --git a/test/hydration/samples/claim-comment/_config.js b/test/hydration/samples/claim-comment/_config.js index bef333510f..305fac9bd9 100644 --- a/test/hydration/samples/claim-comment/_config.js +++ b/test/hydration/samples/claim-comment/_config.js @@ -1,5 +1,10 @@ export default { compileOptions: { preserveComments:true + }, + snapshot(target) { + return { + div: target.querySelectorAll('div')[1] + } } }; diff --git a/test/hydration/samples/claim-comment/main.svelte b/test/hydration/samples/claim-comment/main.svelte index 3029a9dd64..773ad0d1f1 100644 --- a/test/hydration/samples/claim-comment/main.svelte +++ b/test/hydration/samples/claim-comment/main.svelte @@ -1 +1,3 @@ +{"p"} + diff --git a/test/hydration/samples/claim-text/_config.js b/test/hydration/samples/claim-text/_config.js new file mode 100644 index 0000000000..d15bd2bda7 --- /dev/null +++ b/test/hydration/samples/claim-text/_config.js @@ -0,0 +1,8 @@ +export default { + snapshot(target) { + return { + main: target.querySelector('main'), + p: target.querySelector('p') + }; + } +}; diff --git a/test/hydration/samples/component-in-element/_config.js b/test/hydration/samples/component-in-element/_config.js index 557fe068c4..ea0321a15d 100644 --- a/test/hydration/samples/component-in-element/_config.js +++ b/test/hydration/samples/component-in-element/_config.js @@ -8,14 +8,5 @@ export default { p, text: p.childNodes[0] }; - }, - - test(assert, target, snapshot) { - const div = target.querySelector('div'); - const p = target.querySelector('p'); - - assert.equal(div, snapshot.div); - assert.equal(p, snapshot.p); - assert.equal(p.childNodes[0], snapshot.text); } }; diff --git a/test/hydration/samples/component/_config.js b/test/hydration/samples/component/_config.js index 4435b2f86e..50b7651d22 100644 --- a/test/hydration/samples/component/_config.js +++ b/test/hydration/samples/component/_config.js @@ -6,12 +6,5 @@ export default { p, text: p.childNodes[0] }; - }, - - test(assert, target, snapshot) { - const p = target.querySelector('p'); - - assert.equal(p, snapshot.p); - assert.equal(p.childNodes[0], snapshot.text); } }; diff --git a/test/hydration/samples/dynamic-text-changed/_config.js b/test/hydration/samples/dynamic-text-changed/_config.js index c42e251464..b5bac12a65 100644 --- a/test/hydration/samples/dynamic-text-changed/_config.js +++ b/test/hydration/samples/dynamic-text-changed/_config.js @@ -10,12 +10,5 @@ export default { h1, text: h1.childNodes[0] }; - }, - - test(assert, target, snapshot) { - const h1 = target.querySelector('h1'); - - assert.equal(h1, snapshot.h1); - assert.equal(h1.childNodes[0], snapshot.text); } }; diff --git a/test/hydration/samples/dynamic-text-nil/_config.js b/test/hydration/samples/dynamic-text-nil/_config.js index b4d013b777..35583f7fca 100644 --- a/test/hydration/samples/dynamic-text-nil/_config.js +++ b/test/hydration/samples/dynamic-text-nil/_config.js @@ -9,13 +9,5 @@ export default { nullText, undefinedText }; - }, - - test(assert, target, snapshot) { - const nullText = target.querySelectorAll('p')[0].textContent; - const undefinedText = target.querySelectorAll('p')[1].textContent; - - assert.equal(nullText, snapshot.nullText); - assert.equal(undefinedText, snapshot.undefinedText); } }; diff --git a/test/hydration/samples/dynamic-text/_config.js b/test/hydration/samples/dynamic-text/_config.js index 47e095d4ca..58dcbaeefc 100644 --- a/test/hydration/samples/dynamic-text/_config.js +++ b/test/hydration/samples/dynamic-text/_config.js @@ -10,12 +10,5 @@ export default { h1, text: h1.childNodes[0] }; - }, - - test(assert, target, snapshot) { - const h1 = target.querySelector('h1'); - - assert.equal(h1, snapshot.h1); - assert.equal(h1.childNodes[0], snapshot.text); } }; diff --git a/test/hydration/samples/each-block-arg-clash/_config.js b/test/hydration/samples/each-block-arg-clash/_config.js index 1b04393629..5723b452e8 100644 --- a/test/hydration/samples/each-block-arg-clash/_config.js +++ b/test/hydration/samples/each-block-arg-clash/_config.js @@ -15,17 +15,9 @@ export default { return { ul, - lis + lis0: lis[0], + lis1: lis[1], + lis2: lis[2] }; - }, - - test(assert, target, snapshot) { - const ul = target.querySelector('ul'); - const lis = ul.querySelectorAll('li'); - - assert.equal(ul, snapshot.ul); - assert.equal(lis[0], snapshot.lis[0]); - assert.equal(lis[1], snapshot.lis[1]); - assert.equal(lis[2], snapshot.lis[2]); } }; diff --git a/test/hydration/samples/each-block/_config.js b/test/hydration/samples/each-block/_config.js index 81f0a75831..2352cd8ace 100644 --- a/test/hydration/samples/each-block/_config.js +++ b/test/hydration/samples/each-block/_config.js @@ -13,17 +13,9 @@ export default { return { ul, - lis + lis0: lis[0], + lis1: lis[1], + lis2: lis[2] }; - }, - - test(assert, target, snapshot) { - const ul = target.querySelector('ul'); - const lis = ul.querySelectorAll('li'); - - assert.equal(ul, snapshot.ul); - assert.equal(lis[0], snapshot.lis[0]); - assert.equal(lis[1], snapshot.lis[1]); - assert.equal(lis[2], snapshot.lis[2]); } }; diff --git a/test/hydration/samples/element-attribute-added/_config.js b/test/hydration/samples/element-attribute-added/_config.js index a662743c2c..ab0dd986b9 100644 --- a/test/hydration/samples/element-attribute-added/_config.js +++ b/test/hydration/samples/element-attribute-added/_config.js @@ -9,11 +9,5 @@ export default { return { div }; - }, - - test(assert, target, snapshot) { - const div = target.querySelector('div'); - - assert.equal(div, snapshot.div); } }; diff --git a/test/hydration/samples/element-attribute-changed/_config.js b/test/hydration/samples/element-attribute-changed/_config.js index d402e35d7b..561343e19c 100644 --- a/test/hydration/samples/element-attribute-changed/_config.js +++ b/test/hydration/samples/element-attribute-changed/_config.js @@ -9,11 +9,5 @@ export default { return { div }; - }, - - test(assert, target, snapshot) { - const div = target.querySelector('div'); - - assert.equal(div, snapshot.div); } }; diff --git a/test/hydration/samples/element-attribute-removed/_config.js b/test/hydration/samples/element-attribute-removed/_config.js index d402e35d7b..561343e19c 100644 --- a/test/hydration/samples/element-attribute-removed/_config.js +++ b/test/hydration/samples/element-attribute-removed/_config.js @@ -9,11 +9,5 @@ export default { return { div }; - }, - - test(assert, target, snapshot) { - const div = target.querySelector('div'); - - assert.equal(div, snapshot.div); } }; diff --git a/test/hydration/samples/element-attribute-unchanged/_config.js b/test/hydration/samples/element-attribute-unchanged/_config.js index d9d220b6e5..e9ec881acb 100644 --- a/test/hydration/samples/element-attribute-unchanged/_config.js +++ b/test/hydration/samples/element-attribute-unchanged/_config.js @@ -5,11 +5,5 @@ export default { return { div }; - }, - - test(assert, target, snapshot) { - const div = target.querySelector('div'); - - assert.equal(div, snapshot.div); } }; diff --git a/test/hydration/samples/element-nested-sibling/_config.js b/test/hydration/samples/element-nested-sibling/_config.js index 8410fc189d..d62e04a4fb 100644 --- a/test/hydration/samples/element-nested-sibling/_config.js +++ b/test/hydration/samples/element-nested-sibling/_config.js @@ -7,13 +7,5 @@ export default { span: p.querySelector('span'), code: p.querySelector('code') }; - }, - - test(assert, target, snapshot) { - const p = target.querySelector('p'); - - assert.equal(p, snapshot.p); - assert.equal(p.querySelector('span'), snapshot.span); - assert.equal(p.querySelector('code'), snapshot.code); } }; diff --git a/test/hydration/samples/element-nested/_config.js b/test/hydration/samples/element-nested/_config.js index cd34008c04..d9f1077796 100644 --- a/test/hydration/samples/element-nested/_config.js +++ b/test/hydration/samples/element-nested/_config.js @@ -6,12 +6,5 @@ export default { div, p: div.querySelector('p') }; - }, - - test(assert, target, snapshot) { - const div = target.querySelector('div'); - - assert.equal(div, snapshot.div); - assert.equal(div.querySelector('p'), snapshot.p); } }; diff --git a/test/hydration/samples/element-ref/_config.js b/test/hydration/samples/element-ref/_config.js index 80d681f7c5..7e5e736300 100644 --- a/test/hydration/samples/element-ref/_config.js +++ b/test/hydration/samples/element-ref/_config.js @@ -7,10 +7,8 @@ export default { }; }, - test(assert, target, snapshot, component) { + test(assert, target, _, component) { const h1 = target.querySelector('h1'); - - assert.equal(h1, snapshot.h1); assert.equal(component.h1, h1); } }; diff --git a/test/hydration/samples/event-handler/_config.js b/test/hydration/samples/event-handler/_config.js index 027b2bd15b..6338e54aee 100644 --- a/test/hydration/samples/event-handler/_config.js +++ b/test/hydration/samples/event-handler/_config.js @@ -11,10 +11,8 @@ export default { }; }, - async test(assert, target, snapshot, component, window) { + async test(assert, target, _, component, window) { const button = target.querySelector('button'); - assert.equal(button, snapshot.button); - await button.dispatchEvent(new window.MouseEvent('click')); assert.ok(component.clicked); diff --git a/test/hydration/samples/expression-sibling/_config.js b/test/hydration/samples/expression-sibling/_config.js index c6d3ef3f2f..a46d49e0d2 100644 --- a/test/hydration/samples/expression-sibling/_config.js +++ b/test/hydration/samples/expression-sibling/_config.js @@ -7,13 +7,5 @@ export default { text: p.childNodes[0], span: p.querySelector('span') }; - }, - - test(assert, target, snapshot) { - const p = target.querySelector('p'); - - assert.equal(p, snapshot.p); - assert.equal(p.childNodes[0], snapshot.text); - assert.equal(p.querySelector('span'), snapshot.span); } }; diff --git a/test/hydration/samples/if-block-anchor/_config.js b/test/hydration/samples/if-block-anchor/_config.js index ab519c913b..68bf6ac431 100644 --- a/test/hydration/samples/if-block-anchor/_config.js +++ b/test/hydration/samples/if-block-anchor/_config.js @@ -13,14 +13,5 @@ export default { p0: ps[0], p1: ps[1] }; - }, - - test(assert, target, snapshot) { - const div = target.querySelector('div'); - const ps = target.querySelectorAll('p'); - - assert.equal(div, snapshot.div); - assert.equal(ps[0], snapshot.p0); - assert.equal(ps[1], snapshot.p1); } }; diff --git a/test/hydration/samples/if-block-false/_config.js b/test/hydration/samples/if-block-false/_config.js index a11d800e45..1559837feb 100644 --- a/test/hydration/samples/if-block-false/_config.js +++ b/test/hydration/samples/if-block-false/_config.js @@ -9,11 +9,5 @@ export default { return { p }; - }, - - test(assert, target, snapshot) { - const p = target.querySelector('p'); - - assert.equal(p, snapshot.p); } }; diff --git a/test/hydration/samples/if-block-update/_config.js b/test/hydration/samples/if-block-update/_config.js index fb4a723145..0f8ed286bb 100644 --- a/test/hydration/samples/if-block-update/_config.js +++ b/test/hydration/samples/if-block-update/_config.js @@ -12,11 +12,9 @@ export default { }; }, - test(assert, target, snapshot, component) { + test(assert, target, _, component) { const p = target.querySelector('p'); - assert.equal(p, snapshot.p); - component.foo = false; component.bar = true; assert.htmlEqual(target.innerHTML, 'bar!
'); diff --git a/test/hydration/samples/if-block/_config.js b/test/hydration/samples/if-block/_config.js index bd89748dc0..11f705e7a9 100644 --- a/test/hydration/samples/if-block/_config.js +++ b/test/hydration/samples/if-block/_config.js @@ -9,11 +9,5 @@ export default { return { p }; - }, - - test(assert, target, snapshot) { - const p = target.querySelector('p'); - - assert.equal(p, snapshot.p); } }; diff --git a/test/hydration/samples/raw/_config.js b/test/hydration/samples/raw/_config.js index f4fb2889cd..14ba7b12c1 100644 --- a/test/hydration/samples/raw/_config.js +++ b/test/hydration/samples/raw/_config.js @@ -14,14 +14,5 @@ export default { p1: ps[1], text1: ps[1].firstChild }; - }, - - test(assert, target, snapshot) { - const ps = target.querySelectorAll('p'); - - assert.equal(ps[0], snapshot.p0); - assert.equal(ps[0].firstChild, snapshot.text0); - assert.equal(ps[1], snapshot.p1); - assert.equal(ps[1].firstChild, snapshot.text1); } };