From 4afa1332149be16df73adf60fe3821f17a7af646 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 27 Oct 2018 22:57:09 -0400 Subject: [PATCH] reinstate tests --- src/compile/render-dom/wrappers/Element/index.ts | 1 - src/compile/render-dom/wrappers/Head.ts | 2 ++ test/js/index.js | 9 +++++++-- test/js/samples/action/expected.js | 4 ++-- test/js/samples/debug-empty/expected.js | 5 ++++- test/js/samples/debug-foo-bar-baz-things/expected.js | 5 ++++- test/js/samples/debug-foo/expected.js | 5 ++++- .../dev-warning-missing-data-computed/expected.js | 5 ++++- test/js/samples/use-elements-as-anchors/expected.js | 2 +- test/js/samples/window-binding-scroll/expected.js | 2 +- 10 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/compile/render-dom/wrappers/Element/index.ts b/src/compile/render-dom/wrappers/Element/index.ts index 83647953b4..58b215889b 100644 --- a/src/compile/render-dom/wrappers/Element/index.ts +++ b/src/compile/render-dom/wrappers/Element/index.ts @@ -94,7 +94,6 @@ export default class ElementWrapper extends Wrapper { var: string; - constructor( renderer: Renderer, block: Block, diff --git a/src/compile/render-dom/wrappers/Head.ts b/src/compile/render-dom/wrappers/Head.ts index 3cc6c7749c..b9cd885145 100644 --- a/src/compile/render-dom/wrappers/Head.ts +++ b/src/compile/render-dom/wrappers/Head.ts @@ -17,6 +17,8 @@ export default class HeadWrapper extends Wrapper { ) { super(renderer, block, parent, node); + this.canUseInnerHTML = false; + this.fragment = new FragmentWrapper( renderer, block, diff --git a/test/js/index.js b/test/js/index.js index e9da9bb91e..9b9805f471 100644 --- a/test/js/index.js +++ b/test/js/index.js @@ -1,7 +1,6 @@ import assert from "assert"; import * as fs from "fs"; import * as path from "path"; -import { rollup } from "rollup"; import { loadConfig, svelte } from "../helpers.js"; describe("js", () => { @@ -35,8 +34,14 @@ describe("js", () => { } const output = `${dir}/_actual.js`; - fs.writeFileSync(output, actual); + + const expected = fs.readFileSync(`${dir}/expected.js`, "utf-8"); + + assert.equal( + actual.trim().replace(/^[ \t]+$/gm, ""), + expected.trim().replace(/^[ \t]+$/gm, "") + ); }); }); }); diff --git a/test/js/samples/action/expected.js b/test/js/samples/action/expected.js index 2c173d0133..83a668acd5 100644 --- a/test/js/samples/action/expected.js +++ b/test/js/samples/action/expected.js @@ -2,7 +2,7 @@ import { assign, createElement, detachNode, init, insert, noop, proto } from "svelte/shared.js"; function link(node) { - + function onClick(event) { event.preventDefault(); history.pushState(null, null, event.target.href); @@ -39,7 +39,7 @@ function create_main_fragment(component, ctx) { detachNode(a); } - if (typeof link_action.destroy === 'function') link_action.destroy.call(component); + if (link_action && typeof link_action.destroy === 'function') link_action.destroy.call(component); } }; } diff --git a/test/js/samples/debug-empty/expected.js b/test/js/samples/debug-empty/expected.js index ffe8867c29..482eb26e24 100644 --- a/test/js/samples/debug-empty/expected.js +++ b/test/js/samples/debug-empty/expected.js @@ -44,7 +44,10 @@ function create_main_fragment(component, ctx) { function SvelteComponent(options) { this._debugName = ''; - if (!options || (!options.target && !options.root)) throw new Error("'target' is a required option"); + if (!options || (!options.target && !options.root)) { + throw new Error("'target' is a required option"); + } + init(this, options); this._state = assign({}, options.data); if (!('name' in this._state)) console.warn(" was created without expected data property 'name'"); diff --git a/test/js/samples/debug-foo-bar-baz-things/expected.js b/test/js/samples/debug-foo-bar-baz-things/expected.js index 6430cc5b3f..cc00d13d3f 100644 --- a/test/js/samples/debug-foo-bar-baz-things/expected.js +++ b/test/js/samples/debug-foo-bar-baz-things/expected.js @@ -131,7 +131,10 @@ function create_each_block(component, ctx) { function SvelteComponent(options) { this._debugName = ''; - if (!options || (!options.target && !options.root)) throw new Error("'target' is a required option"); + if (!options || (!options.target && !options.root)) { + throw new Error("'target' is a required option"); + } + init(this, options); this._state = assign({}, options.data); if (!('things' in this._state)) console.warn(" was created without expected data property 'things'"); diff --git a/test/js/samples/debug-foo/expected.js b/test/js/samples/debug-foo/expected.js index 1dd12d272e..091838cde8 100644 --- a/test/js/samples/debug-foo/expected.js +++ b/test/js/samples/debug-foo/expected.js @@ -131,7 +131,10 @@ function create_each_block(component, ctx) { function SvelteComponent(options) { this._debugName = ''; - if (!options || (!options.target && !options.root)) throw new Error("'target' is a required option"); + if (!options || (!options.target && !options.root)) { + throw new Error("'target' is a required option"); + } + init(this, options); this._state = assign({}, options.data); if (!('things' in this._state)) console.warn(" was created without expected data property 'things'"); diff --git a/test/js/samples/dev-warning-missing-data-computed/expected.js b/test/js/samples/dev-warning-missing-data-computed/expected.js index 2a5a3cedf9..9930eaacba 100644 --- a/test/js/samples/dev-warning-missing-data-computed/expected.js +++ b/test/js/samples/dev-warning-missing-data-computed/expected.js @@ -46,7 +46,10 @@ function create_main_fragment(component, ctx) { function SvelteComponent(options) { this._debugName = ''; - if (!options || (!options.target && !options.root)) throw new Error("'target' is a required option"); + if (!options || (!options.target && !options.root)) { + throw new Error("'target' is a required option"); + } + init(this, options); this._state = assign({ Math : Math }, options.data); this._recompute({ foo: 1 }, this._state); diff --git a/test/js/samples/use-elements-as-anchors/expected.js b/test/js/samples/use-elements-as-anchors/expected.js index 3627a22943..9bede88e68 100644 --- a/test/js/samples/use-elements-as-anchors/expected.js +++ b/test/js/samples/use-elements-as-anchors/expected.js @@ -58,7 +58,7 @@ function create_main_fragment(component, ctx) { if (!if_block0) { if_block0 = create_if_block_4(component, ctx); if_block0.c(); - if_block0.m(div, null); + if_block0.m(div, text0); } } else if (if_block0) { if_block0.d(1); diff --git a/test/js/samples/window-binding-scroll/expected.js b/test/js/samples/window-binding-scroll/expected.js index 94d3247865..ae6a4324bb 100644 --- a/test/js/samples/window-binding-scroll/expected.js +++ b/test/js/samples/window-binding-scroll/expected.js @@ -16,7 +16,7 @@ function create_main_fragment(component, ctx) { window.addEventListener("scroll", onwindowscroll); component.on("state", ({ changed, current }) => { - if (changed["y"]) { + if (changed["y"] && !window_updating) { window_updating = true; clearTimeout(window_updating_timeout); window.scrollTo(window.pageXOffset, current["y"]);