-
-
Notifications
You must be signed in to change notification settings - Fork 507
/
Copy pathEleventyAddGlobalDataTest.js
118 lines (99 loc) · 3.45 KB
/
EleventyAddGlobalDataTest.js
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 test from "ava";
import Eleventy from "../src/Eleventy.js";
test("Eleventy addGlobalData should run once", async (t) => {
let count = 0;
let elev = new Eleventy("./test/stubs-addglobaldata/", "./test/stubs-addglobaldata/_site", {
config: function (eleventyConfig) {
eleventyConfig.addGlobalData("count", () => {
count++;
return count;
});
},
});
let results = await elev.toJSON();
t.is(count, 1);
});
test("Eleventy addGlobalData shouldn’t run if no input templates match!", async (t) => {
let count = 0;
let elev = new Eleventy(
"./test/stubs-addglobaldata-noop/",
"./test/stubs-addglobaldata-noop/_site",
{
config: function (eleventyConfig) {
eleventyConfig.addGlobalData("count", () => {
count++;
return count;
});
},
}
);
let results = await elev.toJSON();
t.is(count, 0);
});
test("Eleventy addGlobalData can feed layouts to populate data cascade with layout data, issue #1245", async (t) => {
let elev = new Eleventy("./test/stubs-2145/", "./test/stubs-2145/_site", {
config: function (eleventyConfig) {
eleventyConfig.addGlobalData("layout", () => "layout.njk");
eleventyConfig.dataFilterSelectors.add("LayoutData");
},
});
let [result] = await elev.toJSON();
t.deepEqual(result.data, { LayoutData: 123 });
t.is(result.content.trim(), "FromLayoutlayout.njk");
});
test("Eleventy addGlobalData merge data #3389", async (t) => {
let elev = new Eleventy("./test/stubs-virtual/", undefined, {
config: function (eleventyConfig) {
eleventyConfig.addGlobalData("eleventyComputed", {
testing(data) {
return `testing:${data.page.url}`;
}
});
eleventyConfig.addGlobalData("eleventyComputed", {
other(data) {
return `other:${data.page.url}`;
}
});
eleventyConfig.addTemplate("computed.njk", "{{ testing }}|{{ other }}", {})
},
});
let results = await elev.toJSON();
t.is(results.length, 1);
t.is(results[0].content, "testing:/computed/|other:/computed/");
});
test("Eleventy addGlobalData merge data #3389 lodash set", async (t) => {
let elev = new Eleventy("./test/stubs-virtual/", undefined, {
config: function (eleventyConfig) {
eleventyConfig.addGlobalData("eleventyComputed.testing", () => {
return (data) => {
return `testing:${data.page.url}`;
}
});
eleventyConfig.addGlobalData("eleventyComputed.other", () => {
return (data) => {
return `other:${data.page.url}`;
}
});
eleventyConfig.addTemplate("computed.njk", "{{ testing }}|{{ other }}", {})
},
});
let results = await elev.toJSON();
t.is(results.length, 1);
t.is(results[0].content, "testing:/computed/|other:/computed/");
});
test.skip("Eleventy addGlobalData merge data #3389 no nested function", async (t) => {
let elev = new Eleventy("./test/stubs-virtual/", undefined, {
config: function (eleventyConfig) {
eleventyConfig.addGlobalData("eleventyComputed.testing", (data) => {
return `testing:${data.page.url}`;
});
eleventyConfig.addGlobalData("eleventyComputed.other", (data) => {
return `other:${data.page.url}`;
});
eleventyConfig.addTemplate("computed.njk", "{{ testing }}|{{ other }}", {})
},
});
let results = await elev.toJSON();
t.is(results.length, 1);
t.is(results[0].content, "testing:/computed/|other:/computed/");
});