-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.ts
117 lines (105 loc) · 2.79 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
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
import {
assertEquals,
assertStringIncludes,
} from "https://deno.land/[email protected]/testing/asserts.ts";
import { transform, transformCSS } from "./mod.ts";
Deno.test("aleph compiler", async (t) => {
await t.step("transform css", async () => {
const ret = await transformCSS(
"./app.css",
`@custom-media --modern (color), (hover);
.foo {
background: yellow;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
border-radius: 2px;
-webkit-transition: background 200ms;
-moz-transition: background 200ms;
transition: background 200ms;
&.bar {
color: green;
}
}
@media (--modern) and (width > 1024px) {
.a {
color: green;
}
}`,
{
minify: true,
targets: {
chrome: 95,
},
drafts: {
nesting: true,
customMedia: true,
},
},
);
assertEquals(
ret.code,
`.foo{background:#ff0;border-radius:2px;transition:background .2s}.foo.bar{color:green}@media ((color) or (hover)) and (min-width:1024px){.a{color:green}}`,
);
});
await t.step("transform ts", async () => {
const ret = await transform(
"./mod.ts",
await Deno.readTextFile("./mod.ts"),
);
assertStringIncludes(ret.code, `function transform(`);
});
await t.step("transform jsx", async () => {
const ret = await transform(
"./app.jsx",
`
import React from "https://esm.sh/react";
export default function App() {
return <h1>Hello world!</h1>
}
`,
);
assertStringIncludes(ret.code, `React.createElement("h1"`);
});
await t.step("transform jsx (preserve)", async () => {
const ret = await transform(
"./app.jsx",
`
export default function App() {
return <h1>Hello world!</h1>
}
`,
{
jsx: "preserve",
},
);
assertStringIncludes(ret.code, `<h1>Hello world!</h1>`);
});
await t.step("transform jsx (automatic)", async () => {
const ret = await transform(
"./app.jsx",
`
export default function App() {
return <h1>Hello world!</h1>
}
`,
{
jsx: "automatic",
jsxImportSource: "https://esm.sh/react",
resolveRemoteModule: true,
},
);
assertStringIncludes(
ret.code,
`import { jsx as _jsx } from "/-/esm.sh/react/jsx-runtime"`,
);
assertStringIncludes(ret.code, `_jsx("h1"`);
});
await t.step("transform large js", async () => {
const ret = await transform(
"./gsi-client.js",
await Deno.readTextFile("./testdata/gsi-client.js"),
{ minify: { compress: true } },
);
assertStringIncludes(ret.code, `this.default_gsi`);
});
});