set up tests for omitted scoping attributes

pull/689/head
Rich Harris 8 years ago
parent d237983374
commit 0cbd201200

@ -1,6 +1,6 @@
import assert from "assert"; import assert from "assert";
import * as fs from "fs"; import * as fs from "fs";
import { svelte } from "../helpers.js"; import { env, svelte } from "../helpers.js";
function tryRequire(file) { function tryRequire(file) {
try { try {
@ -23,19 +23,45 @@ describe("css", () => {
} }
(solo ? it.only : it)(dir, () => { (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 const input = fs
.readFileSync(`test/css/samples/${dir}/input.html`, "utf-8") .readFileSync(`test/css/samples/${dir}/input.html`, "utf-8")
.replace(/\s+$/, ""); .replace(/\s+$/, "");
const actual = svelte.compile(input, config).css; const actual = svelte.compile(input, config);
fs.writeFileSync(`test/css/samples/${dir}/_actual.css`, actual); fs.writeFileSync(`test/css/samples/${dir}/_actual.css`, actual.css);
const expected = fs.readFileSync( const expected = {
`test/css/samples/${dir}/expected.css`, html: read(`test/css/samples/${dir}/expected.html`),
"utf-8" 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;
}
}
Loading…
Cancel
Save