-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ts
80 lines (68 loc) · 1.91 KB
/
test.ts
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
72
73
74
75
76
77
78
79
80
import * as path from "https://deno.land/[email protected]/path/mod.ts";
import { exists } from "https://deno.land/[email protected]/fs/mod.ts";
import {
assert,
assertEquals,
} from "https://deno.land/[email protected]/testing/asserts.ts";
import { compile, compileToString } from "./compiler.ts";
const DEFAULT_ENTRY = "./fixtures/Main.elm";
const TEST_OUTPUT_DIR = "./tmp";
const TEST_OUTPUT_FILE = path.join(TEST_OUTPUT_DIR, "test.elm.js");
Deno.test("basic compile", async function (): Promise<void> {
const defaultPath = "./index.html";
await compile(DEFAULT_ENTRY);
const fileExists = await exists(defaultPath);
try {
assert(fileExists, "Compiles to basic index.html");
await Deno.remove(defaultPath);
} catch (err) {
throw err;
}
});
Deno.test("fails with bad source", async function () {
try {
await compile("");
} catch (err) {
assertEquals(
err.indexOf("Exception thrown when attempting to run Elm compiler"),
0
);
}
});
Deno.test("compiles with outut", async function (): Promise<void> {
await compile(DEFAULT_ENTRY, {
output: TEST_OUTPUT_FILE,
});
const fileExists = await exists(TEST_OUTPUT_FILE);
try {
assert(fileExists);
await cleanup();
} catch (err) {
throw err;
}
});
Deno.test(
"Doesn't compile with 'optimize' and 'Debug.funcs' in the source code",
async function () {
try {
await compile(DEFAULT_ENTRY, {
output: TEST_OUTPUT_FILE,
mode: "optimize",
});
console.log("no err");
} catch (err) {
assertEquals(
err.indexOf("Exception thrown when attempting to run Elm compiler"),
0
);
}
}
);
Deno.test("compiles to a string", async function () {
const result = await compileToString(DEFAULT_ENTRY);
const [firstLine] = result.split("\n");
assert(firstLine === "(function(scope){");
});
async function cleanup() {
await Deno.remove(TEST_OUTPUT_DIR, { recursive: true });
}