-
-
Notifications
You must be signed in to change notification settings - Fork 75
/
bundler.test.ts
64 lines (52 loc) 路 1.64 KB
/
bundler.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
import { assert, assertStrictEquals as equals } from "../deps/assert.ts";
import { build, getSite, testPage } from "./utils.ts";
import bundler from "../plugins/bundler.ts";
Deno.test("bundler plugin", async () => {
const site = getSite({
src: "bundler",
});
site.ignore("modules");
site.use(bundler({
extensions: [".ts", ".tsx"],
options: {
bundle: "module",
},
}));
await build(site);
const { formats } = site;
// Register the loader extensions
assert(formats.has(".ts"));
assert(formats.has(".tsx"));
equals(formats.get(".ts")?.pageType, "asset");
equals(formats.get(".tsx")?.pageType, "asset");
testPage(site, "/main", (page) => {
equals(page.dest.path, "/main");
equals(page.dest.ext, ".js");
const content = page.content as string;
assert(content.includes('.createElement("h1", null, salute1)'));
});
});
Deno.test("bundler plugin (not bundle)", async () => {
const site = getSite({
src: "bundler",
});
site.use(bundler({
extensions: [".ts", ".tsx"],
}));
await build(site);
// Register the loader extensions
testPage(site, "/main", (page) => {
equals(page.dest.path, "/main");
equals(page.dest.ext, ".js");
const content = page.content as string;
assert(content.includes('import Title from "./modules/title.js";'));
});
testPage(site, "/modules/utils", (page) => {
const content = page.content as string;
assert(content.includes("return `Hello, ${name}`;"));
});
testPage(site, "/modules/title", (page) => {
const content = page.content as string;
assert(content.includes('React.createElement("h1", null, salute),'));
});
});