@diplodoc/cli-tests 5.16.2 → 5.16.4
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/vars-ignore.test.ts +168 -0
- package/mocks/nested-docs/input/.yfm +1 -0
- package/mocks/nested-docs/input/.yfm-subdoc +5 -0
- package/mocks/nested-docs/input/index.md +5 -0
- package/mocks/nested-docs/input/presets.yaml +3 -0
- package/mocks/nested-docs/input/subdoc/.yfm +0 -0
- package/mocks/nested-docs/input/subdoc/index.md +5 -0
- package/mocks/nested-docs/input/subdoc/presets.yaml +3 -0
- package/mocks/nested-docs/input/subdoc/toc.yaml +4 -0
- package/mocks/nested-docs/input/toc.yaml +6 -0
- package/mocks/vars-ignore/input/.yfm +1 -0
- package/mocks/vars-ignore/input/data/data-test.md +4 -0
- package/mocks/vars-ignore/input/data/presets.yaml +3 -0
- package/mocks/vars-ignore/input/data/temp-test.md +4 -0
- package/mocks/vars-ignore/input/ignored/ignored-test.md +4 -0
- package/mocks/vars-ignore/input/ignored/presets.yaml +3 -0
- package/mocks/vars-ignore/input/presets.yaml +3 -0
- package/mocks/vars-ignore/input/test.md +6 -0
- package/mocks/vars-ignore/input/toc.yaml +8 -0
- package/package.json +1 -1
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import {describe, expect, test} from 'vitest';
|
|
2
|
+
import {resolve} from 'node:path';
|
|
3
|
+
import {readFileSync} from 'node:fs';
|
|
4
|
+
|
|
5
|
+
import {TestAdapter, getTestPaths} from '../fixtures';
|
|
6
|
+
|
|
7
|
+
describe('VarsService ignore patterns', () => {
|
|
8
|
+
test('should ignore presets files based on ignore patterns', async () => {
|
|
9
|
+
const {inputPath, outputPath} = getTestPaths('mocks/vars-ignore');
|
|
10
|
+
|
|
11
|
+
// Test with ignore patterns via flags - should ignore ignored/ and data/ folders
|
|
12
|
+
await TestAdapter.testBuildPass(inputPath, outputPath, {
|
|
13
|
+
md2md: true,
|
|
14
|
+
args: '--ignore ignored/ --ignore data/',
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// Check that variables from ignored presets are not resolved
|
|
18
|
+
const outputContent = readFileSync(resolve(outputPath, 'test.md'), 'utf8');
|
|
19
|
+
expect(outputContent).toContain('Root var: rootValue');
|
|
20
|
+
expect(outputContent).toContain('Common var: fromRoot');
|
|
21
|
+
expect(outputContent).toContain('Ignored var: {{ignoredVar}}'); // Should remain unresolved
|
|
22
|
+
expect(outputContent).toContain('Data var: {{dataVar}}'); // Should remain unresolved
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('should load all presets when no ignore patterns specified', async () => {
|
|
26
|
+
const {inputPath, outputPath} = getTestPaths('mocks/vars-ignore');
|
|
27
|
+
|
|
28
|
+
// Test without ignore patterns - should load all presets
|
|
29
|
+
await TestAdapter.testBuildPass(inputPath, outputPath + '-no-ignore', {
|
|
30
|
+
md2md: true,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Check that variables in subdirectories are resolved
|
|
34
|
+
const ignoredContent = readFileSync(
|
|
35
|
+
resolve(outputPath + '-no-ignore', 'ignored/ignored-test.md'),
|
|
36
|
+
'utf8',
|
|
37
|
+
);
|
|
38
|
+
expect(ignoredContent).toContain('Root var: rootValue');
|
|
39
|
+
expect(ignoredContent).toContain('Ignored var: ignoredValue');
|
|
40
|
+
|
|
41
|
+
const dataContent = readFileSync(
|
|
42
|
+
resolve(outputPath + '-no-ignore', 'data/data-test.md'),
|
|
43
|
+
'utf8',
|
|
44
|
+
);
|
|
45
|
+
expect(dataContent).toContain('Root var: rootValue');
|
|
46
|
+
expect(dataContent).toContain('Data var: dataValue');
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('should handle partial ignore patterns', async () => {
|
|
50
|
+
const {inputPath, outputPath} = getTestPaths('mocks/vars-ignore');
|
|
51
|
+
|
|
52
|
+
// Test with partial ignore - should ignore only data/ folder
|
|
53
|
+
await TestAdapter.testBuildPass(inputPath, outputPath + '-partial', {
|
|
54
|
+
md2md: true,
|
|
55
|
+
args: '--ignore data/',
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Check that ignored/ presets are loaded but data/ presets are not
|
|
59
|
+
const ignoredContent = readFileSync(
|
|
60
|
+
resolve(outputPath + '-partial', 'ignored/ignored-test.md'),
|
|
61
|
+
'utf8',
|
|
62
|
+
);
|
|
63
|
+
expect(ignoredContent).toContain('Root var: rootValue');
|
|
64
|
+
expect(ignoredContent).toContain('Ignored var: ignoredValue'); // Should be resolved
|
|
65
|
+
|
|
66
|
+
const dataContent = readFileSync(
|
|
67
|
+
resolve(outputPath + '-partial', 'data/data-test.md'),
|
|
68
|
+
'utf8',
|
|
69
|
+
);
|
|
70
|
+
expect(dataContent).toContain('Root var: rootValue');
|
|
71
|
+
expect(dataContent).toContain('{{dataVar}}'); // Should remain unresolved
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('should handle ignore patterns with trailing slashes normalization', async () => {
|
|
75
|
+
const {inputPath, outputPath} = getTestPaths('mocks/vars-ignore');
|
|
76
|
+
|
|
77
|
+
// Test with various trailing slash patterns
|
|
78
|
+
await TestAdapter.testBuildPass(inputPath, outputPath + '-slashes', {
|
|
79
|
+
md2md: true,
|
|
80
|
+
args: '--ignore ignored// --ignore data/',
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Check that both folders are ignored despite different slash patterns
|
|
84
|
+
const outputContent = readFileSync(resolve(outputPath + '-slashes', 'test.md'), 'utf8');
|
|
85
|
+
expect(outputContent).toContain('Root var: rootValue');
|
|
86
|
+
expect(outputContent).toContain('Common var: fromRoot');
|
|
87
|
+
expect(outputContent).toContain('Ignored var: {{ignoredVar}}'); // Should remain unresolved
|
|
88
|
+
expect(outputContent).toContain('Data var: {{dataVar}}'); // Should remain unresolved
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('should ignore top-level presets when using custom config for nested docs', async () => {
|
|
92
|
+
const {inputPath, outputPath} = getTestPaths('mocks/nested-docs');
|
|
93
|
+
|
|
94
|
+
// Test nested docs scenario - use custom config that ignores everything except subdoc/
|
|
95
|
+
await TestAdapter.testBuildPass(inputPath, outputPath + '-nested', {
|
|
96
|
+
md2md: true,
|
|
97
|
+
args: '--config .yfm-subdoc',
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// Check that subdoc files are processed and variables are resolved correctly
|
|
101
|
+
const subDocContent = readFileSync(
|
|
102
|
+
resolve(outputPath + '-nested', 'subdoc/index.md'),
|
|
103
|
+
'utf8',
|
|
104
|
+
);
|
|
105
|
+
expect(subDocContent).toContain('Sub var: subValue'); // Should be resolved from subdoc presets
|
|
106
|
+
expect(subDocContent).toContain('Common var: fromSub'); // Should use subdoc override
|
|
107
|
+
expect(subDocContent).toContain('{{topLevelVar}}'); // Should remain unresolved (top-level presets ignored)
|
|
108
|
+
|
|
109
|
+
// Verify that top-level presets.yaml was ignored by checking that top-level variables are not available
|
|
110
|
+
expect(subDocContent).not.toContain('topLevelValue');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('should not load any presets when using custom config with disabled template vars', async () => {
|
|
114
|
+
const {inputPath, outputPath} = getTestPaths('mocks/nested-docs');
|
|
115
|
+
|
|
116
|
+
// Test with custom config and --no-template-vars - should not load any presets at all
|
|
117
|
+
await TestAdapter.testBuildPass(inputPath, outputPath + '-no-vars-config', {
|
|
118
|
+
md2md: true,
|
|
119
|
+
args: '--config .yfm-subdoc --no-template-vars',
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// Check that ALL variables remain unresolved (no presets loaded at all)
|
|
123
|
+
const subDocContent = readFileSync(
|
|
124
|
+
resolve(outputPath + '-no-vars-config', 'subdoc/index.md'),
|
|
125
|
+
'utf8',
|
|
126
|
+
);
|
|
127
|
+
expect(subDocContent).toContain('{{subVar}}'); // Should remain unresolved
|
|
128
|
+
expect(subDocContent).toContain('{{commonVar}}'); // Should remain unresolved
|
|
129
|
+
expect(subDocContent).toContain('{{topLevelVar}}'); // Should remain unresolved
|
|
130
|
+
|
|
131
|
+
// Verify that no variables were resolved at all
|
|
132
|
+
expect(subDocContent).not.toContain('Sub var: subValue');
|
|
133
|
+
expect(subDocContent).not.toContain('Common var: fromSub');
|
|
134
|
+
expect(subDocContent).not.toContain('Top level var: topLevelValue');
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test('should not load any presets when template vars are disabled', async () => {
|
|
138
|
+
const {inputPath, outputPath} = getTestPaths('mocks/vars-ignore');
|
|
139
|
+
|
|
140
|
+
// Test with --no-template-vars flag - should not load any presets
|
|
141
|
+
await TestAdapter.testBuildPass(inputPath, outputPath + '-no-vars', {
|
|
142
|
+
md2md: true,
|
|
143
|
+
args: '--no-template-vars',
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// Check that ALL variables remain unresolved (no presets loaded)
|
|
147
|
+
const outputContent = readFileSync(resolve(outputPath + '-no-vars', 'test.md'), 'utf8');
|
|
148
|
+
expect(outputContent).toContain('{{rootVar}}'); // Should remain unresolved
|
|
149
|
+
expect(outputContent).toContain('{{commonVar}}'); // Should remain unresolved
|
|
150
|
+
expect(outputContent).toContain('{{ignoredVar}}'); // Should remain unresolved
|
|
151
|
+
expect(outputContent).toContain('{{dataVar}}'); // Should remain unresolved
|
|
152
|
+
|
|
153
|
+
// Check subdirectory files - variables should also remain unresolved
|
|
154
|
+
const ignoredContent = readFileSync(
|
|
155
|
+
resolve(outputPath + '-no-vars', 'ignored/ignored-test.md'),
|
|
156
|
+
'utf8',
|
|
157
|
+
);
|
|
158
|
+
expect(ignoredContent).toContain('{{rootVar}}'); // Should remain unresolved
|
|
159
|
+
expect(ignoredContent).toContain('{{ignoredVar}}'); // Should remain unresolved
|
|
160
|
+
|
|
161
|
+
const dataContent = readFileSync(
|
|
162
|
+
resolve(outputPath + '-no-vars', 'data/data-test.md'),
|
|
163
|
+
'utf8',
|
|
164
|
+
);
|
|
165
|
+
expect(dataContent).toContain('{{rootVar}}'); // Should remain unresolved
|
|
166
|
+
expect(dataContent).toContain('{{dataVar}}'); // Should remain unresolved
|
|
167
|
+
});
|
|
168
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|