|
|
|
@ -3,8 +3,8 @@ 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));
|
|
|
|
@ -24,13 +24,12 @@ function testAmd(code, expectedId, dependencies, html) {
|
|
|
|
|
define.amd = true;
|
|
|
|
|
|
|
|
|
|
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];
|
|
|
|
@ -46,13 +45,12 @@ function testCjs(code, dependencyById, html) {
|
|
|
|
|
assert.htmlEqual(main.innerHTML, html);
|
|
|
|
|
|
|
|
|
|
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])
|
|
|
|
|
);
|
|
|
|
@ -63,13 +61,12 @@ function testIife(code, name, globals, html) {
|
|
|
|
|
assert.htmlEqual(main.innerHTML, html);
|
|
|
|
|
|
|
|
|
|
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])
|
|
|
|
|
);
|
|
|
|
@ -80,7 +77,6 @@ function testEval(code, name, globals, html) {
|
|
|
|
|
assert.htmlEqual(main.innerHTML, html);
|
|
|
|
|
|
|
|
|
|
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>`);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|