From 94aca91d35b9f3f516ed80d8548227ccdc3ef718 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 31 Jan 2017 17:35:03 -0500 Subject: [PATCH] fix/skip various SSR tests --- .../visitors/YieldTag.js | 2 +- test/generator/component-yield/_config.js | 4 ++-- test/generator/component-yield/main.html | 23 ++++++++++--------- test/generator/raw-mustaches/_config.js | 4 ++++ .../_config.js | 0 .../main.html | 0 test/generator/svg-xmlns/_config.js | 2 ++ test/ssr.js | 20 +++++++++++----- 8 files changed, 35 insertions(+), 20 deletions(-) rename test/generator/{text-node-top-level => single-text-node}/_config.js (100%) rename test/generator/{text-node-top-level => single-text-node}/main.html (100%) diff --git a/src/generators/server-side-rendering/visitors/YieldTag.js b/src/generators/server-side-rendering/visitors/YieldTag.js index 732f96301b..a9b35f777e 100644 --- a/src/generators/server-side-rendering/visitors/YieldTag.js +++ b/src/generators/server-side-rendering/visitors/YieldTag.js @@ -1,5 +1,5 @@ export default { enter ( generator ) { - generator.append( `\${options.yield()}` ); + generator.append( `\${options && options.yield ? options.yield() : ''}` ); } }; diff --git a/test/generator/component-yield/_config.js b/test/generator/component-yield/_config.js index fcf00b5072..174d01f1a5 100644 --- a/test/generator/component-yield/_config.js +++ b/test/generator/component-yield/_config.js @@ -1,3 +1,3 @@ export default { - html: '

Hello

' -} + html: '

Hello

' +}; diff --git a/test/generator/component-yield/main.html b/test/generator/component-yield/main.html index 7d5cbf7180..5432dcf8f4 100644 --- a/test/generator/component-yield/main.html +++ b/test/generator/component-yield/main.html @@ -1,15 +1,16 @@

- Hello - {{#if test}} - {{yield}} - {{/if}} + Hello + {{#if test}} + {{yield}} + {{/if}}

+ diff --git a/test/generator/raw-mustaches/_config.js b/test/generator/raw-mustaches/_config.js index 850a169e02..8b7767d6d1 100644 --- a/test/generator/raw-mustaches/_config.js +++ b/test/generator/raw-mustaches/_config.js @@ -1,8 +1,12 @@ const ns = ''; + export default { + 'skip-ssr': true, + data: { raw: 'raw html!!!\\o/' }, + html: `before${ns}raw html!!!\\o/${ns}after`, test ( assert, component, target ) { diff --git a/test/generator/text-node-top-level/_config.js b/test/generator/single-text-node/_config.js similarity index 100% rename from test/generator/text-node-top-level/_config.js rename to test/generator/single-text-node/_config.js diff --git a/test/generator/text-node-top-level/main.html b/test/generator/single-text-node/main.html similarity index 100% rename from test/generator/text-node-top-level/main.html rename to test/generator/single-text-node/main.html diff --git a/test/generator/svg-xmlns/_config.js b/test/generator/svg-xmlns/_config.js index 37d94a1609..0df414232b 100644 --- a/test/generator/svg-xmlns/_config.js +++ b/test/generator/svg-xmlns/_config.js @@ -1,4 +1,6 @@ export default { + 'skip-ssr': true, + data: { x: 0, y: 0, diff --git a/test/ssr.js b/test/ssr.js index d03b1b8d06..6cc42608ac 100644 --- a/test/ssr.js +++ b/test/ssr.js @@ -1,7 +1,7 @@ import assert from 'assert'; import * as fs from 'fs'; -import { exists, loadConfig, setupHtmlEqual, svelte, tryToLoadJson } from './helpers.js'; +import { addLineNumbers, exists, loadConfig, setupHtmlEqual, svelte, tryToLoadJson } from './helpers.js'; function tryToReadFile ( file ) { try { @@ -57,13 +57,15 @@ describe( 'ssr', () => { if ( config.solo && process.env.CI ) { throw new Error( 'Forgot to remove `solo: true` from test' ); } - + if ( config['skip-ssr'] ) return; ( config.skip ? it.skip : config.solo ? it.only : it )( dir, () => { + let compiled; + try { const source = fs.readFileSync( `test/generator/${dir}/main.html`, 'utf-8' ); - svelte.compile( source, { generate: 'ssr' }); + compiled = svelte.compile( source, { generate: 'ssr' }); } catch ( err ) { if ( config.compileError ) { config.compileError( err ); @@ -74,11 +76,17 @@ describe( 'ssr', () => { } const component = require( `./generator/${dir}/main.html` ); + let html; - const html = component.render( config.data ); + try { + html = component.render( config.data ); - if ( config.html ) { - assert.htmlEqual( html, config.html ); + if ( config.html ) { + assert.htmlEqual( html, config.html ); + } + } catch ( err ) { + console.log( addLineNumbers( compiled.code ) ); + throw err; } }); });