-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.test.ts
112 lines (91 loc) · 3.8 KB
/
main.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
import { EleventyTest } from './_eleventy-test-instance.js';
import { describe, test } from 'vitest';
const testInstance = new EleventyTest('./tests/stubs/');
await testInstance.rebuild();
describe('Can print Eleventy data', { concurrent: true }, () => {
const matrix = [
['Static data', 'static'],
['Computed data', 'computed'],
];
test.for(matrix)('%s', async ([_label, slug], { expect }) => {
const result = testInstance.getBuildResultForUrl(`/data-handling/${slug}/`);
expect(result?.content).toMatchSnapshot(`data-${slug}`);
});
});
describe("Can include from Eleventy's `includes` directory", { concurrent: true }, () => {
const matrix = [
['Without data', 'without-data'],
['With data', 'with-data'],
];
test.for(matrix)('%s', async ([_label, slug], { expect }) => {
const result = testInstance.getBuildResultForUrl(`/include-handling/${slug}/`);
expect(result?.content).toMatchSnapshot(`includes-${slug}`);
});
});
describe("Can use layouts from Eleventy's `layouts` directory", { concurrent: true }, () => {
const matrix = [
['Example 1', 'example-1'],
['Example 2', 'example-2'],
];
test.for(matrix)('%s', async ([_label, slug], { expect }) => {
const result = testInstance.getBuildResultForUrl(`/layout-handling/${slug}/`);
expect(result?.content).toMatchSnapshot(`layouts-${slug}`);
});
});
describe('Can process Eleventy permalink keys', { concurrent: true }, () => {
test('render a page at a nested permalink', async ({ expect }) => {
const result = testInstance.getBuildResultForUrl('/page/at/nested/permalink/');
expect(result?.content).toMatchSnapshot('permalink-nested');
});
test('render a page at root url', async ({ expect }) => {
const result = testInstance.getBuildResultForUrl('/');
expect(result?.content).toMatchSnapshot('permalink-root');
});
test('render a page at a dynamic permalink', async ({ expect }) => {
const result = testInstance.getBuildResultForUrl('/directory-data-test-page.html');
expect(result?.content).toBeDefined();
});
test('render a page at a dynamic permalink (js)', async ({ expect }) => {
const result = testInstance.getBuildResultForUrl('/directory-data-test-page-js.html');
expect(result?.content).toBeDefined();
});
test('skips rendering a file', async ({ expect }) => {
const skipped = testInstance.getPageWithInput('\nLeave me out of this.\n');
expect(skipped?.url).toBe(false);
});
});
describe('Can run Vento filters', { concurrent: true }, () => {
const matrix = [
['Built-in methods', 'built-in'],
['Chained methods', 'complex'],
['Custom filter', 'custom'],
];
test.for(matrix)('%s', async ([_label, slug], { expect }) => {
const result = testInstance.getBuildResultForUrl(`/filters/${slug}/`);
expect(result?.content).toMatchSnapshot(`filters-${slug}`);
});
test('use context data (this.page)', async ({ expect }) => {
const result = [
testInstance.getBuildResultForUrl('/filters/with-this-example-1/'),
testInstance.getBuildResultForUrl('/filters/with-this-example-2/'),
].every((result) => result?.content === 'true');
expect(result).toBe(true);
});
test('use context env (this.env)', async ({ expect }) => {
const result = testInstance.getBuildResultForUrl('/filters/with-env-compile/');
expect(result?.content).toBe('4');
});
});
describe('Can run Eleventy shortcodes as Vento tags', { concurrent: true }, () => {
const matrix = [
['single shortcodes', 'single'],
['single shortcodes with filters', 'single-filters'],
['paired shortcodes', 'paired'],
['paired shortcodes with filters', 'paired-filters'],
['nested shortcodes with adjacent content', 'paired-nested'],
];
test.for(matrix)('run %s', async ([_label, slug], { expect }) => {
const result = testInstance.getBuildResultForUrl(`/shortcodes/${slug}/`);
expect(result?.content).toMatchSnapshot(`shortcodes-${slug}`);
});
});