@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.
@@ -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
+
@@ -0,0 +1,5 @@
1
+ ignore:
2
+ - "*.yaml"
3
+ - "*.md"
4
+ - "!subdoc/"
5
+ - "!subdoc/**"
@@ -0,0 +1,5 @@
1
+ # Top Level Documentation
2
+
3
+ Top level var: {{topLevelVar}}
4
+ Common var: {{commonVar}}
5
+ Sub var: {{subVar}}
@@ -0,0 +1,3 @@
1
+ default:
2
+ topLevelVar: topLevelValue
3
+ commonVar: fromTopLevel
File without changes
@@ -0,0 +1,5 @@
1
+ # Sub Documentation
2
+
3
+ Top level var: {{topLevelVar}}
4
+ Common var: {{commonVar}}
5
+ Sub var: {{subVar}}
@@ -0,0 +1,3 @@
1
+ default:
2
+ subVar: subValue
3
+ commonVar: fromSub
@@ -0,0 +1,4 @@
1
+ title: Sub Documentation
2
+ items:
3
+ - name: Sub Page
4
+ href: index.md
@@ -0,0 +1,6 @@
1
+ title: Top Level Doc
2
+ items:
3
+ - name: Top Level Page
4
+ href: index.md
5
+ - name: Sub Documentation
6
+ href: subdoc/
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,4 @@
1
+ # Data Test
2
+
3
+ Root var: {{rootVar}}
4
+ Data var: {{dataVar}}
@@ -0,0 +1,3 @@
1
+ default:
2
+ dataVar: dataValue
3
+ commonVar: fromData
@@ -0,0 +1,4 @@
1
+ # Temp Test
2
+
3
+ Root var: {{rootVar}}
4
+ Temp var: {{tempVar}}
@@ -0,0 +1,4 @@
1
+ # Ignored Test
2
+
3
+ Root var: {{rootVar}}
4
+ Ignored var: {{ignoredVar}}
@@ -0,0 +1,3 @@
1
+ default:
2
+ ignoredVar: ignoredValue
3
+ commonVar: fromIgnored
@@ -0,0 +1,3 @@
1
+ default:
2
+ rootVar: rootValue
3
+ commonVar: fromRoot
@@ -0,0 +1,6 @@
1
+ # Test
2
+
3
+ Root var: {{rootVar}}
4
+ Common var: {{commonVar}}
5
+ Ignored var: {{ignoredVar}}
6
+ Data var: {{dataVar}}
@@ -0,0 +1,8 @@
1
+ title: Test
2
+ items:
3
+ - name: Test
4
+ href: test.md
5
+ - name: Ignored Test
6
+ href: ignored/ignored-test.md
7
+ - name: Data Test
8
+ href: data/data-test.md
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diplodoc/cli-tests",
3
- "version": "5.16.2",
3
+ "version": "5.16.4",
4
4
  "bin": {
5
5
  "diplodoc-cli-test": "bin.mjs"
6
6
  },