|
|
|
@ -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);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|