|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
import assert from "assert";
|
|
|
|
|
import * as fs from "fs";
|
|
|
|
|
import { svelte } from "../helpers.js";
|
|
|
|
|
import { env, svelte } from "../helpers.js";
|
|
|
|
|
|
|
|
|
|
function tryRequire(file) {
|
|
|
|
|
try {
|
|
|
|
@ -23,19 +23,45 @@ describe("css", () => {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(solo ? it.only : it)(dir, () => {
|
|
|
|
|
const config = tryRequire(`./samples/${dir}/_config.js`) || {};
|
|
|
|
|
const config = Object.assign(tryRequire(`./samples/${dir}/_config.js`) || {}, {
|
|
|
|
|
format: 'iife',
|
|
|
|
|
name: 'SvelteComponent'
|
|
|
|
|
});
|
|
|
|
|
const input = fs
|
|
|
|
|
.readFileSync(`test/css/samples/${dir}/input.html`, "utf-8")
|
|
|
|
|
.replace(/\s+$/, "");
|
|
|
|
|
|
|
|
|
|
const actual = svelte.compile(input, config).css;
|
|
|
|
|
fs.writeFileSync(`test/css/samples/${dir}/_actual.css`, actual);
|
|
|
|
|
const expected = fs.readFileSync(
|
|
|
|
|
`test/css/samples/${dir}/expected.css`,
|
|
|
|
|
"utf-8"
|
|
|
|
|
);
|
|
|
|
|
const actual = svelte.compile(input, config);
|
|
|
|
|
fs.writeFileSync(`test/css/samples/${dir}/_actual.css`, actual.css);
|
|
|
|
|
const expected = {
|
|
|
|
|
html: read(`test/css/samples/${dir}/expected.html`),
|
|
|
|
|
css: read(`test/css/samples/${dir}/expected.css`)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
assert.equal(actual.css.trim(), expected.css.trim());
|
|
|
|
|
|
|
|
|
|
// verify that the right elements have scoping selectors
|
|
|
|
|
if (expected.html !== null) {
|
|
|
|
|
return env().then(window => {
|
|
|
|
|
const Component = eval(`(function () { ${actual.code}; return SvelteComponent; }())`);
|
|
|
|
|
const target = window.document.querySelector("main");
|
|
|
|
|
|
|
|
|
|
assert.equal(actual.trim(), expected.trim());
|
|
|
|
|
new Component({ target });
|
|
|
|
|
const html = target.innerHTML;
|
|
|
|
|
|
|
|
|
|
fs.writeFileSync(`test/css/samples/${dir}/_actual.html`, html);
|
|
|
|
|
|
|
|
|
|
assert.equal(html.trim(), expected.html.trim());
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function read(file) {
|
|
|
|
|
try {
|
|
|
|
|
return fs.readFileSync(file, 'utf-8');
|
|
|
|
|
} catch(err) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|