deno.land / x / lume@v2.1.4 / tests / core / processors.test.ts

processors.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
import { assertEquals as equals } from "../../deps/assert.ts";import Processors from "../../core/processors.ts";import { Page } from "../../core/file.ts";
Deno.test("Processors", async (t) => { const processors = new Processors();
equals(processors.processors.size, 0);
await t.step("Add processors", () => { const ext = [".foo"]; const fn = (pages: Page[]) => { pages.forEach((page) => { const content = page.content as string; page.content = content.toUpperCase(); }); };
processors.set(ext, fn);
equals(processors.processors.size, 1); const entry = Array.from(processors.processors)[0]; equals(entry[0], fn); equals(entry[1], ext);
const asterisk = (pages: Page[]) => { pages.forEach((page) => { const content = page.content as string; page.content = content + "*"; }); };
processors.set("*", asterisk);
equals(processors.processors.size, 2); });
await t.step({ name: "Run processors", ignore: true, fn: async () => { const page1 = new Page({ path: "file1", ext: ".foo", }); page1.content = "content page 1";
const page2 = new Page({ path: "file2", ext: ".bar", }); page2.content = "content page 2";
const page3 = new Page({ path: "file2", ext: ".bar", }); page3.data.url = "file2.foo"; page3.content = "content page 3";
const pages = [page1, page2, page3]; await processors.run(pages);
equals(page1.content, "CONTENT PAGE 1*"); equals(page2.content, "content page 2*"); equals(page3.content, "CONTENT PAGE 3*"); }, });});
lume

Version Info

Tagged at
7 months ago