forked from sveltejs/svelte
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
71 lines (61 loc) · 1.66 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import assert from "assert";
import * as fs from "fs";
import * as path from "path";
import { rollup } from "rollup";
import { svelte } from "../helpers.js";
describe("js", () => {
fs.readdirSync("test/js/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, () => {
dir = path.resolve("test/js/samples", dir);
const input = fs
.readFileSync(`${dir}/input.html`, "utf-8")
.replace(/\s+$/, "");
let actual;
try {
actual = svelte.compile(input, {
shared: true
}).code;
} catch (err) {
console.log(err.frame);
throw err;
}
fs.writeFileSync(`${dir}/_actual.js`, actual);
const expected = fs.readFileSync(`${dir}/expected.js`, "utf-8");
const expectedBundle = fs.readFileSync(
`${dir}/expected-bundle.js`,
"utf-8"
);
return rollup({
entry: `${dir}/_actual.js`,
plugins: [
{
resolveId(importee, importer) {
if (!importer) return importee;
if (importee === "svelte/shared.js")
return path.resolve("shared.js");
return null;
}
}
]
}).then(bundle => {
return bundle.generate({ format: "es" })
}).then(({ code }) => {
fs.writeFileSync(`${dir}/_actual-bundle.js`, code);
assert.equal(
actual.trim().replace(/^\s+$/gm, ""),
expected.trim().replace(/^\s+$/gm, "")
);
assert.equal(
code.trim().replace(/^\s+$/gm, ""),
expectedBundle.trim().replace(/^\s+$/gm, "")
);
});
});
});
});