@diplodoc/cli-tests 5.21.0 → 5.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/e2e/empty-presets.spec.ts +32 -0
- package/e2e/themer.test.ts +174 -0
- package/mocks/empty-presets/input/.yfm +1 -0
- package/mocks/empty-presets/input/index.md +3 -0
- package/mocks/empty-presets/input/presets.yaml +3 -0
- package/mocks/empty-presets/input/subfolder/presets.yaml +3 -0
- package/mocks/empty-presets/input/subfolder/subpage.md +3 -0
- package/mocks/empty-presets/input/subfolder/toc.yaml +4 -0
- package/mocks/empty-presets/input/toc.yaml +4 -0
- package/mocks/themer/test1/input/.yfm +3 -0
- package/mocks/themer/test1/input/_assets/style/custom.css +3 -0
- package/mocks/themer/test1/input/index.md +1 -0
- package/mocks/themer/test1/input/theme.yaml +14 -0
- package/mocks/themer/test1/input/toc.yaml +3 -0
- package/mocks/themer/test2/input/index.md +1 -0
- package/mocks/themer/test2/input/theme.yaml +8 -0
- package/mocks/themer/test2/input/toc.yaml +3 -0
- package/mocks/themer/test3/input/index.md +1 -0
- package/mocks/themer/test3/input/toc.yaml +3 -0
- package/mocks/themer/test4/input/index.md +1 -0
- package/mocks/themer/test4/input/theme.yaml +3 -0
- package/mocks/themer/test4/input/toc.yaml +3 -0
- package/package.json +1 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {describe, expect, test} from 'vitest';
|
|
2
|
+
import {existsSync, readFileSync} from 'node:fs';
|
|
3
|
+
import {resolve} from 'node:path';
|
|
4
|
+
|
|
5
|
+
import {TestAdapter, getTestPaths} from '../fixtures';
|
|
6
|
+
|
|
7
|
+
describe('Empty presets.yaml handling', () => {
|
|
8
|
+
test('should not create empty presets.yaml files in md output format when no variables are used', async () => {
|
|
9
|
+
const {inputPath, outputPath} = getTestPaths('mocks/empty-presets');
|
|
10
|
+
|
|
11
|
+
// Test with --output-format=md and disabled templating
|
|
12
|
+
await TestAdapter.testBuildPass(inputPath, outputPath, {
|
|
13
|
+
md2md: true,
|
|
14
|
+
args: '-f md --no-template',
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// Check that presets.yaml file was NOT created in the output
|
|
18
|
+
const presetsPath = resolve(outputPath, 'presets.yaml');
|
|
19
|
+
expect(existsSync(presetsPath)).toBe(false);
|
|
20
|
+
|
|
21
|
+
// Check that subfolder presets.yaml file was NOT created in the output
|
|
22
|
+
const subfolderPresetsPath = resolve(outputPath, 'subfolder/presets.yaml');
|
|
23
|
+
expect(existsSync(subfolderPresetsPath)).toBe(false);
|
|
24
|
+
|
|
25
|
+
// Verify that the markdown files were still processed correctly
|
|
26
|
+
const indexContent = readFileSync(resolve(outputPath, 'index.md'), 'utf8');
|
|
27
|
+
expect(indexContent).toContain('Test Page');
|
|
28
|
+
|
|
29
|
+
const subpageContent = readFileSync(resolve(outputPath, 'subfolder/subpage.md'), 'utf8');
|
|
30
|
+
expect(subpageContent).toContain('Sub Page');
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import {describe, expect, it} from 'vitest';
|
|
2
|
+
import {existsSync} from 'node:fs';
|
|
3
|
+
import {readFile} from 'node:fs/promises';
|
|
4
|
+
import {join} from 'node:path';
|
|
5
|
+
|
|
6
|
+
import {TestAdapter, getTestPaths} from '../fixtures';
|
|
7
|
+
|
|
8
|
+
describe('Build themer feature', () => {
|
|
9
|
+
it.each([
|
|
10
|
+
['md2md', true, false],
|
|
11
|
+
['md2html', false, true],
|
|
12
|
+
])('generates theme.css from theme.yaml (%s)', async (_, md2md, md2html) => {
|
|
13
|
+
const {inputPath, outputPath} = getTestPaths('mocks/themer/test1');
|
|
14
|
+
|
|
15
|
+
await TestAdapter.testBuildPass(inputPath, outputPath, {
|
|
16
|
+
md2md,
|
|
17
|
+
md2html,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const cssPath = join(outputPath, '_assets', 'style', 'theme.css');
|
|
21
|
+
const css = await readFile(cssPath, 'utf8');
|
|
22
|
+
|
|
23
|
+
expect(css).toContain('--g-color-base-brand: var(--g-color-private-base-brand-550-solid);');
|
|
24
|
+
expect(css).toContain('--g-color-private-base-brand-550-solid: rgb(255 0 0);');
|
|
25
|
+
expect(css).toContain('--g-color-private-base-brand-600-solid: rgb(255 25 25);');
|
|
26
|
+
expect(css).toContain('--yfm-color-link: green;');
|
|
27
|
+
expect(css).toContain('--yfm-color-link: blue;');
|
|
28
|
+
expect(css).toContain('--g-color-base-selection: rgb(255 0 255);');
|
|
29
|
+
expect(css).toContain('--g-color-base-background: hsl(60 100% 50%);');
|
|
30
|
+
expect(css).toContain('--g-color-base-background: rgba(255, 165, 0, 1);');
|
|
31
|
+
expect(css).toContain('--g-color-base-selection: hsla(0 0% 50% / 1);');
|
|
32
|
+
expect(css).toContain('--yfm-color-note-info-background: red;');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it.each([
|
|
36
|
+
['md2md', true, false],
|
|
37
|
+
['md2html', false, true],
|
|
38
|
+
])('generates theme.css with theme.yaml and flag value (%s)', async (_, md2md, md2html) => {
|
|
39
|
+
const {inputPath, outputPath} = getTestPaths('mocks/themer/test1');
|
|
40
|
+
|
|
41
|
+
await TestAdapter.testBuildPass(inputPath, outputPath, {
|
|
42
|
+
md2md,
|
|
43
|
+
md2html,
|
|
44
|
+
args: '--theme pink',
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const cssPath = join(outputPath, '_assets', 'style', 'theme.css');
|
|
48
|
+
const css = await readFile(cssPath, 'utf8');
|
|
49
|
+
|
|
50
|
+
expect(css).toContain('--g-color-base-brand: var(--g-color-private-base-brand-550-solid);');
|
|
51
|
+
expect(css).toContain('--g-color-private-base-brand-550-solid: rgb(255 192 203);');
|
|
52
|
+
expect(css).toContain('--g-color-private-base-brand-600-solid: rgb(234 177 188);');
|
|
53
|
+
expect(css).toContain('--yfm-color-link: green;');
|
|
54
|
+
expect(css).toContain('--yfm-color-link: blue;');
|
|
55
|
+
expect(css).toContain('--g-color-base-selection: rgb(255 0 255);');
|
|
56
|
+
expect(css).toContain('--g-color-base-background: hsl(60 100% 50%);');
|
|
57
|
+
expect(css).toContain('--g-color-base-background: rgba(255, 165, 0, 1);');
|
|
58
|
+
expect(css).toContain('--g-color-base-selection: hsla(0 0% 50% / 1);');
|
|
59
|
+
expect(css).toContain('--yfm-color-note-info-background: red;');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it.each([
|
|
63
|
+
['md2md', true, false],
|
|
64
|
+
['md2html', false, true],
|
|
65
|
+
])('generates theme.css from flag value only (%s)', async (_, md2md, md2html) => {
|
|
66
|
+
const {inputPath, outputPath} = getTestPaths('mocks/themer/test3');
|
|
67
|
+
|
|
68
|
+
await TestAdapter.testBuildPass(inputPath, outputPath, {
|
|
69
|
+
md2md,
|
|
70
|
+
md2html,
|
|
71
|
+
args: '--theme pink',
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const cssPath = join(outputPath, '_assets', 'style', 'theme.css');
|
|
75
|
+
const css = await readFile(cssPath, 'utf8');
|
|
76
|
+
|
|
77
|
+
expect(existsSync(join(inputPath, 'theme.yaml'))).toBe(false);
|
|
78
|
+
expect(css).toContain('--g-color-base-brand: var(--g-color-private-base-brand-550-solid);');
|
|
79
|
+
expect(css).toContain('--g-color-private-base-brand-550-solid: rgb(255 192 203);');
|
|
80
|
+
expect(css).toContain('--g-color-private-base-brand-600-solid: rgb(234 177 188);');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('custom styles override theme colors', async () => {
|
|
84
|
+
const {inputPath, outputPath} = getTestPaths('mocks/themer/test1');
|
|
85
|
+
|
|
86
|
+
await TestAdapter.testBuildPass(inputPath, outputPath, {
|
|
87
|
+
md2md: false,
|
|
88
|
+
md2html: true,
|
|
89
|
+
args: '--allow-custom-resources true',
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const htmlPath = join(outputPath, 'index.html');
|
|
93
|
+
const html = await readFile(htmlPath, 'utf8');
|
|
94
|
+
|
|
95
|
+
const themeIndex = html.indexOf('_assets/style/theme.css');
|
|
96
|
+
const customIndex = html.indexOf('_assets/style/custom.css');
|
|
97
|
+
expect(customIndex).toBeGreaterThan(themeIndex);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('does not generates theme.css if not theme.yaml and flag', async () => {
|
|
101
|
+
const {inputPath, outputPath} = getTestPaths('mocks/themer/test3');
|
|
102
|
+
|
|
103
|
+
await TestAdapter.testBuildPass(inputPath, outputPath, {
|
|
104
|
+
md2md: false,
|
|
105
|
+
md2html: true,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const htmlPath = join(outputPath, 'index.html');
|
|
109
|
+
const html = await readFile(htmlPath, 'utf8');
|
|
110
|
+
|
|
111
|
+
const themeIndex = html.indexOf('_assets/style/theme.css');
|
|
112
|
+
expect(themeIndex).toBe(-1);
|
|
113
|
+
|
|
114
|
+
const themePath = join(outputPath, '_assets', 'style', 'theme.css');
|
|
115
|
+
expect(existsSync(themePath)).toBe(false);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it.each([
|
|
119
|
+
['md2md', 'md'],
|
|
120
|
+
['md2html', 'html'],
|
|
121
|
+
])('includes errors for invalid colors from theme.yaml and flag (%s)', async (_, format) => {
|
|
122
|
+
const {inputPath, outputPath} = getTestPaths('mocks/themer/test2');
|
|
123
|
+
|
|
124
|
+
const report = await TestAdapter.build.run(inputPath, outputPath, [
|
|
125
|
+
'-f',
|
|
126
|
+
format,
|
|
127
|
+
'--theme',
|
|
128
|
+
'pinkk',
|
|
129
|
+
]);
|
|
130
|
+
|
|
131
|
+
expect(report.code).toBe(1);
|
|
132
|
+
expect(report.errors.includes('ERR Invalid color: "pinkk"')).toBe(true);
|
|
133
|
+
expect(report.errors.includes('ERR Invalid color: "redd"')).toBe(true);
|
|
134
|
+
expect(report.errors.includes('ERR /dark/link must be string')).toBe(true);
|
|
135
|
+
expect(report.errors.includes('ERR Invalid color: "5"')).toBe(true);
|
|
136
|
+
expect(report.errors.includes('ERR Invalid color: ""')).toBe(true);
|
|
137
|
+
expect(report.errors.includes('ERR Invalid color: " "')).toBe(true);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it.each([
|
|
141
|
+
['md2md', 'md'],
|
|
142
|
+
['md2html', 'html'],
|
|
143
|
+
])('warns about unknown color keys in theme.yaml (%s)', async (_, format) => {
|
|
144
|
+
const {inputPath, outputPath} = getTestPaths('mocks/themer/test1');
|
|
145
|
+
|
|
146
|
+
const report = await TestAdapter.build.run(inputPath, outputPath, ['-f', format]);
|
|
147
|
+
|
|
148
|
+
expect(report.code).toBe(0);
|
|
149
|
+
expect(
|
|
150
|
+
report.warns.includes(
|
|
151
|
+
'WARN File theme.yaml must NOT have additional properties "base-brandd"',
|
|
152
|
+
),
|
|
153
|
+
).toBe(true);
|
|
154
|
+
expect(
|
|
155
|
+
report.warns.includes('WARN /dark must NOT have additional properties "unknown-color"'),
|
|
156
|
+
).toBe(true);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it.each([
|
|
160
|
+
['md2md', 'md'],
|
|
161
|
+
['md2html', 'html'],
|
|
162
|
+
])('includes errors for invalid syntax in theme.yaml (%s)', async (_, format) => {
|
|
163
|
+
const {inputPath, outputPath} = getTestPaths('mocks/themer/test4');
|
|
164
|
+
|
|
165
|
+
const report = await TestAdapter.build.run(inputPath, outputPath, ['-f', format]);
|
|
166
|
+
|
|
167
|
+
expect(report.code).toBe(1);
|
|
168
|
+
expect(
|
|
169
|
+
report.errors.includes(
|
|
170
|
+
'ERR Failed to generate theme: YAMLException: bad indentation of a mapping entry (3:5)',
|
|
171
|
+
),
|
|
172
|
+
).toBe(true);
|
|
173
|
+
});
|
|
174
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
varsPreset: default
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Test for themer
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
base-brand: red
|
|
2
|
+
link: green
|
|
3
|
+
note-info-background: red
|
|
4
|
+
base-brandd: red
|
|
5
|
+
base-selection: rgb(255 0 255)
|
|
6
|
+
|
|
7
|
+
dark:
|
|
8
|
+
link: blue
|
|
9
|
+
unknown-color: blue
|
|
10
|
+
base-background: hsl(60 100% 50%)
|
|
11
|
+
|
|
12
|
+
light:
|
|
13
|
+
base-background: rgba(255, 165, 0, 1)
|
|
14
|
+
base-selection: hsla(0 0% 50% / 1)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Test for themer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Test for themer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Test for themer
|