-
Notifications
You must be signed in to change notification settings - Fork 169
/
loaders_vue_test.ts
116 lines (104 loc) · 3.69 KB
/
loaders_vue_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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import { join } from "std/path/mod.ts";
import { assertEquals } from "std/testing/asserts.ts";
import VueLoader from "../loaders/vue.ts";
Deno.test("loaders/vue.ts: VueLoader", async () => {
const dir = await Deno.makeTempDir();
Deno.chdir(dir);
await Deno.writeTextFile(
join(dir, "test.vue"),
`
<script setup>
import { ref } from "https://esm.sh/vue@3"
const msg = ref("Hello World!")
</script>
<template>
<h1>{{ msg }}</h1>
<input v-model="msg">
</template>
<style scoped>
h1 {
font-size: 30px;
}
</style>
`,
);
const loader = new VueLoader();
const { lang, code, inlineCSS, atomicCSS } = await loader.load("/test.vue", { isDev: false });
assertEquals(loader.test("/app.vue"), true);
assertEquals(loader.test("/app.jsx"), false);
assertEquals(lang, "js");
assertEquals(code.includes(`createElementBlock as _createElementBlock } from "https://esm.sh/vue"`), true);
assertEquals(code.includes(`setup(__props)`), true);
assertEquals(code.includes(`const msg = ref("Hello World!")`), true);
assertEquals(code.includes(`_createElementBlock(_Fragment`), true);
assertEquals(code.includes(`_createElementVNode("h1"`), true);
assertEquals(code.includes(`_withDirectives(_createElementVNode("input"`), true);
assertEquals(code.includes(`__sfc__.__file = "./test.vue"`), true);
assertEquals(code.includes(`__sfc__.__scopeId = "data-v-`), true);
assertEquals(inlineCSS?.includes("h1[data-v-"), true);
assertEquals(inlineCSS?.includes("font-size: 30px;"), true);
assertEquals(atomicCSS, true);
});
Deno.test("loaders/vue.ts: VueLoader.hmr", async () => {
const dir = await Deno.makeTempDir();
Deno.chdir(dir);
await Deno.writeTextFile(
join(dir, "test.vue"),
`
<script setup>
import { ref } from "https://esm.sh/vue@3"
const msg = ref("Hello World!")
</script>
<template>
<h1>{{ msg }}</h1>
<input v-model="msg">
</template>
<style scoped>
h1 {
font-size: 30px;
}
</style>
`,
);
const loader = new VueLoader();
const { code } = await loader.load("/test.vue", { isDev: true });
assertEquals(code.includes(`createElementBlock as _createElementBlock } from "https://esm.sh/vue"`), true);
assertEquals(code.includes(`__sfc__.__hmrId = "`), true);
assertEquals(code.includes(`__sfc__.__scriptHash = "`), true);
assertEquals(code.includes(`__sfc__.render = function render(`), true);
});
Deno.test("loaders/vue.ts: VueLoader.ssr", async () => {
const dir = await Deno.makeTempDir();
Deno.chdir(dir);
await Deno.writeTextFile(
join(dir, "test.vue"),
`
<script setup>
import { ref } from "https://esm.sh/vue@3"
const msg = ref("Hello World!")
</script>
<template>
<h1>{{ msg }}</h1>
<input v-model="msg">
</template>
<style scoped>
h1 {
font-size: 30px;
}
</style>
`,
);
const loader = new VueLoader();
const { code, inlineCSS } = await loader.load("/test.vue", { ssr: true });
assertEquals(code.includes(`ssrInterpolate as _ssrInterpolate } from "https://esm.sh/@vue/server-renderer"`), true);
assertEquals(code.includes(`__ssrInlineRender: true,`), true);
assertEquals(code.includes(`setup(__props)`), true);
assertEquals(code.includes(`const msg = ref("Hello World!")`), true);
assertEquals(code.includes(`<h1`), true);
assertEquals(code.includes(`<input`), true);
assertEquals(code.includes(` data-v-`), true);
assertEquals(code.includes(`__file = "./test.vue"`), true);
assertEquals(code.includes(`__scopeId = "data-v-`), true);
assertEquals(inlineCSS?.includes("h1[data-v-"), true);
assertEquals(inlineCSS?.includes("font-size: 30px;"), true);
});