diff --git a/test/ssr/attribute-boolean/_actual.html b/test/ssr/attribute-boolean/_actual.html new file mode 100644 index 0000000000..c45ee39b0f --- /dev/null +++ b/test/ssr/attribute-boolean/_actual.html @@ -0,0 +1 @@ +<textarea readonly/> \ No newline at end of file diff --git a/test/ssr/attribute-boolean/_expected.html b/test/ssr/attribute-boolean/_expected.html new file mode 100644 index 0000000000..3ca3bfd9a8 --- /dev/null +++ b/test/ssr/attribute-boolean/_expected.html @@ -0,0 +1 @@ +<textarea readonly></textarea> diff --git a/test/ssr/attribute-boolean/main.html b/test/ssr/attribute-boolean/main.html new file mode 100644 index 0000000000..3ca3bfd9a8 --- /dev/null +++ b/test/ssr/attribute-boolean/main.html @@ -0,0 +1 @@ +<textarea readonly></textarea> diff --git a/test/ssr/attribute-dynamic/_actual.html b/test/ssr/attribute-dynamic/_actual.html new file mode 100644 index 0000000000..8960382913 --- /dev/null +++ b/test/ssr/attribute-dynamic/_actual.html @@ -0,0 +1 @@ +<div style="font-family: sans-serif; color: aquamarine;">aquamarine sans-serif</div> \ No newline at end of file diff --git a/test/ssr/attribute-dynamic/_expected.html b/test/ssr/attribute-dynamic/_expected.html new file mode 100644 index 0000000000..5d9e40d299 --- /dev/null +++ b/test/ssr/attribute-dynamic/_expected.html @@ -0,0 +1 @@ +<div style='font-family: sans-serif; color: aquamarine;'>aquamarine sans-serif</div> diff --git a/test/ssr/attribute-dynamic/data.json b/test/ssr/attribute-dynamic/data.json new file mode 100644 index 0000000000..774a6ed7b1 --- /dev/null +++ b/test/ssr/attribute-dynamic/data.json @@ -0,0 +1,4 @@ +{ + "font": "sans-serif", + "color": "aquamarine" +} diff --git a/test/ssr/attribute-dynamic/main.html b/test/ssr/attribute-dynamic/main.html new file mode 100644 index 0000000000..18732ab91a --- /dev/null +++ b/test/ssr/attribute-dynamic/main.html @@ -0,0 +1 @@ +<div style='font-family: {{font}}; color: {{color}};'>{{color}} {{font}}</div> diff --git a/test/ssr/attribute-static/_actual.html b/test/ssr/attribute-static/_actual.html new file mode 100644 index 0000000000..f82d79e45a --- /dev/null +++ b/test/ssr/attribute-static/_actual.html @@ -0,0 +1 @@ +<div class="foo"/> \ No newline at end of file diff --git a/test/ssr/attribute-static/_expected.html b/test/ssr/attribute-static/_expected.html new file mode 100644 index 0000000000..3cb2e4b233 --- /dev/null +++ b/test/ssr/attribute-static/_expected.html @@ -0,0 +1 @@ +<div class='foo'></div> diff --git a/test/ssr/attribute-static/main.html b/test/ssr/attribute-static/main.html new file mode 100644 index 0000000000..3cb2e4b233 --- /dev/null +++ b/test/ssr/attribute-static/main.html @@ -0,0 +1 @@ +<div class='foo'></div> diff --git a/test/ssr/component-data-dynamic/Widget.html b/test/ssr/component-data-dynamic/Widget.html new file mode 100644 index 0000000000..43184b9ad8 --- /dev/null +++ b/test/ssr/component-data-dynamic/Widget.html @@ -0,0 +1,4 @@ +<p>foo: {{foo}}</p> +<p>baz: {{baz}} ({{typeof baz}})</p> +<p>qux: {{qux}}</p> +<p>quux: {{quux}}</p> diff --git a/test/ssr/component-data-dynamic/_actual.html b/test/ssr/component-data-dynamic/_actual.html new file mode 100644 index 0000000000..97800c17aa --- /dev/null +++ b/test/ssr/component-data-dynamic/_actual.html @@ -0,0 +1,4 @@ +<div><p>foo: lol</p> + <p>baz: 42 (number)</p> + <p>qux: this is a piece of string</p> + <p>quux: core</p></div> \ No newline at end of file diff --git a/test/ssr/component-data-dynamic/_expected.html b/test/ssr/component-data-dynamic/_expected.html new file mode 100644 index 0000000000..432cfba85a --- /dev/null +++ b/test/ssr/component-data-dynamic/_expected.html @@ -0,0 +1,4 @@ +<div><p>foo: lol</p> +<p>baz: 42 (number)</p> +<p>qux: this is a piece of string</p> +<p>quux: core</p></div> diff --git a/test/ssr/component-data-dynamic/data.json b/test/ssr/component-data-dynamic/data.json new file mode 100644 index 0000000000..89604b3e8b --- /dev/null +++ b/test/ssr/component-data-dynamic/data.json @@ -0,0 +1,6 @@ +{ + "bar": "lol", + "x": 2, + "compound": "piece of", + "go": { "deeper": "core" } +} diff --git a/test/ssr/component-data-dynamic/main.html b/test/ssr/component-data-dynamic/main.html new file mode 100644 index 0000000000..12d5f3208b --- /dev/null +++ b/test/ssr/component-data-dynamic/main.html @@ -0,0 +1,11 @@ +<div> + <Widget foo='{{bar}}' baz='{{40 + x}}' qux='this is a {{compound}} string' quux='{{go.deeper}}'/> +</div> + +<script> + import Widget from './Widget.html'; + + export default { + components: { Widget } + }; +</script> diff --git a/test/ssr/component-data-empty/Widget.html b/test/ssr/component-data-empty/Widget.html new file mode 100644 index 0000000000..89d0010a35 --- /dev/null +++ b/test/ssr/component-data-empty/Widget.html @@ -0,0 +1 @@ +<p>foo: '{{foo}}'</p> diff --git a/test/ssr/component-data-empty/_actual.html b/test/ssr/component-data-empty/_actual.html new file mode 100644 index 0000000000..dab5ab5387 --- /dev/null +++ b/test/ssr/component-data-empty/_actual.html @@ -0,0 +1 @@ +<div><p>foo: ''</p></div> \ No newline at end of file diff --git a/test/ssr/component-data-empty/_expected.html b/test/ssr/component-data-empty/_expected.html new file mode 100644 index 0000000000..ecaf8e5897 --- /dev/null +++ b/test/ssr/component-data-empty/_expected.html @@ -0,0 +1 @@ +<div><p>foo: ''</p></div> diff --git a/test/ssr/component-data-empty/main.html b/test/ssr/component-data-empty/main.html new file mode 100644 index 0000000000..8b797c8a60 --- /dev/null +++ b/test/ssr/component-data-empty/main.html @@ -0,0 +1,11 @@ +<div> + <Widget foo=''/> +</div> + +<script> + import Widget from './Widget.html'; + + export default { + components: { Widget } + }; +</script> diff --git a/test/ssr/component-data-static/Widget.html b/test/ssr/component-data-static/Widget.html new file mode 100644 index 0000000000..573b6ffcc3 --- /dev/null +++ b/test/ssr/component-data-static/Widget.html @@ -0,0 +1,2 @@ +<p>foo: {{foo}}</p> +<p>baz: {{baz}} ({{typeof baz}})</p> diff --git a/test/ssr/component-data-static/_actual.html b/test/ssr/component-data-static/_actual.html new file mode 100644 index 0000000000..9502567ec5 --- /dev/null +++ b/test/ssr/component-data-static/_actual.html @@ -0,0 +1,2 @@ +<div><p>foo: bar</p> + <p>baz: 42 (number)</p></div> \ No newline at end of file diff --git a/test/ssr/component-data-static/_expected.html b/test/ssr/component-data-static/_expected.html new file mode 100644 index 0000000000..7e3d0496bd --- /dev/null +++ b/test/ssr/component-data-static/_expected.html @@ -0,0 +1,2 @@ +<div><p>foo: bar</p> +<p>baz: 42 (number)</p></div> diff --git a/test/ssr/component-data-static/main.html b/test/ssr/component-data-static/main.html new file mode 100644 index 0000000000..0df72c1465 --- /dev/null +++ b/test/ssr/component-data-static/main.html @@ -0,0 +1,11 @@ +<div> + <Widget foo='bar' baz='42'/> +</div> + +<script> + import Widget from './Widget.html'; + + export default { + components: { Widget } + }; +</script> diff --git a/test/ssr/component-yield/Widget.html b/test/ssr/component-yield/Widget.html new file mode 100644 index 0000000000..c1ffda500d --- /dev/null +++ b/test/ssr/component-yield/Widget.html @@ -0,0 +1,11 @@ +<p>{{yield}}</p> + +<script> + export default { + data () { + return { + data: 'this should not appear' + }; + } + }; +</script> diff --git a/test/ssr/component-yield/_actual.html b/test/ssr/component-yield/_actual.html new file mode 100644 index 0000000000..3c0acf1a81 --- /dev/null +++ b/test/ssr/component-yield/_actual.html @@ -0,0 +1 @@ +<div><p>Hello</p></div> \ No newline at end of file diff --git a/test/ssr/component-yield/_expected.html b/test/ssr/component-yield/_expected.html new file mode 100644 index 0000000000..fb13e0ab30 --- /dev/null +++ b/test/ssr/component-yield/_expected.html @@ -0,0 +1 @@ +<div><p>Hello</p></div> diff --git a/test/ssr/component-yield/main.html b/test/ssr/component-yield/main.html new file mode 100644 index 0000000000..cb1d683e78 --- /dev/null +++ b/test/ssr/component-yield/main.html @@ -0,0 +1,17 @@ +<div> + <Widget>{{data}}</Widget> +</div> + +<script> + import Widget from './Widget.html'; + + export default { + components: { Widget }, + + data () { + return { + data: 'Hello' + }; + } + }; +</script> diff --git a/test/ssr/component/Widget.html b/test/ssr/component/Widget.html new file mode 100644 index 0000000000..460a2a1c01 --- /dev/null +++ b/test/ssr/component/Widget.html @@ -0,0 +1 @@ +<p>i am a widget</p> diff --git a/test/ssr/component/_actual.html b/test/ssr/component/_actual.html new file mode 100644 index 0000000000..715d1a85c3 --- /dev/null +++ b/test/ssr/component/_actual.html @@ -0,0 +1 @@ +<div><p>i am a widget</p></div> \ No newline at end of file diff --git a/test/ssr/component/_expected.html b/test/ssr/component/_expected.html new file mode 100644 index 0000000000..3551c5971e --- /dev/null +++ b/test/ssr/component/_expected.html @@ -0,0 +1 @@ +<div><p>i am a widget</p></div> diff --git a/test/ssr/component/main.html b/test/ssr/component/main.html new file mode 100644 index 0000000000..5b119b5527 --- /dev/null +++ b/test/ssr/component/main.html @@ -0,0 +1,11 @@ +<div> + <Widget/> +</div> + +<script> + import Widget from './Widget.html'; + + export default { + components: { Widget } + }; +</script> diff --git a/test/ssr/computed/_actual.html b/test/ssr/computed/_actual.html new file mode 100644 index 0000000000..f5a05c2882 --- /dev/null +++ b/test/ssr/computed/_actual.html @@ -0,0 +1,2 @@ +<p>1 + 2 = 3</p> + <p>3 * 3 = 9</p> \ No newline at end of file diff --git a/test/ssr/computed/_expected.html b/test/ssr/computed/_expected.html new file mode 100644 index 0000000000..0219d548a6 --- /dev/null +++ b/test/ssr/computed/_expected.html @@ -0,0 +1,2 @@ +<p>1 + 2 = 3</p> +<p>3 * 3 = 9</p> diff --git a/test/ssr/computed/data.json b/test/ssr/computed/data.json new file mode 100644 index 0000000000..27d5db50b5 --- /dev/null +++ b/test/ssr/computed/data.json @@ -0,0 +1,4 @@ +{ + "a": 1, + "b": 2 +} diff --git a/test/ssr/computed/main.html b/test/ssr/computed/main.html new file mode 100644 index 0000000000..6f92236436 --- /dev/null +++ b/test/ssr/computed/main.html @@ -0,0 +1,11 @@ +<p>{{a}} + {{b}} = {{c}}</p> +<p>{{c}} * {{c}} = {{cSquared}}</p> + +<script> + export default { + computed: { + c: ( a, b ) => a + b, + cSquared: c => c * c + } + }; +</script> diff --git a/test/ssr/default-data-override/_actual.html b/test/ssr/default-data-override/_actual.html new file mode 100644 index 0000000000..cfe6edcec5 --- /dev/null +++ b/test/ssr/default-data-override/_actual.html @@ -0,0 +1 @@ +<p>2</p> \ No newline at end of file diff --git a/test/ssr/default-data-override/_expected.html b/test/ssr/default-data-override/_expected.html new file mode 100644 index 0000000000..d1b089dc53 --- /dev/null +++ b/test/ssr/default-data-override/_expected.html @@ -0,0 +1 @@ +<p>2</p> diff --git a/test/ssr/default-data-override/data.json b/test/ssr/default-data-override/data.json new file mode 100644 index 0000000000..7625ba3b3c --- /dev/null +++ b/test/ssr/default-data-override/data.json @@ -0,0 +1,3 @@ +{ + "foo": 2 +} diff --git a/test/ssr/default-data-override/main.html b/test/ssr/default-data-override/main.html new file mode 100644 index 0000000000..3605487855 --- /dev/null +++ b/test/ssr/default-data-override/main.html @@ -0,0 +1,11 @@ +<p>{{foo}}</p> + +<script> + export default { + data () { + return { + foo: 1 + } + } + }; +</script> diff --git a/test/ssr/default-data/_actual.html b/test/ssr/default-data/_actual.html new file mode 100644 index 0000000000..40001b6811 --- /dev/null +++ b/test/ssr/default-data/_actual.html @@ -0,0 +1 @@ +<p>1</p> \ No newline at end of file diff --git a/test/ssr/default-data/_expected.html b/test/ssr/default-data/_expected.html new file mode 100644 index 0000000000..c460ecf3a5 --- /dev/null +++ b/test/ssr/default-data/_expected.html @@ -0,0 +1 @@ +<p>1</p> diff --git a/test/ssr/default-data/main.html b/test/ssr/default-data/main.html new file mode 100644 index 0000000000..3605487855 --- /dev/null +++ b/test/ssr/default-data/main.html @@ -0,0 +1,11 @@ +<p>{{foo}}</p> + +<script> + export default { + data () { + return { + foo: 1 + } + } + }; +</script> diff --git a/test/ssr/dynamic-text/_actual.html b/test/ssr/dynamic-text/_actual.html new file mode 100644 index 0000000000..85c8829392 --- /dev/null +++ b/test/ssr/dynamic-text/_actual.html @@ -0,0 +1 @@ +it works \ No newline at end of file diff --git a/test/ssr/dynamic-text/_expected.html b/test/ssr/dynamic-text/_expected.html new file mode 100644 index 0000000000..7658ad2c24 --- /dev/null +++ b/test/ssr/dynamic-text/_expected.html @@ -0,0 +1 @@ +it works diff --git a/test/ssr/dynamic-text/data.json b/test/ssr/dynamic-text/data.json new file mode 100644 index 0000000000..0f008a185b --- /dev/null +++ b/test/ssr/dynamic-text/data.json @@ -0,0 +1,3 @@ +{ + "foo": "it works" +} diff --git a/test/ssr/dynamic-text/main.html b/test/ssr/dynamic-text/main.html new file mode 100644 index 0000000000..054e96cb81 --- /dev/null +++ b/test/ssr/dynamic-text/main.html @@ -0,0 +1 @@ +{{foo}} diff --git a/test/ssr/each-block/_actual.html b/test/ssr/each-block/_actual.html new file mode 100644 index 0000000000..9f0c3c2b55 --- /dev/null +++ b/test/ssr/each-block/_actual.html @@ -0,0 +1 @@ +<p>1: alligator</p><p>2: beetle</p><p>3: cuckoo</p> \ No newline at end of file diff --git a/test/ssr/each-block/_expected.html b/test/ssr/each-block/_expected.html new file mode 100644 index 0000000000..86df2b82da --- /dev/null +++ b/test/ssr/each-block/_expected.html @@ -0,0 +1 @@ +<p>1: alligator</p><p>2: beetle</p><p>3: cuckoo</p> diff --git a/test/ssr/each-block/data.json b/test/ssr/each-block/data.json new file mode 100644 index 0000000000..febcba093c --- /dev/null +++ b/test/ssr/each-block/data.json @@ -0,0 +1,7 @@ +{ + "animals": [ + "alligator", + "beetle", + "cuckoo" + ] +} diff --git a/test/ssr/each-block/main.html b/test/ssr/each-block/main.html new file mode 100644 index 0000000000..dfe0195d2a --- /dev/null +++ b/test/ssr/each-block/main.html @@ -0,0 +1,3 @@ +{{#each animals as animal, i}} + <p>{{i + 1}}: {{animal}}</p> +{{/each}} diff --git a/test/ssr/helpers/_actual.html b/test/ssr/helpers/_actual.html new file mode 100644 index 0000000000..4b5c34ffb9 --- /dev/null +++ b/test/ssr/helpers/_actual.html @@ -0,0 +1 @@ +<p>3</p> \ No newline at end of file diff --git a/test/ssr/helpers/_expected.html b/test/ssr/helpers/_expected.html new file mode 100644 index 0000000000..ca54385e2b --- /dev/null +++ b/test/ssr/helpers/_expected.html @@ -0,0 +1 @@ +<p>3</p> diff --git a/test/ssr/helpers/main.html b/test/ssr/helpers/main.html new file mode 100644 index 0000000000..de61efe8a0 --- /dev/null +++ b/test/ssr/helpers/main.html @@ -0,0 +1,15 @@ +<p>{{thrice(foo)}}</p> + +<script> + export default { + data () { + return { + foo: 1 + } + }, + + helpers: { + thrice: num => 3 * num + } + }; +</script> diff --git a/test/ssr/if-block-false/_actual.html b/test/ssr/if-block-false/_actual.html new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/ssr/if-block-false/_expected.html b/test/ssr/if-block-false/_expected.html new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/ssr/if-block-false/data.json b/test/ssr/if-block-false/data.json new file mode 100644 index 0000000000..5b42b1ce4f --- /dev/null +++ b/test/ssr/if-block-false/data.json @@ -0,0 +1,3 @@ +{ + "foo": false +} diff --git a/test/ssr/if-block-false/main.html b/test/ssr/if-block-false/main.html new file mode 100644 index 0000000000..2824b7e504 --- /dev/null +++ b/test/ssr/if-block-false/main.html @@ -0,0 +1,3 @@ +{{#if foo}} + <p>foo is true</p> +{{/if}} diff --git a/test/ssr/if-block-true/_actual.html b/test/ssr/if-block-true/_actual.html new file mode 100644 index 0000000000..df979b8d53 --- /dev/null +++ b/test/ssr/if-block-true/_actual.html @@ -0,0 +1 @@ +<p>foo is true</p> \ No newline at end of file diff --git a/test/ssr/if-block-true/_expected.html b/test/ssr/if-block-true/_expected.html new file mode 100644 index 0000000000..b6f3d8a330 --- /dev/null +++ b/test/ssr/if-block-true/_expected.html @@ -0,0 +1 @@ +<p>foo is true</p> diff --git a/test/ssr/if-block-true/data.json b/test/ssr/if-block-true/data.json new file mode 100644 index 0000000000..79cc1f44f6 --- /dev/null +++ b/test/ssr/if-block-true/data.json @@ -0,0 +1,3 @@ +{ + "foo": true +} diff --git a/test/ssr/if-block-true/main.html b/test/ssr/if-block-true/main.html new file mode 100644 index 0000000000..2824b7e504 --- /dev/null +++ b/test/ssr/if-block-true/main.html @@ -0,0 +1,3 @@ +{{#if foo}} + <p>foo is true</p> +{{/if}} diff --git a/test/ssr/static-div/_actual.html b/test/ssr/static-div/_actual.html new file mode 100644 index 0000000000..78e7012b82 --- /dev/null +++ b/test/ssr/static-div/_actual.html @@ -0,0 +1 @@ +<div/> \ No newline at end of file diff --git a/test/ssr/static-div/_expected.html b/test/ssr/static-div/_expected.html new file mode 100644 index 0000000000..7c89b545c5 --- /dev/null +++ b/test/ssr/static-div/_expected.html @@ -0,0 +1 @@ +<div></div> diff --git a/test/ssr/static-div/main.html b/test/ssr/static-div/main.html new file mode 100644 index 0000000000..7c89b545c5 --- /dev/null +++ b/test/ssr/static-div/main.html @@ -0,0 +1 @@ +<div></div> diff --git a/test/ssr/static-text/_actual.html b/test/ssr/static-text/_actual.html new file mode 100644 index 0000000000..b649a9bf89 --- /dev/null +++ b/test/ssr/static-text/_actual.html @@ -0,0 +1 @@ +some text \ No newline at end of file diff --git a/test/ssr/static-text/_expected.html b/test/ssr/static-text/_expected.html new file mode 100644 index 0000000000..7b57bd29ea --- /dev/null +++ b/test/ssr/static-text/_expected.html @@ -0,0 +1 @@ +some text diff --git a/test/ssr/static-text/main.html b/test/ssr/static-text/main.html new file mode 100644 index 0000000000..7b57bd29ea --- /dev/null +++ b/test/ssr/static-text/main.html @@ -0,0 +1 @@ +some text diff --git a/test/test.js b/test/test.js index f9d01848d0..0eff94bd02 100644 --- a/test/test.js +++ b/test/test.js @@ -62,6 +62,15 @@ function addLineNumbers ( code ) { }).join( '\n' ); } +function tryToLoadJson ( file ) { + try { + return JSON.parse( fs.readFileSync( file ) ); + } catch ( err ) { + if ( err.code !== 'ENOENT' ) throw err; + return null; + } +} + describe( 'svelte', () => { before( () => { function cleanChildren ( node ) { @@ -154,15 +163,6 @@ describe( 'svelte', () => { }); describe( 'validate', () => { - function tryToLoadJson ( file ) { - try { - return JSON.parse( fs.readFileSync( file ) ); - } catch ( err ) { - if ( err.code !== 'ENOENT' ) throw err; - return null; - } - } - fs.readdirSync( 'test/validator' ).forEach( dir => { if ( dir[0] === '.' ) return; @@ -505,4 +505,29 @@ describe( 'svelte', () => { }); }); }); + + describe( 'ssr', () => { + before( () => { + require( '../ssr/register' ); + }); + + fs.readdirSync( 'test/ssr' ).forEach( dir => { + if ( dir[0] === '.' ) return; + + const solo = exists( `test/ssr/${dir}/solo` ); + + ( solo ? it.only : it )( dir, () => { + const component = require( `./ssr/${dir}/main.html` ); + + const expected = fs.readFileSync( `test/ssr/${dir}/_expected.html`, 'utf-8' ); + + const data = tryToLoadJson( `test/ssr/${dir}/data.json` ); + const actual = component.render( data ); + + fs.writeFileSync( `test/ssr/${dir}/_actual.html`, actual ); + + assert.htmlEqual( actual, expected ); + }); + }); + }); });