-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
41 lines (32 loc) · 1.14 KB
/
test.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 { preprocess } from "svelte/compiler";
import { ifProcessor } from "./src/index.js";
import fs from "fs";
import path from "path";
const testsFolder = "tests";
const tests = fs.readdirSync(path.resolve(testsFolder));
let allCount = tests.length;
let successCount = 0;
await Promise.all(
tests.map(async (test) => {
const source = fs.readFileSync(
path.resolve(testsFolder, test, "file.svelte"),
"utf-8"
);
const output = await preprocess(source, ifProcessor());
const expected = fs.readFileSync(
path.resolve(testsFolder, test, "output.svelte"),
"utf-8"
);
fs.writeFileSync(
path.resolve(testsFolder, test, "last-run.svelte"),
output.code
);
if (output.code === expected) successCount += 1;
})
);
console.log("---------------------------------------");
console.log("| |");
console.log(`| Tests finished: ${successCount} / ${allCount} |`);
console.log(`| ${allCount - successCount} tests Failed! |`);
console.log("| |");
console.log("---------------------------------------");