From b9f9a93a60edd9eda986bdda689380374363b63b Mon Sep 17 00:00:00 2001 From: pushkine Date: Wed, 27 May 2020 19:11:58 +0200 Subject: [PATCH] init --- mocha.opts | 1 - package-lock.json | 22 ------------------- package.json | 11 +++++++--- test/css/{index.js => index.ts} | 3 +-- test/custom-elements/{index.js => index.ts} | 6 ++--- test/{helpers.js => helpers.ts} | 7 +++--- test/hydration/{index.js => index.ts} | 16 +++++--------- test/js/{index.js => index.ts} | 2 +- test/motion/{index.js => index.ts} | 0 test/parser/{index.js => index.ts} | 4 ++-- test/preprocess/{index.js => index.ts} | 2 +- test/runtime/{index.js => index.ts} | 8 +++---- .../{index.js => index.ts} | 6 ++--- test/{setup.js => setup.ts} | 0 test/sourcemaps/{index.js => index.ts} | 2 +- test/stats/{index.js => index.ts} | 2 +- test/store/{index.js => index.ts} | 0 test/{test.js => test.ts} | 8 +++---- test/validator/{index.js => index.ts} | 2 +- test/vars/{index.js => index.ts} | 2 +- 20 files changed, 41 insertions(+), 63 deletions(-) delete mode 100644 mocha.opts rename test/css/{index.js => index.ts} (97%) rename test/custom-elements/{index.js => index.ts} (96%) rename test/{helpers.js => helpers.ts} (95%) rename test/hydration/{index.js => index.ts} (93%) rename test/js/{index.js => index.ts} (99%) rename test/motion/{index.js => index.ts} (100%) rename test/parser/{index.js => index.ts} (96%) rename test/preprocess/{index.js => index.ts} (94%) rename test/runtime/{index.js => index.ts} (97%) rename test/server-side-rendering/{index.js => index.ts} (98%) rename test/{setup.js => setup.ts} (100%) rename test/sourcemaps/{index.js => index.ts} (98%) rename test/stats/{index.js => index.ts} (95%) rename test/store/{index.js => index.ts} (100%) rename test/{test.js => test.ts} (76%) rename test/validator/{index.js => index.ts} (97%) rename test/vars/{index.js => index.ts} (95%) diff --git a/mocha.opts b/mocha.opts deleted file mode 100644 index 427b029758..0000000000 --- a/mocha.opts +++ /dev/null @@ -1 +0,0 @@ -test/test.js \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index cd9a83e04b..87d1b99100 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1580,18 +1580,6 @@ "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", "dev": true }, - "globalyzer": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/globalyzer/-/globalyzer-0.1.4.tgz", - "integrity": "sha512-LeguVWaxgHN0MNbWC6YljNMzHkrCny9fzjmEUdnF1kQ7wATFD1RHFRqA1qxaX2tgxGENlcxjOflopBwj3YZiXA==", - "dev": true - }, - "globrex": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/globrex/-/globrex-0.1.2.tgz", - "integrity": "sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg==", - "dev": true - }, "graceful-fs": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.0.tgz", @@ -3565,16 +3553,6 @@ "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", "dev": true }, - "tiny-glob": { - "version": "0.2.6", - "resolved": "https://registry.npmjs.org/tiny-glob/-/tiny-glob-0.2.6.tgz", - "integrity": "sha512-A7ewMqPu1B5PWwC3m7KVgAu96Ch5LA0w4SnEN/LbDREj/gAD0nPWboRbn8YoP9ISZXqeNAlMvKSKoEuhcfK3Pw==", - "dev": true, - "requires": { - "globalyzer": "^0.1.0", - "globrex": "^0.1.1" - } - }, "tmp": { "version": "0.0.33", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", diff --git a/package.json b/package.json index 0d59059290..b9dccbca58 100644 --- a/package.json +++ b/package.json @@ -23,9 +23,9 @@ }, "types": "types/runtime/index.d.ts", "scripts": { - "test": "mocha --opts mocha.opts", + "test": "mocha", "test:unit": "mocha --require sucrase/register --recursive src/**/__test__.ts", - "quicktest": "mocha --opts mocha.opts", + "quicktest": "mocha", "update-expected": "node -r sucrase/register ./test/js/update.ts && node -r sucrase/register ./test/parser/update.ts", "precoverage": "c8 mocha --opts mocha.coverage.opts", "coverage": "c8 report --reporter=text-lcov > coverage.lcov && c8 report --reporter=html", @@ -40,6 +40,12 @@ "tsd": "tsc -p src/compiler --emitDeclarationOnly && tsc -p src/runtime --emitDeclarationOnly", "lint": "eslint \"{src,test}/**/*.{ts,js}\"" }, + "mocha": { + "file": "./test/test.ts", + "require": "sucrase/register", + "bail": true, + "timeout": "10000" + }, "repository": { "type": "git", "url": "https://github.com/sveltejs/svelte.git" @@ -89,7 +95,6 @@ "rollup": "^1.27.14", "source-map": "^0.7.3", "source-map-support": "^0.5.13", - "tiny-glob": "^0.2.6", "tslib": "^1.10.0", "typescript": "^3.5.3" }, diff --git a/test/css/index.js b/test/css/index.ts similarity index 97% rename from test/css/index.js rename to test/css/index.ts index 81d27a94bf..4dbb81b049 100644 --- a/test/css/index.js +++ b/test/css/index.ts @@ -1,6 +1,5 @@ -import * as assert from 'assert'; import * as fs from 'fs'; -import { env, svelte, setupHtmlEqual, shouldUpdateExpected } from '../helpers.js'; +import { env, svelte, setupHtmlEqual, shouldUpdateExpected, assert } from '../helpers'; function try_require(file) { try { diff --git a/test/custom-elements/index.js b/test/custom-elements/index.ts similarity index 96% rename from test/custom-elements/index.js rename to test/custom-elements/index.ts index b1bdf48219..4fd6803886 100644 --- a/test/custom-elements/index.js +++ b/test/custom-elements/index.ts @@ -2,9 +2,9 @@ import * as fs from 'fs'; import * as path from 'path'; import * as http from 'http'; import { rollup } from 'rollup'; -import * as virtual from '@rollup/plugin-virtual'; -import * as puppeteer from 'puppeteer'; -import { addLineNumbers, loadConfig, loadSvelte } from "../helpers.js"; +import virtual from '@rollup/plugin-virtual'; +import puppeteer from 'puppeteer'; +import { addLineNumbers, loadConfig, loadSvelte } from "../helpers"; import { deepEqual } from 'assert'; const page = ` diff --git a/test/helpers.js b/test/helpers.ts similarity index 95% rename from test/helpers.js rename to test/helpers.ts index a764d43f96..67636bc778 100644 --- a/test/helpers.js +++ b/test/helpers.ts @@ -1,9 +1,10 @@ +import * as assert$1 from 'assert'; import * as jsdom from 'jsdom'; -import * as assert from 'assert'; -import * as glob from 'tiny-glob/sync.js'; +import { glob } from './tiny-glob'; import * as path from 'path'; import * as fs from 'fs'; import * as colors from 'kleur'; +export const assert = (assert$1 as unknown) as typeof assert$1 & { htmlEqual: (actual, expected, message?) => void }; // for coverage purposes, we need to test source files, // but for sanity purposes, we need to test dist files @@ -63,7 +64,7 @@ global.window = window; // add missing ecmascript globals to window for (const key of Object.getOwnPropertyNames(global)) { - window[key] = window[key] || global[key]; + if (!(key in window)) window[key] = global[key]; } // implement mock scroll diff --git a/test/hydration/index.js b/test/hydration/index.ts similarity index 93% rename from test/hydration/index.js rename to test/hydration/index.ts index f57a0cdc1a..9c73c5f4ff 100644 --- a/test/hydration/index.js +++ b/test/hydration/index.ts @@ -1,15 +1,15 @@ -import * as assert from 'assert'; import * as path from 'path'; import * as fs from 'fs'; import { + assert, showOutput, loadConfig, loadSvelte, env, setupHtmlEqual, shouldUpdateExpected -} from '../helpers.js'; +} from '../helpers'; let compileOptions = null; @@ -58,13 +58,7 @@ describe('hydration', () => { try { global.window = window; - let SvelteComponent; - - try { - SvelteComponent = require(`${cwd}/main.svelte`).default; - } catch (err) { - throw err; - } + const SvelteComponent = require(`${cwd}/main.svelte`).default; const target = window.document.body; const head = window.document.head; @@ -75,7 +69,9 @@ describe('hydration', () => { try { before_head = fs.readFileSync(`${cwd}/_before_head.html`, 'utf-8'); head.innerHTML = before_head; - } catch (err) {} + } catch (err) { + // + } const snapshot = config.snapshot ? config.snapshot(target) : {}; diff --git a/test/js/index.js b/test/js/index.ts similarity index 99% rename from test/js/index.js rename to test/js/index.ts index 8aa4cc76a9..3a3643de47 100644 --- a/test/js/index.js +++ b/test/js/index.ts @@ -2,7 +2,7 @@ import * as assert from "assert"; import * as fs from "fs"; import * as path from "path"; import * as colors from "kleur"; -import { loadConfig, svelte, shouldUpdateExpected } from "../helpers.js"; +import { loadConfig, svelte, shouldUpdateExpected } from "../helpers"; describe("js", () => { fs.readdirSync(`${__dirname}/samples`).forEach(dir => { diff --git a/test/motion/index.js b/test/motion/index.ts similarity index 100% rename from test/motion/index.js rename to test/motion/index.ts diff --git a/test/parser/index.js b/test/parser/index.ts similarity index 96% rename from test/parser/index.js rename to test/parser/index.ts index 2c8d516a7d..32afcbbafc 100644 --- a/test/parser/index.js +++ b/test/parser/index.ts @@ -1,6 +1,6 @@ import * as assert from 'assert'; import * as fs from 'fs'; -import { svelte, tryToLoadJson, shouldUpdateExpected } from '../helpers.js'; +import { svelte, tryToLoadJson, shouldUpdateExpected } from '../helpers'; describe('parse', () => { fs.readdirSync(`${__dirname}/samples`).forEach(dir => { @@ -38,7 +38,7 @@ describe('parse', () => { } catch (err) { if (err.name !== 'ParseError') throw err; if (!expectedError) throw err; - const { code, message, pos, start } = err + const { code, message, pos, start } = err; try { assert.deepEqual({ code, message, pos, start }, expectedError); } catch (err2) { diff --git a/test/preprocess/index.js b/test/preprocess/index.ts similarity index 94% rename from test/preprocess/index.js rename to test/preprocess/index.ts index 5d83bb6059..abb45012ce 100644 --- a/test/preprocess/index.js +++ b/test/preprocess/index.ts @@ -1,6 +1,6 @@ import * as fs from 'fs'; import * as assert from 'assert'; -import { loadConfig, svelte } from '../helpers.js'; +import { loadConfig, svelte } from '../helpers'; describe('preprocess', () => { fs.readdirSync(`${__dirname}/samples`).forEach(dir => { diff --git a/test/runtime/index.js b/test/runtime/index.ts similarity index 97% rename from test/runtime/index.js rename to test/runtime/index.ts index 65157196c9..8809585a80 100644 --- a/test/runtime/index.js +++ b/test/runtime/index.ts @@ -1,12 +1,12 @@ -import * as assert from "assert"; import * as path from "path"; import * as fs from "fs"; import { rollup } from 'rollup'; -import * as virtual from '@rollup/plugin-virtual'; -import * as glob from 'tiny-glob/sync.js'; +import virtual from '@rollup/plugin-virtual'; +import { glob } from '../tiny-glob'; import { clear_loops, flush, set_now, set_raf } from "../../internal"; import { + assert, showOutput, loadConfig, loadSvelte, @@ -14,7 +14,7 @@ import { env, setupHtmlEqual, mkdirp -} from "../helpers.js"; +} from "../helpers"; let svelte$; let svelte; diff --git a/test/server-side-rendering/index.js b/test/server-side-rendering/index.ts similarity index 98% rename from test/server-side-rendering/index.js rename to test/server-side-rendering/index.ts index 2d539782ff..de3d11eeb5 100644 --- a/test/server-side-rendering/index.js +++ b/test/server-side-rendering/index.ts @@ -1,9 +1,9 @@ -import * as assert from "assert"; import * as fs from "fs"; import * as path from "path"; -import * as glob from 'tiny-glob/sync.js'; +import { glob } from '../tiny-glob'; import { + assert, showOutput, loadConfig, loadSvelte, @@ -12,7 +12,7 @@ import { cleanRequireCache, shouldUpdateExpected, mkdirp -} from "../helpers.js"; +} from "../helpers"; function tryToReadFile(file) { try { diff --git a/test/setup.js b/test/setup.ts similarity index 100% rename from test/setup.js rename to test/setup.ts diff --git a/test/sourcemaps/index.js b/test/sourcemaps/index.ts similarity index 98% rename from test/sourcemaps/index.js rename to test/sourcemaps/index.ts index 0b0424a764..da2d79295c 100644 --- a/test/sourcemaps/index.js +++ b/test/sourcemaps/index.ts @@ -1,7 +1,7 @@ import * as fs from "fs"; import * as path from "path"; import * as assert from "assert"; -import { svelte } from "../helpers.js"; +import { svelte } from "../helpers"; import { SourceMapConsumer } from "source-map"; import { getLocator } from "locate-character"; diff --git a/test/stats/index.js b/test/stats/index.ts similarity index 95% rename from test/stats/index.js rename to test/stats/index.ts index acea7a4663..a6efd93d22 100644 --- a/test/stats/index.js +++ b/test/stats/index.ts @@ -1,6 +1,6 @@ import * as fs from 'fs'; import * as assert from 'assert'; -import { svelte, loadConfig, tryToLoadJson } from '../helpers.js'; +import { svelte, loadConfig, tryToLoadJson } from '../helpers'; describe('stats', () => { fs.readdirSync(`${__dirname}/samples`).forEach(dir => { diff --git a/test/store/index.js b/test/store/index.ts similarity index 100% rename from test/store/index.js rename to test/store/index.ts diff --git a/test/test.js b/test/test.ts similarity index 76% rename from test/test.js rename to test/test.ts index 6ea4bd60ab..e713da1ccf 100644 --- a/test/test.js +++ b/test/test.ts @@ -1,14 +1,14 @@ const glob = require('tiny-glob/sync.js'); -require('./setup'); +import './setup'; // bind internal to jsdom -require('./helpers'); -require('../internal'); +import './helpers'; +import '../internal'; console.clear(); -const test_folders = glob('*/index.js', { cwd: 'test' }); +const test_folders = glob('*/index.ts', { cwd: 'test' }); const solo_folders = test_folders.filter(folder => /\.solo/.test(folder)); if (solo_folders.length) { diff --git a/test/validator/index.js b/test/validator/index.ts similarity index 97% rename from test/validator/index.js rename to test/validator/index.ts index 433e1a94ae..7408e8b085 100644 --- a/test/validator/index.js +++ b/test/validator/index.ts @@ -1,6 +1,6 @@ import * as fs from "fs"; import * as assert from "assert"; -import { svelte, loadConfig, tryToLoadJson } from "../helpers.js"; +import { svelte, loadConfig, tryToLoadJson } from "../helpers"; describe("validate", () => { fs.readdirSync(`${__dirname}/samples`).forEach(dir => { diff --git a/test/vars/index.js b/test/vars/index.ts similarity index 95% rename from test/vars/index.js rename to test/vars/index.ts index a12ac177f2..4cebf7fbb4 100644 --- a/test/vars/index.js +++ b/test/vars/index.ts @@ -1,6 +1,6 @@ import * as fs from 'fs'; import * as assert from 'assert'; -import { svelte, loadConfig, tryToLoadJson } from '../helpers.js'; +import { svelte, loadConfig, tryToLoadJson } from '../helpers'; describe('vars', () => { fs.readdirSync(`${__dirname}/samples`).forEach(dir => {