-
Notifications
You must be signed in to change notification settings - Fork 170
/
loaders_vue_test.ts
119 lines (105 loc) · 3.78 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
117
118
119
import { assert, assertEquals } from "std/testing/asserts.ts";
import VueLoader from "../loaders/vue.ts";
Deno.test("[unit] loaders/vue.ts", async (t) => {
await t.step("VueLoader", async () => {
const testVue = `
<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 } = await loader.load("/test.vue", testVue, { isDev: false });
assertEquals(lang, "js");
assert(code.includes(`createElementBlock as _createElementBlock } from "https://esm.sh/vue"`));
assert(code.includes(`setup(__props)`));
assert(code.includes(`const msg = ref("Hello World!")`));
assert(code.includes(`_createElementBlock(_Fragment`));
assert(code.includes(`_createElementVNode("h1"`));
assert(code.includes(`_withDirectives(_createElementVNode("input"`));
assert(code.includes(`__sfc__.__file = "./test.vue"`));
assert(code.includes(`__sfc__.__scopeId = "data-v-`));
assert(inlineCSS?.includes("h1[data-v-"));
assert(inlineCSS?.includes("font-size: 30px;"));
});
await t.step("VueLoader(ts)", async () => {
const testVue = `
<script setup lang="ts">
let x: string | number = 1
</script>
<template>
<p>{{ (x as number).toFixed(2) }}</p>
</template>
`;
const loader = new VueLoader();
const { lang, code } = await loader.load("/test.vue", testVue, { isDev: false });
assertEquals(lang, "ts");
assert(code.includes(`createElementBlock as _createElementBlock } from "https://esm.sh/vue"`));
assert(code.includes(`setup(__props)`));
assert(code.includes(`let x: string | number = 1`));
assert(code.includes(`_createElementBlock("p"`));
assert(code.includes(`__sfc__.__file = "./test.vue"`));
});
await t.step("VueLoader(hmr)", async () => {
const testVue = `
<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", testVue, { isDev: true });
assert(code.includes(`createElementBlock as _createElementBlock } from "https://esm.sh/vue"`));
assert(code.includes(`__sfc__.__hmrId = "`));
assert(code.includes(`__sfc__.__scriptHash = "`));
assert(code.includes(`__sfc__.render = function render(`));
});
await t.step("VueLoader(ssr)", async () => {
const testVue = `
<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", testVue, { ssr: true });
assert(code.includes(`ssrInterpolate as _ssrInterpolate } from "https://esm.sh/@vue/server-renderer"`));
assert(code.includes(`__ssrInlineRender: true,`));
assert(code.includes(`setup(__props)`));
assert(code.includes(`const msg = ref("Hello World!")`));
assert(code.includes(`<h1`));
assert(code.includes(`<input`));
assert(code.includes(` data-v-`));
assert(code.includes(`__file = "./test.vue"`));
assert(code.includes(`__scopeId = "data-v-`));
assert(inlineCSS?.includes("h1[data-v-"));
assert(inlineCSS?.includes("font-size: 30px;"));
});
});