|
|
|
@ -3,84 +3,80 @@ import { svelte, deindent, env, setupHtmlEqual } from "../helpers.js";
|
|
|
|
|
|
|
|
|
|
function testAmd(code, expectedId, dependencies, html) {
|
|
|
|
|
const fn = new Function("define", code);
|
|
|
|
|
const window = env();
|
|
|
|
|
|
|
|
|
|
return env().then(window => {
|
|
|
|
|
function define(id, deps, factory) {
|
|
|
|
|
assert.equal(id, expectedId);
|
|
|
|
|
assert.deepEqual(deps, Object.keys(dependencies));
|
|
|
|
|
function define(id, deps, factory) {
|
|
|
|
|
assert.equal(id, expectedId);
|
|
|
|
|
assert.deepEqual(deps, Object.keys(dependencies));
|
|
|
|
|
|
|
|
|
|
const SvelteComponent = factory(
|
|
|
|
|
...Object.keys(dependencies).map(key => dependencies[key])
|
|
|
|
|
);
|
|
|
|
|
const SvelteComponent = factory(
|
|
|
|
|
...Object.keys(dependencies).map(key => dependencies[key])
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const main = window.document.body.querySelector("main");
|
|
|
|
|
const component = new SvelteComponent({ target: main });
|
|
|
|
|
const main = window.document.body.querySelector("main");
|
|
|
|
|
const component = new SvelteComponent({ target: main });
|
|
|
|
|
|
|
|
|
|
assert.htmlEqual(main.innerHTML, html);
|
|
|
|
|
assert.htmlEqual(main.innerHTML, html);
|
|
|
|
|
|
|
|
|
|
component.destroy();
|
|
|
|
|
}
|
|
|
|
|
component.destroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
define.amd = true;
|
|
|
|
|
define.amd = true;
|
|
|
|
|
|
|
|
|
|
fn(define);
|
|
|
|
|
});
|
|
|
|
|
fn(define);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function testCjs(code, dependencyById, html) {
|
|
|
|
|
const fn = new Function("module", "exports", "require", code);
|
|
|
|
|
const window = env();
|
|
|
|
|
|
|
|
|
|
return env().then(window => {
|
|
|
|
|
const module = { exports: {} };
|
|
|
|
|
const require = id => {
|
|
|
|
|
return dependencyById[id];
|
|
|
|
|
};
|
|
|
|
|
const module = { exports: {} };
|
|
|
|
|
const require = id => {
|
|
|
|
|
return dependencyById[id];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
fn(module, module.exports, require);
|
|
|
|
|
fn(module, module.exports, require);
|
|
|
|
|
|
|
|
|
|
const SvelteComponent = module.exports;
|
|
|
|
|
const SvelteComponent = module.exports;
|
|
|
|
|
|
|
|
|
|
const main = window.document.body.querySelector("main");
|
|
|
|
|
const component = new SvelteComponent({ target: main });
|
|
|
|
|
const main = window.document.body.querySelector("main");
|
|
|
|
|
const component = new SvelteComponent({ target: main });
|
|
|
|
|
|
|
|
|
|
assert.htmlEqual(main.innerHTML, html);
|
|
|
|
|
assert.htmlEqual(main.innerHTML, html);
|
|
|
|
|
|
|
|
|
|
component.destroy();
|
|
|
|
|
});
|
|
|
|
|
component.destroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function testIife(code, name, globals, html) {
|
|
|
|
|
const fn = new Function(Object.keys(globals), `${code}\n\nreturn ${name};`);
|
|
|
|
|
const window = env();
|
|
|
|
|
|
|
|
|
|
return env().then(window => {
|
|
|
|
|
const SvelteComponent = fn(
|
|
|
|
|
...Object.keys(globals).map(key => globals[key])
|
|
|
|
|
);
|
|
|
|
|
const SvelteComponent = fn(
|
|
|
|
|
...Object.keys(globals).map(key => globals[key])
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const main = window.document.body.querySelector("main");
|
|
|
|
|
const component = new SvelteComponent({ target: main });
|
|
|
|
|
const main = window.document.body.querySelector("main");
|
|
|
|
|
const component = new SvelteComponent({ target: main });
|
|
|
|
|
|
|
|
|
|
assert.htmlEqual(main.innerHTML, html);
|
|
|
|
|
assert.htmlEqual(main.innerHTML, html);
|
|
|
|
|
|
|
|
|
|
component.destroy();
|
|
|
|
|
});
|
|
|
|
|
component.destroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function testEval(code, name, globals, html) {
|
|
|
|
|
const fn = new Function(Object.keys(globals), `return ${code};`);
|
|
|
|
|
const window = env();
|
|
|
|
|
|
|
|
|
|
return env().then(window => {
|
|
|
|
|
const SvelteComponent = fn(
|
|
|
|
|
...Object.keys(globals).map(key => globals[key])
|
|
|
|
|
);
|
|
|
|
|
const SvelteComponent = fn(
|
|
|
|
|
...Object.keys(globals).map(key => globals[key])
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const main = window.document.body.querySelector("main");
|
|
|
|
|
const component = new SvelteComponent({ target: main });
|
|
|
|
|
const main = window.document.body.querySelector("main");
|
|
|
|
|
const component = new SvelteComponent({ target: main });
|
|
|
|
|
|
|
|
|
|
assert.htmlEqual(main.innerHTML, html);
|
|
|
|
|
assert.htmlEqual(main.innerHTML, html);
|
|
|
|
|
|
|
|
|
|
component.destroy();
|
|
|
|
|
});
|
|
|
|
|
component.destroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
describe("formats", () => {
|
|
|
|
@ -190,9 +186,9 @@ describe("formats", () => {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return testAmd(code, "foo", { answer: 42 }, `<div>42</div>`)
|
|
|
|
|
.then(() => testCjs(code, { answer: 42 }, `<div>42</div>`))
|
|
|
|
|
.then(() => testIife(code, "Foo", { answer: 42 }, `<div>42</div>`));
|
|
|
|
|
testAmd(code, "foo", { answer: 42 }, `<div>42</div>`);
|
|
|
|
|
testCjs(code, { answer: 42 }, `<div>42</div>`);
|
|
|
|
|
testIife(code, "Foo", { answer: 42 }, `<div>42</div>`);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|