forked from sveltejs/svelte
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (34 loc) · 1.04 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import assert from "assert";
import * as fs from "fs";
import { svelte } from "../helpers.js";
function tryRequire(file) {
try {
return require(file).default;
} catch (err) {
if (err.code !== "MODULE_NOT_FOUND") throw err;
return null;
}
}
describe("css", () => {
fs.readdirSync("test/css/samples").forEach(dir => {
if (dir[0] === ".") return;
// add .solo to a sample directory name to only run that test
const solo = /\.solo/.test(dir);
if (solo && process.env.CI) {
throw new Error("Forgot to remove `solo: true` from test");
}
(solo ? it.only : it)(dir, () => {
const config = tryRequire(`./samples/${dir}/_config.js`) || {};
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"
);
assert.equal(actual.trim(), expected.trim());
});
});
});