-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ts
60 lines (55 loc) · 1.12 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
import { rewrite } from "./code";
import minify from "html-minifier"
const source = `
<template>
<div>
<span>
<portal name="a">
<content />
</portal>
<portal name="b" title="B title" />
<portal name="c" />
</span>
<card portal="b"><h1>\${title}</h1></card>
<card portal="a"><h1>\${content}</h1></card>
<card portal="c"><h1>C title</h1></card>
<card portal="d">test</card>
</div>
</template>
<script>
</script>
`
const expected = `
<template>
<div>
<span>
<card portal="a">
<h1>
<content/>
</h1>
</card>
<card portal="b">
<h1>B title</h1>
</card>
<card portal="c">
<h1>C title</h1>
</card>
</span>
<card portal="d">test</card>
</div>
</template>
<script>
</script>
`
function lin(text: string) {
return minify.minify(text, {
collapseWhitespace: true
});
}
if (lin(expected) != lin(rewrite(source))) {
console.log(lin(expected));
console.log(lin(rewrite(source)));
throw new Error("Test failed")
} else {
console.log("Test passed")
}