diff --git a/test/runtime/index.js b/test/runtime/index.js index 3e3d070cfe..b572ec81bc 100644 --- a/test/runtime/index.js +++ b/test/runtime/index.js @@ -51,7 +51,7 @@ describe("runtime", () => { throw new Error("Forgot to remove `solo: true` from test"); } - (config.skip ? it.skip : config.solo ? it.only : it)(`${dir} (${shared ? 'shared' : 'inline'} helpers)`, async () => { + (config.skip ? it.skip : config.solo ? it.only : it)(`${dir} (${shared ? 'shared' : 'inline'} helpers)`, () => { if (failed.has(dir)) { // this makes debugging easier, by only printing compiled output once throw new Error('skipping test, already failed'); @@ -105,95 +105,98 @@ describe("runtime", () => { const window = env(); - try { - // set of hacks to support transition tests - transitionManager.running = false; - transitionManager.transitions = []; - - const raf = { - time: 0, - callback: null, - tick: now => { - raf.time = now; - if (raf.callback) raf.callback(); - } - }; - window.performance = { now: () => raf.time }; - global.requestAnimationFrame = cb => { - let called = false; - raf.callback = () => { - if (!called) { - called = true; - cb(); + return Promise.resolve() + .then(() => { + // set of hacks to support transition tests + transitionManager.running = false; + transitionManager.transitions = []; + + const raf = { + time: 0, + callback: null, + tick: now => { + raf.time = now; + if (raf.callback) raf.callback(); } }; - }; - - global.window = window; + window.performance = { now: () => raf.time }; + global.requestAnimationFrame = cb => { + let called = false; + raf.callback = () => { + if (!called) { + called = true; + cb(); + } + }; + }; - try { - SvelteComponent = require(`./samples/${dir}/main.html`); - } catch (err) { - showOutput(cwd, { shared, format: 'cjs', hydratable: hydrate }, svelte); // eslint-disable-line no-console - throw err; - } + global.window = window; - global.window = window; + try { + SvelteComponent = require(`./samples/${dir}/main.html`); + } catch (err) { + showOutput(cwd, { shared, format: 'cjs', hydratable: hydrate }, svelte); // eslint-disable-line no-console + throw err; + } - // Put the constructor on window for testing - window.SvelteComponent = SvelteComponent; + global.window = window; - const target = window.document.querySelector("main"); + // Put the constructor on window for testing + window.SvelteComponent = SvelteComponent; - const warnings = []; - const warn = console.warn; - console.warn = warning => { - warnings.push(warning); - }; + const target = window.document.querySelector("main"); - const options = Object.assign({}, { - target, - hydrate, - data: config.data - }, config.options || {}); + const warnings = []; + const warn = console.warn; + console.warn = warning => { + warnings.push(warning); + }; - const component = new SvelteComponent(options); + const options = Object.assign({}, { + target, + hydrate, + data: config.data + }, config.options || {}); - console.warn = warn; + const component = new SvelteComponent(options); - if (config.error) { - unintendedError = true; - throw new Error("Expected a runtime error"); - } + console.warn = warn; - if (config.warnings) { - assert.deepEqual(warnings, config.warnings); - } else if (warnings.length) { - unintendedError = true; - throw new Error("Received unexpected warnings"); - } + if (config.error) { + unintendedError = true; + throw new Error("Expected a runtime error"); + } - if (config.html) { - assert.htmlEqual(target.innerHTML, config.html); - } + if (config.warnings) { + assert.deepEqual(warnings, config.warnings); + } else if (warnings.length) { + unintendedError = true; + throw new Error("Received unexpected warnings"); + } - if (config.test) { - await config.test(assert, component, target, window, raf); - } else { - component.destroy(); - assert.equal(target.innerHTML, ""); - } - } catch (err) { - if (config.error && !unintendedError) { - config.error(assert, err); - } else { - failed.add(dir); - showOutput(cwd, { shared, format: 'cjs', hydratable: hydrate }, svelte); // eslint-disable-line no-console - throw err; - } - } + if (config.html) { + assert.htmlEqual(target.innerHTML, config.html); + } - if (config.show) showOutput(cwd, { shared, format: 'cjs', hydratable: hydrate }, svelte); + if (config.test) { + return config.test(assert, component, target, window, raf); + } else { + component.destroy(); + assert.equal(target.innerHTML, ""); + } + }) + .catch(err => { + if (config.error && !unintendedError) { + config.error(assert, err); + } else { + failed.add(dir); + showOutput(cwd, { shared, format: 'cjs', hydratable: hydrate }, svelte); // eslint-disable-line no-console + throw err; + } + }) + .then(() => { + if (config.show) showOutput(cwd, { shared, format: 'cjs', hydratable: hydrate }, svelte); + }); }); } diff --git a/test/runtime/samples/await-then-catch/_config.js b/test/runtime/samples/await-then-catch/_config.js index 9f03479d9c..ed467b0382 100644 --- a/test/runtime/samples/await-then-catch/_config.js +++ b/test/runtime/samples/await-then-catch/_config.js @@ -13,38 +13,37 @@ export default {
loading...
`, - async test(assert, component, target) { + test(assert, component, target) { fulfil(42); - await thePromise; - assert.htmlEqual(target.innerHTML, ` -the value is 42
- `); + return thePromise + .then(() => { + assert.htmlEqual(target.innerHTML, ` +the value is 42
+ `); - let reject; + let reject; - thePromise = new Promise((f, r) => { - reject = r; - }); + thePromise = new Promise((f, r) => { + reject = r; + }); - component.set({ - thePromise - }); + component.set({ + thePromise + }); - assert.htmlEqual(target.innerHTML, ` -loading...
- `); + assert.htmlEqual(target.innerHTML, ` +loading...
+ `); - reject(new Error('something broke')); + reject(new Error('something broke')); - try { - await thePromise; - } catch (err) { - // do nothing - } - - assert.htmlEqual(target.innerHTML, ` -oh no! something broke
- `); + return thePromise.catch(() => {}); + }) + .then(() => { + assert.htmlEqual(target.innerHTML, ` +oh no! something broke
+ `); + }); } }; \ No newline at end of file