From 70dad6af54380133722f09ec05afb6fd16c00e46 Mon Sep 17 00:00:00 2001 From: pushkine Date: Thu, 21 May 2020 20:21:50 +0200 Subject: [PATCH] remove styling --- test/css/index.ts | 27 ++++++---- test/custom-elements/index.ts | 10 ++-- test/helpers.ts | 36 ++++++++----- test/hydration/index.ts | 17 +++--- test/motion/index.ts | 2 +- test/parser/index.ts | 11 ++-- test/server-side-rendering/index.ts | 81 ++++++++++++++++------------- test/store/index.ts | 2 +- 8 files changed, 103 insertions(+), 83 deletions(-) diff --git a/test/css/index.ts b/test/css/index.ts index 8f1545bb6b..7bb537798a 100644 --- a/test/css/index.ts +++ b/test/css/index.ts @@ -13,7 +13,10 @@ function try_require(file) { } function normalize_warning(warning) { - warning.frame = warning.frame.replace(/^\n/, '').replace(/^\t+/gm, '').replace(/\s+$/gm, ''); + warning.frame = warning.frame + .replace(/^\n/, '') + .replace(/^\t+/gm, '') + .replace(/\s+$/gm, ''); delete warning.filename; delete warning.toString; delete warning.start; @@ -26,7 +29,7 @@ function create(code) { const fn = new Function('module', 'exports', 'require', code); const module = { exports: {} }; - fn(module, module.exports, (id) => { + fn(module, module.exports, id => { if (id === 'svelte') return require('../../index.js'); if (id.startsWith('svelte/')) return require(id.replace('svelte', '../../')); @@ -41,7 +44,7 @@ describe('css', () => { setupHtmlEqual(); }); - readdirSync(`${__dirname}/samples`).forEach((dir) => { + readdirSync(`${__dirname}/samples`).forEach(dir => { if (dir[0] === '.') return; // add .solo to a sample directory name to only run that test @@ -58,9 +61,15 @@ describe('css', () => { const expected_warnings = (config.warnings || []).map(normalize_warning); - const dom = svelte.compile(input, Object.assign(config.compileOptions || {}, { format: 'cjs' })); + const dom = svelte.compile( + input, + Object.assign(config.compileOptions || {}, { format: 'cjs' }) + ); - const ssr = svelte.compile(input, Object.assign(config.compileOptions || {}, { format: 'cjs', generate: 'ssr' })); + const ssr = svelte.compile( + input, + Object.assign(config.compileOptions || {}, { format: 'cjs', generate: 'ssr' }) + ); assert.equal(dom.css.code, ssr.css.code); @@ -73,10 +82,10 @@ describe('css', () => { writeFileSync(`${__dirname}/samples/${dir}/_actual.css`, dom.css.code); const expected = { html: read(`${__dirname}/samples/${dir}/expected.html`), - css: read(`${__dirname}/samples/${dir}/expected.css`), + css: read(`${__dirname}/samples/${dir}/expected.css`) }; - const actual_css = dom.css.code.replace(/svelte(-ref)?-[a-z0-9]+/g, (m, $1) => ($1 ? m : 'svelte-xyz')); + const actual_css = dom.css.code.replace(/svelte(-ref)?-[a-z0-9]+/g, (m, $1) => $1 ? m : 'svelte-xyz'); try { assert.equal(actual_css, expected.css); } catch (error) { @@ -131,9 +140,7 @@ describe('css', () => { // ssr try { - const actual_ssr = ServerComponent.render(config.props).html.replace(/svelte(-ref)?-[a-z0-9]+/g, (m, $1) => - $1 ? m : 'svelte-xyz' - ); + const actual_ssr = ServerComponent.render(config.props).html.replace(/svelte(-ref)?-[a-z0-9]+/g, (m, $1) => $1 ? m : 'svelte-xyz'); assert.htmlEqual(actual_ssr, expected.html); } catch (err) { console.log(ssr.js.code); diff --git a/test/custom-elements/index.ts b/test/custom-elements/index.ts index da303c89da..c0e510da81 100644 --- a/test/custom-elements/index.ts +++ b/test/custom-elements/index.ts @@ -53,7 +53,7 @@ describe('custom-elements', function () { await browser.close(); }); - fs.readdirSync(`${__dirname}/samples`).forEach((dir) => { + fs.readdirSync(`${__dirname}/samples`).forEach(dir => { if (dir[0] === '.') return; const solo = /\.solo$/.test(dir); @@ -94,9 +94,9 @@ describe('custom-elements', function () { }, }, virtual({ - assert, - }), - ], + assert + }) + ] }); const result = await bundle.generate({ format: 'iife', name: 'test' }); @@ -108,7 +108,7 @@ describe('custom-elements', function () { console[type](...args); }); - page.on('error', (error) => { + page.on('error', error => { console.log('>>> an error happened'); console.error(error); }); diff --git a/test/helpers.ts b/test/helpers.ts index 3197779b35..d5ec4c298a 100644 --- a/test/helpers.ts +++ b/test/helpers.ts @@ -47,14 +47,14 @@ export function tryToReadFile(file) { export function cleanRequireCache() { Object.keys(require.cache) - .filter((x) => x.endsWith('.svelte')) - .forEach((file) => delete require.cache[file]); + .filter(x => x.endsWith('.svelte')) + .forEach(file => delete require.cache[file]); } const virtualConsole = new jsdom.VirtualConsole(); virtualConsole.sendTo(console); -const { window } = new jsdom.JSDOM('
', { virtualConsole }); +const window = new jsdom.JSDOM('
', {virtualConsole}).window; global.document = window.document; global.navigator = window.navigator; @@ -68,7 +68,7 @@ for (const key of Object.getOwnPropertyNames(global)) { } // implement mock scroll -window.scrollTo = function (pageXOffset, pageYOffset) { +window.scrollTo = function(pageXOffset, pageYOffset) { window.pageXOffset = pageXOffset; window.pageYOffset = pageYOffset; }; @@ -89,11 +89,11 @@ function cleanChildren(node: Element) { return a.name < b.name ? -1 : 1; }); - attributes.forEach((attr) => { + attributes.forEach(attr => { node.removeAttribute(attr.name); }); - attributes.forEach((attr) => { + attributes.forEach(attr => { node.setAttribute(attr.name, attr.value); }); @@ -148,8 +148,12 @@ export function normalizeHtml(window, html) { export function setupHtmlEqual() { const window = env(); - assert.htmlEqual = function (actual, expected, message) { - assert.deepEqual(normalizeHtml(window, actual), normalizeHtml(window, expected), message); + assert.htmlEqual = (actual, expected, message) => { + assert.deepEqual( + normalizeHtml(window, actual), + normalizeHtml(window, expected), + message + ); }; } @@ -175,20 +179,24 @@ export function addLineNumbers(code) { .map((line, i) => { i = String(i + 1); while (i.length < 3) i = ` ${i}`; - return colors.gray(` ${i}: `) + line.replace(/^\t+/, (match) => match.split('\t').join(' ')); + + return ( + colors.gray(` ${i}: `) + + line.replace(/^\t+/, match => match.split('\t').join(' ')) + ); }) .join('\n'); } export function showOutput(cwd, options = {}, compile = svelte.compile) { - glob('**/*.svelte', { cwd }).forEach((file) => { + glob('**/*.svelte', { cwd }).forEach(file => { if (file[0] === '_') return; try { const { js } = compile( fs.readFileSync(`${cwd}/${file}`, 'utf-8'), Object.assign(options, { - filename: file, + filename: file }) ); @@ -218,13 +226,13 @@ export function useFakeTimers() { return { flush() { - callbacks.forEach((fn) => fn()); + callbacks.forEach(fn => fn()); callbacks.splice(0, callbacks.length); }, removeFakeTimers() { callbacks.splice(0, callbacks.length); global.setTimeout = original_set_timeout; - }, + } }; } @@ -239,4 +247,4 @@ export function mkdirp(dir) { } catch (err) { // do nothing } -} +} \ No newline at end of file diff --git a/test/hydration/index.ts b/test/hydration/index.ts index a5262c1b99..1d90aa69ed 100644 --- a/test/hydration/index.ts +++ b/test/hydration/index.ts @@ -12,13 +12,13 @@ describe('hydration', () => { before(() => { const svelte = loadSvelte(); - require.extensions['.svelte'] = function (module, filename) { + require.extensions['.svelte'] = function(module, filename) { const options = Object.assign( { filename, hydratable: true, format: 'cjs', - sveltePath, + sveltePath }, compileOptions ); @@ -75,7 +75,7 @@ describe('hydration', () => { const component = new SvelteComponent({ target, hydrate: true, - props: config.props, + props: config.props }); try { @@ -110,19 +110,18 @@ describe('hydration', () => { } } catch (err) { showOutput(cwd, { - hydratable: true, + hydratable: true }); throw err; } - if (config.show) - showOutput(cwd, { - hydratable: true, - }); + if (config.show) showOutput(cwd, { + hydratable: true + }); }); } - fs.readdirSync(`${__dirname}/samples`).forEach((dir) => { + fs.readdirSync(`${__dirname}/samples`).forEach(dir => { runTest(dir, null); }); }); diff --git a/test/motion/index.ts b/test/motion/index.ts index 220e234ee5..d4299629a4 100644 --- a/test/motion/index.ts +++ b/test/motion/index.ts @@ -23,7 +23,7 @@ describe('motion', () => { it('sets immediately when duration is 0', () => { const size = tweened(0); - size.set(100, { duration: 0 }); + size.set(100, { duration : 0 }); assert.equal(get(size), 100); }); }); diff --git a/test/parser/index.ts b/test/parser/index.ts index f5590834e2..c3a0251340 100644 --- a/test/parser/index.ts +++ b/test/parser/index.ts @@ -3,7 +3,7 @@ import { svelte, tryToLoadJson } from '../helpers'; import { assert } from '../test'; describe('parser', () => { - fs.readdirSync(`${__dirname}/samples`).forEach((dir) => { + fs.readdirSync(`${__dirname}/samples`).forEach(dir => { if (dir[0] === '.') return; // add .solo to a sample directory name to only run that test @@ -23,12 +23,9 @@ describe('parser', () => { const expectedError = tryToLoadJson(`${__dirname}/samples/${dir}/error.json`); try { - const { ast } = svelte.compile( - input, - Object.assign(options, { - generate: false, - }) - ); + const { ast } = svelte.compile(input, Object.assign(options, { + generate: false + })); fs.writeFileSync(`${__dirname}/samples/${dir}/_actual.json`, JSON.stringify(ast, null, '\t')); diff --git a/test/server-side-rendering/index.ts b/test/server-side-rendering/index.ts index 4d1c3dc8c9..e7dcfbeb56 100644 --- a/test/server-side-rendering/index.ts +++ b/test/server-side-rendering/index.ts @@ -1,5 +1,5 @@ -import * as fs from 'fs'; -import * as path from 'path'; +import * as fs from "fs"; +import * as path from "path"; import { showOutput, @@ -10,31 +10,31 @@ import { cleanRequireCache, shouldUpdateExpected, mkdirp, -} from '../helpers'; -import { glob } from '../tiny-glob'; -import { assert } from '../test'; +} from "../helpers"; +import { glob } from "../tiny-glob"; +import { assert } from "../test"; function tryToReadFile(file) { try { - return fs.readFileSync(file, 'utf-8'); + return fs.readFileSync(file, "utf-8"); } catch (err) { - if (err.code !== 'ENOENT') throw err; + if (err.code !== "ENOENT") throw err; return null; } } -const sveltePath = process.cwd().split('\\').join('/'); +const sveltePath = process.cwd().split("\\").join("/"); let compile = null; -describe('ssr', () => { +describe("ssr", () => { before(() => { compile = loadSvelte(true).compile; return setupHtmlEqual(); }); - fs.readdirSync(`${__dirname}/samples`).forEach((dir) => { - if (dir[0] === '.') return; + fs.readdirSync(`${__dirname}/samples`).forEach(dir => { + if (dir[0] === ".") return; const config = loadConfig(`${__dirname}/samples/${dir}/_config.js`); @@ -45,7 +45,7 @@ describe('ssr', () => { const show = /\.show/.test(dir); if (solo && process.env.CI) { - throw new Error('Forgot to remove `solo: true` from test'); + throw new Error("Forgot to remove `solo: true` from test"); } (skip ? it.skip : solo ? it.only : it)(dir, () => { @@ -56,17 +56,17 @@ describe('ssr', () => { const compileOptions = { sveltePath, ...config.compileOptions, - generate: 'ssr', - format: 'cjs', + generate: "ssr", + format: "cjs", }; - require('../../register')(compileOptions); + require("../../register")(compileOptions); try { const Component = require(`${dir}/main.svelte`).default; const expectedHtml = tryToReadFile(`${dir}/_expected.html`); - const expectedCss = tryToReadFile(`${dir}/_expected.css`) || ''; + const expectedCss = tryToReadFile(`${dir}/_expected.css`) || ""; const props = tryToLoadJson(`${dir}/data.json`) || undefined; @@ -88,7 +88,10 @@ describe('ssr', () => { } try { - assert.equal(css.code.replace(/^\s+/gm, '').replace(/[\r\n]/, ''), expectedCss.replace(/^\s+/gm, '').replace(/[\r\n]/, '')); + assert.equal( + css.code.replace(/^\s+/gm, "").replace(/[\r\n]/, ""), + expectedCss.replace(/^\s+/gm, "").replace(/[\r\n]/, "") + ); } catch (error) { if (shouldUpdateExpected()) { fs.writeFileSync(`${dir}/_expected.css`, css.code); @@ -102,7 +105,10 @@ describe('ssr', () => { fs.writeFileSync(`${dir}/_actual-head.html`, head); try { - assert.htmlEqual(head, fs.readFileSync(`${dir}/_expected-head.html`, 'utf-8')); + assert.htmlEqual( + head, + fs.readFileSync(`${dir}/_expected-head.html`, 'utf-8') + ); } catch (error) { if (shouldUpdateExpected()) { fs.writeFileSync(`${dir}/_expected-head.html`, head); @@ -113,9 +119,9 @@ describe('ssr', () => { } } - if (show) showOutput(dir, { generate: 'ssr', format: 'cjs' }); + if (show) showOutput(dir, { generate: "ssr", format: "cjs" }); } catch (err) { - showOutput(dir, { generate: 'ssr', format: 'cjs' }); + showOutput(dir, { generate: "ssr", format: "cjs" }); err.stack += `\n\ncmd-click: ${path.relative(process.cwd(), dir)}/main.svelte`; throw err; } @@ -123,21 +129,21 @@ describe('ssr', () => { }); // duplicate client-side tests, as far as possible - fs.readdirSync('test/runtime/samples').forEach((dir) => { - if (dir[0] === '.') return; + fs.readdirSync("test/runtime/samples").forEach(dir => { + if (dir[0] === ".") return; const config = loadConfig(`./runtime/samples/${dir}/_config.js`); const solo = config.solo || /\.solo/.test(dir); const skip = config.skip || /\.skip/.test(dir); if (solo && process.env.CI) { - throw new Error('Forgot to remove `solo: true` from test'); + throw new Error("Forgot to remove `solo: true` from test"); } if (config.skip_if_ssr) return; (skip ? it.skip : solo ? it.only : it)(dir, () => { - const cwd = path.resolve('test/runtime/samples', dir); + const cwd = path.resolve("test/runtime/samples", dir); cleanRequireCache(); @@ -146,17 +152,17 @@ describe('ssr', () => { const compileOptions = { sveltePath, ...config.compileOptions, - generate: 'ssr', - format: 'cjs', + generate: "ssr", + format: "cjs" }; - require('../../register')(compileOptions); + require("../../register")(compileOptions); - glob('**/*.svelte', { cwd }).forEach((file) => { - if (file[0] === '_') return; + glob("**/*.svelte", { cwd }).forEach((file) => { + if (file[0] === "_") return; const dir = `${cwd}/_output/ssr`; - const out = `${dir}/${file.replace(/\.svelte$/, '.js')}`; + const out = `${dir}/${file.replace(/\.svelte$/, ".js")}`; if (fs.existsSync(out)) { fs.unlinkSync(out); @@ -165,10 +171,13 @@ describe('ssr', () => { mkdirp(dir); try { - const { js } = compile(fs.readFileSync(`${cwd}/${file}`, 'utf-8'), { - ...compileOptions, - filename: file, - }); + const { js } = compile( + fs.readFileSync(`${cwd}/${file}`, 'utf-8'), + { + ...compileOptions, + filename: file + } + ); fs.writeFileSync(out, js.code); } catch (err) { @@ -181,7 +190,7 @@ describe('ssr', () => { const Component = require(`../runtime/samples/${dir}/main.svelte`).default; const { html } = Component.render(config.props, { - store: config.store !== true && config.store, + store: (config.store !== true) && config.store }); if (config.ssrHtml) { @@ -199,7 +208,7 @@ describe('ssr', () => { err.stack += `\n\ncmd-click: ${path.relative(process.cwd(), cwd)}/main.svelte`; if (config.error) { - if (typeof config.error === 'function') { + if (typeof config.error === "function") { config.error(assert, err); } else { assert.equal(err.message, config.error); diff --git a/test/store/index.ts b/test/store/index.ts index e02007f3d1..d475f74483 100644 --- a/test/store/index.ts +++ b/test/store/index.ts @@ -373,4 +373,4 @@ describe('store', () => { assert.equal(get(fake_observable), 42); }); }); -}); +}); \ No newline at end of file