@mintlify/cli 4.0.1739 → 4.0.1741
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/__test__/validateCommand.test.ts +422 -39
- package/__test__/validateEngine.test.ts +187 -3
- package/__test__/validateRules.test.ts +64 -49
- package/bin/cli.js +29 -44
- package/bin/helpers.js +1 -0
- package/bin/tsconfig.build.tsbuildinfo +1 -1
- package/bin/validate/command.js +50 -18
- package/bin/validate/engine.js +93 -8
- package/bin/validate/files.js +1 -1
- package/bin/validate/output.js +29 -13
- package/bin/validate/report.js +11 -0
- package/bin/validate/rules/build.js +94 -0
- package/bin/validate/rules/index.js +3 -1
- package/bin/validate/rules/openapi.js +50 -0
- package/package.json +5 -5
- package/src/cli.tsx +37 -61
- package/src/helpers.tsx +3 -0
- package/src/validate/command.tsx +46 -19
- package/src/validate/engine.ts +132 -9
- package/src/validate/files.ts +1 -1
- package/src/validate/output.tsx +34 -14
- package/src/validate/report.ts +40 -0
- package/src/validate/rules/build.ts +132 -0
- package/src/validate/rules/index.ts +3 -1
- package/src/validate/rules/openapi.ts +59 -0
- package/src/validate/types.ts +10 -0
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { addLog,
|
|
1
|
+
import { addLog, checkBuild } from '@mintlify/previewing';
|
|
2
2
|
import fs from 'fs-extra';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { mockProcessExit } from 'vitest-mock-process';
|
|
5
5
|
|
|
6
|
+
import { sendPublishPrompt } from '../src/signup.js';
|
|
7
|
+
import { toReport } from '../src/validate/report.js';
|
|
6
8
|
import { runCommand } from './utils.js';
|
|
7
9
|
|
|
8
10
|
const { dir } = vi.hoisted(() => ({
|
|
@@ -14,9 +16,19 @@ vi.mock('../src/helpers.js', async (importOriginal) => {
|
|
|
14
16
|
return { ...mod, CMD_EXEC_PATH: dir, autoUpgradeIfNeeded: vi.fn() };
|
|
15
17
|
});
|
|
16
18
|
|
|
19
|
+
vi.mock('../src/signup.js', async (importOriginal) => {
|
|
20
|
+
const mod = await importOriginal<typeof import('../src/signup.js')>();
|
|
21
|
+
return { ...mod, sendPublishPrompt: vi.fn() };
|
|
22
|
+
});
|
|
23
|
+
|
|
17
24
|
vi.mock('@mintlify/previewing', async (importOriginal) => {
|
|
18
25
|
const mod = await importOriginal<typeof import('@mintlify/previewing')>();
|
|
19
|
-
return { ...mod, addLog: vi.fn(),
|
|
26
|
+
return { ...mod, addLog: vi.fn(), checkBuild: vi.fn() };
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
vi.mock('../src/validate/report.js', async (importOriginal) => {
|
|
30
|
+
const mod = await importOriginal<typeof import('../src/validate/report.js')>();
|
|
31
|
+
return { ...mod, toReport: vi.fn(mod.toReport) };
|
|
20
32
|
});
|
|
21
33
|
|
|
22
34
|
const processExitMock = mockProcessExit();
|
|
@@ -37,80 +49,373 @@ const writeSite = (files: Record<string, string>, config: Record<string, unknown
|
|
|
37
49
|
}
|
|
38
50
|
};
|
|
39
51
|
|
|
52
|
+
const report = async (...args: string[]) => {
|
|
53
|
+
await runCommand(...args);
|
|
54
|
+
const result = vi.mocked(toReport).mock.results.at(-1);
|
|
55
|
+
expect(result?.type).toBe('return');
|
|
56
|
+
return result?.value as ReturnType<typeof toReport>;
|
|
57
|
+
};
|
|
58
|
+
|
|
40
59
|
const logged = () => JSON.stringify(vi.mocked(addLog).mock.calls);
|
|
41
60
|
|
|
61
|
+
const rules = (result: { diagnostics: { rule: string }[] }) =>
|
|
62
|
+
result.diagnostics.map(({ rule }) => rule);
|
|
63
|
+
|
|
42
64
|
describe('mint validate', () => {
|
|
43
65
|
beforeEach(() => {
|
|
44
66
|
vi.clearAllMocks();
|
|
45
|
-
vi.mocked(
|
|
67
|
+
vi.mocked(checkBuild).mockResolvedValue({ passed: true, warnings: [] });
|
|
46
68
|
});
|
|
47
69
|
|
|
48
70
|
afterAll(() => {
|
|
49
71
|
fs.removeSync(dir);
|
|
50
72
|
});
|
|
51
73
|
|
|
52
|
-
it('
|
|
74
|
+
it('builds one report with a summary and every diagnostic', async () => {
|
|
53
75
|
writeSite({
|
|
54
76
|
'index.mdx': '---\ntitle: Home\n---\n\nline<br>\n',
|
|
55
77
|
'other.mdx': '---\ntitle: Other\n---\n\nText {broken\n',
|
|
56
78
|
});
|
|
57
79
|
|
|
58
|
-
await
|
|
80
|
+
const result = await report('validate', '--no-build');
|
|
59
81
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
82
|
+
expect(result).toEqual({
|
|
83
|
+
passed: false,
|
|
84
|
+
summary: { errors: 2, warnings: 0, byRule: { 'parse-error': 1, 'void-tags': 1 } },
|
|
85
|
+
diagnostics: [
|
|
86
|
+
expect.objectContaining({
|
|
87
|
+
rule: 'void-tags',
|
|
88
|
+
group: 'content',
|
|
89
|
+
severity: 'error',
|
|
90
|
+
file: 'index.mdx',
|
|
91
|
+
line: 5,
|
|
92
|
+
fix: { file: 'index.mdx', start: 25, end: 29, text: '<br />' },
|
|
93
|
+
}),
|
|
94
|
+
expect.objectContaining({
|
|
95
|
+
rule: 'parse-error',
|
|
96
|
+
severity: 'error',
|
|
97
|
+
file: 'other.mdx',
|
|
98
|
+
message: expect.stringContaining('(other checks were skipped for this file)'),
|
|
99
|
+
}),
|
|
100
|
+
],
|
|
101
|
+
build: { ran: false, reason: 'disabled' },
|
|
102
|
+
});
|
|
67
103
|
expect(processExitMock).toHaveBeenCalledWith(1);
|
|
68
104
|
});
|
|
69
105
|
|
|
70
|
-
it('
|
|
106
|
+
it('passes and runs the build', async () => {
|
|
71
107
|
writeSite({ 'index.mdx': HOME });
|
|
72
108
|
|
|
73
|
-
await
|
|
109
|
+
const result = await report('validate');
|
|
74
110
|
|
|
75
|
-
expect(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
);
|
|
79
|
-
expect(processExitMock).
|
|
111
|
+
expect(result).toMatchObject({ passed: true, build: { ran: true, passed: true } });
|
|
112
|
+
expect(rules(result)).toEqual([]);
|
|
113
|
+
expect(checkBuild).toHaveBeenCalled();
|
|
114
|
+
expect(sendPublishPrompt).toHaveBeenCalled();
|
|
115
|
+
expect(processExitMock).toHaveBeenCalledWith(0);
|
|
80
116
|
});
|
|
81
117
|
|
|
82
|
-
it('
|
|
83
|
-
writeSite({ 'index.mdx':
|
|
118
|
+
it('skips the build while there are errors', async () => {
|
|
119
|
+
writeSite({ 'index.mdx': '---\ntitle: Home\n---\n\nline<br>\n' });
|
|
84
120
|
|
|
85
|
-
await
|
|
121
|
+
const result = await report('validate');
|
|
86
122
|
|
|
87
|
-
expect(
|
|
123
|
+
expect(result.build).toEqual({ ran: false, reason: 'errors found' });
|
|
124
|
+
expect(checkBuild).not.toHaveBeenCalled();
|
|
125
|
+
expect(processExitMock).toHaveBeenCalledWith(1);
|
|
88
126
|
});
|
|
89
127
|
|
|
90
|
-
it('turns
|
|
91
|
-
writeSite({ 'index.mdx':
|
|
128
|
+
it('turns build warnings into diagnostics', async () => {
|
|
129
|
+
writeSite({ 'index.mdx': HOME });
|
|
130
|
+
vi.mocked(checkBuild).mockResolvedValue({
|
|
131
|
+
passed: false,
|
|
132
|
+
error: 'Build validation failed with 1 warning(s). See above for details.',
|
|
133
|
+
strict: true,
|
|
134
|
+
warnings: [
|
|
135
|
+
{
|
|
136
|
+
type: 'missing-nav-page',
|
|
137
|
+
message: '"gone" is referenced in the docs.json navigation but the file does not exist.',
|
|
138
|
+
},
|
|
139
|
+
],
|
|
140
|
+
});
|
|
92
141
|
|
|
93
|
-
await
|
|
94
|
-
expect(logged()).toContain('parse-error');
|
|
95
|
-
expect(logged()).not.toContain('void-tags');
|
|
142
|
+
const result = await report('validate');
|
|
96
143
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
144
|
+
expect(result.diagnostics).toEqual([
|
|
145
|
+
expect.objectContaining({ rule: 'missing-nav-page', group: 'nav', file: 'docs.json' }),
|
|
146
|
+
]);
|
|
147
|
+
expect(result.build).toEqual({ ran: true, passed: false });
|
|
148
|
+
expect(processExitMock).toHaveBeenCalledWith(1);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('attributes a missing nav page that looks like a file to the config', async () => {
|
|
152
|
+
writeSite({ 'index.mdx': HOME }, { navigation: { pages: ['index', 'guides/setup.md'] } });
|
|
153
|
+
vi.mocked(checkBuild).mockResolvedValue({
|
|
154
|
+
passed: false,
|
|
155
|
+
error: 'Build validation failed with 1 warning(s). See above for details.',
|
|
156
|
+
strict: true,
|
|
157
|
+
warnings: [
|
|
158
|
+
{
|
|
159
|
+
type: 'missing-nav-page',
|
|
160
|
+
message:
|
|
161
|
+
'"guides/setup.md" is referenced in the docs.json navigation but the file does not exist.',
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
const result = await report('validate');
|
|
167
|
+
|
|
168
|
+
expect(result.diagnostics).toEqual([
|
|
169
|
+
expect.objectContaining({
|
|
170
|
+
rule: 'missing-nav-page',
|
|
171
|
+
file: 'docs.json',
|
|
172
|
+
line: expect.any(Number),
|
|
173
|
+
}),
|
|
174
|
+
]);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('reports a build failure no rule explains', async () => {
|
|
178
|
+
writeSite({ 'index.mdx': HOME });
|
|
179
|
+
vi.mocked(checkBuild).mockResolvedValue({
|
|
180
|
+
passed: false,
|
|
181
|
+
error: 'boom',
|
|
182
|
+
strict: false,
|
|
183
|
+
warnings: [],
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
const result = await report('validate');
|
|
187
|
+
|
|
188
|
+
expect(result.diagnostics).toEqual([
|
|
189
|
+
expect.objectContaining({ rule: 'build-failed', message: 'boom' }),
|
|
190
|
+
]);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('passes when the build fails only on disabled rules', async () => {
|
|
194
|
+
writeSite({ 'index.mdx': HOME });
|
|
195
|
+
vi.mocked(checkBuild).mockResolvedValue({
|
|
196
|
+
passed: false,
|
|
197
|
+
error: 'Build validation failed with 1 warning(s). See above for details.',
|
|
198
|
+
strict: true,
|
|
199
|
+
warnings: [
|
|
200
|
+
{
|
|
201
|
+
type: 'missing-nav-page',
|
|
202
|
+
message: '"gone" is referenced in the docs.json navigation but the file does not exist.',
|
|
203
|
+
},
|
|
204
|
+
],
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
const result = await report('validate', '--disable', 'missing-nav-page');
|
|
208
|
+
|
|
209
|
+
expect(result).toMatchObject({ passed: true, build: { ran: true, passed: false } });
|
|
210
|
+
expect(rules(result)).toEqual([]);
|
|
211
|
+
expect(sendPublishPrompt).not.toHaveBeenCalled();
|
|
212
|
+
expect(processExitMock).toHaveBeenCalledWith(0);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('fails on a build error even when a disabled rule covers its warnings', async () => {
|
|
216
|
+
writeSite({ 'index.mdx': HOME });
|
|
217
|
+
vi.mocked(checkBuild).mockResolvedValue({
|
|
218
|
+
passed: false,
|
|
219
|
+
error: 'Unexpected token } in docs.json',
|
|
220
|
+
strict: false,
|
|
221
|
+
warnings: [{ type: 'openapi', message: 'Could not read OpenAPI overlay settings' }],
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
const result = await report('validate', '--disable', 'openapi');
|
|
225
|
+
|
|
226
|
+
expect(result.passed).toBe(false);
|
|
227
|
+
expect(result.diagnostics).toEqual([
|
|
228
|
+
expect.objectContaining({ rule: 'build-failed', message: 'Unexpected token } in docs.json' }),
|
|
229
|
+
]);
|
|
100
230
|
expect(processExitMock).toHaveBeenCalledWith(1);
|
|
101
231
|
});
|
|
102
232
|
|
|
233
|
+
it('skips OpenAPI generation in the build only when no openapi rule is selected', async () => {
|
|
234
|
+
writeSite({ 'index.mdx': HOME });
|
|
235
|
+
|
|
236
|
+
await report('validate', '--disable', 'openapi');
|
|
237
|
+
expect(checkBuild).toHaveBeenLastCalledWith(expect.objectContaining({ disableOpenapi: true }));
|
|
238
|
+
|
|
239
|
+
await report('validate');
|
|
240
|
+
expect(checkBuild).toHaveBeenLastCalledWith(expect.objectContaining({ disableOpenapi: false }));
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it('cleans build warning messages and lifts their position', async () => {
|
|
244
|
+
writeSite({ 'index.mdx': HOME });
|
|
245
|
+
vi.mocked(checkBuild).mockResolvedValue({
|
|
246
|
+
passed: false,
|
|
247
|
+
error: 'Build validation failed with 1 warning(s). See above for details.',
|
|
248
|
+
strict: true,
|
|
249
|
+
warnings: [
|
|
250
|
+
{ type: 'parse-error', message: '\n\u001b[31m./index.mdx:3:7 Unexpected token\u001b[39m' },
|
|
251
|
+
],
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
const result = await report('validate');
|
|
255
|
+
|
|
256
|
+
expect(result.diagnostics).toEqual([
|
|
257
|
+
expect.objectContaining({
|
|
258
|
+
rule: 'parse-error',
|
|
259
|
+
file: 'index.mdx',
|
|
260
|
+
line: 3,
|
|
261
|
+
column: 7,
|
|
262
|
+
message: './index.mdx:3:7 Unexpected token',
|
|
263
|
+
}),
|
|
264
|
+
]);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it('fails when the build fails on a parse error outside --files', async () => {
|
|
268
|
+
writeSite({ 'index.mdx': HOME, 'other.mdx': HOME });
|
|
269
|
+
vi.mocked(checkBuild).mockResolvedValue({
|
|
270
|
+
passed: false,
|
|
271
|
+
error: 'Build validation failed with 1 warning(s). See above for details.',
|
|
272
|
+
strict: true,
|
|
273
|
+
warnings: [{ type: 'parse-error', message: './other.mdx:3:7 Unexpected token' }],
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
const result = await report('validate', '--files', 'index.mdx');
|
|
277
|
+
|
|
278
|
+
expect(result.passed).toBe(false);
|
|
279
|
+
expect(result.diagnostics).toEqual([
|
|
280
|
+
expect.objectContaining({ rule: 'build-failed', file: 'other.mdx' }),
|
|
281
|
+
]);
|
|
282
|
+
expect(processExitMock).toHaveBeenCalledWith(1);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it('attributes import warnings to the importing page', async () => {
|
|
286
|
+
writeSite({ 'index.mdx': HOME });
|
|
287
|
+
vi.mocked(checkBuild).mockResolvedValue({
|
|
288
|
+
passed: false,
|
|
289
|
+
error: 'Build validation failed with 3 warning(s). See above for details.',
|
|
290
|
+
strict: true,
|
|
291
|
+
warnings: [
|
|
292
|
+
{
|
|
293
|
+
type: 'missing-file',
|
|
294
|
+
message: 'Could not find file snippets/gone.mdx - imported from index.mdx',
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
type: 'invalid-import-path',
|
|
298
|
+
message:
|
|
299
|
+
'Invalid import path https://example.com/a.jsx in index.mdx. Only local imports are supported.',
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
type: 'export-collision',
|
|
303
|
+
message: 'Widget is exported by snippets/a.jsx (in index.mdx, importing snippets/b.mdx)',
|
|
304
|
+
},
|
|
305
|
+
],
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
const result = await report('validate');
|
|
309
|
+
|
|
310
|
+
expect(result.diagnostics.map(({ file }) => file)).toEqual([
|
|
311
|
+
'index.mdx',
|
|
312
|
+
'index.mdx',
|
|
313
|
+
'index.mdx',
|
|
314
|
+
]);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it('reports missing imported files with the content group', async () => {
|
|
318
|
+
writeSite({ 'index.mdx': HOME });
|
|
319
|
+
vi.mocked(checkBuild).mockResolvedValue({
|
|
320
|
+
passed: false,
|
|
321
|
+
error: 'Build validation failed with 1 warning(s). See above for details.',
|
|
322
|
+
strict: true,
|
|
323
|
+
warnings: [
|
|
324
|
+
{
|
|
325
|
+
type: 'missing-file',
|
|
326
|
+
message: 'Could not find file snippets/gone.mdx - imported from index.mdx',
|
|
327
|
+
},
|
|
328
|
+
],
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
const result = await report('validate', '--disable', 'all', '--enable', 'content');
|
|
332
|
+
|
|
333
|
+
expect(result.diagnostics).toEqual([
|
|
334
|
+
expect.objectContaining({ rule: 'missing-file', group: 'content', file: 'index.mdx' }),
|
|
335
|
+
]);
|
|
336
|
+
expect(processExitMock).toHaveBeenCalledWith(1);
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it('keeps skipped-spec notices as warnings', async () => {
|
|
340
|
+
writeSite({ 'index.mdx': HOME }, { api: { openapi: 'http://example.com/openapi.json' } });
|
|
341
|
+
|
|
342
|
+
const result = await report('validate', '--no-build');
|
|
343
|
+
|
|
344
|
+
expect(result.passed).toBe(true);
|
|
345
|
+
expect(result.diagnostics).toEqual([
|
|
346
|
+
expect.objectContaining({
|
|
347
|
+
rule: 'openapi-spec',
|
|
348
|
+
severity: 'warning',
|
|
349
|
+
message: expect.stringContaining('--local-schema'),
|
|
350
|
+
}),
|
|
351
|
+
expect.objectContaining({
|
|
352
|
+
rule: 'openapi-spec',
|
|
353
|
+
severity: 'warning',
|
|
354
|
+
message: 'only https protocol is supported in production',
|
|
355
|
+
}),
|
|
356
|
+
]);
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it('exits 2 when the build could not be prepared', async () => {
|
|
360
|
+
writeSite({ 'index.mdx': HOME });
|
|
361
|
+
vi.mocked(checkBuild).mockRejectedValue(new Error('requires an internet connection'));
|
|
362
|
+
|
|
363
|
+
await runCommand('validate');
|
|
364
|
+
|
|
365
|
+
expect(logged()).toContain('requires an internet connection');
|
|
366
|
+
expect(processExitMock).toHaveBeenCalledWith(2);
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
it('applies fixes with --fix and lists them', async () => {
|
|
370
|
+
writeSite({ 'index.mdx': '---\ntitle: Home\n---\n\nline<br>\n' });
|
|
371
|
+
|
|
372
|
+
const result = await report('validate', '--no-build', '--fix');
|
|
373
|
+
|
|
374
|
+
expect(fs.readFileSync(path.join(dir, 'index.mdx'), 'utf-8')).toContain('line<br />');
|
|
375
|
+
expect(result.fixed).toEqual([
|
|
376
|
+
{
|
|
377
|
+
rule: 'void-tags',
|
|
378
|
+
file: 'index.mdx',
|
|
379
|
+
line: 5,
|
|
380
|
+
column: 5,
|
|
381
|
+
before: '<br>',
|
|
382
|
+
after: '<br />',
|
|
383
|
+
},
|
|
384
|
+
]);
|
|
385
|
+
expect(rules(result)).toEqual([]);
|
|
386
|
+
expect(processExitMock).toHaveBeenCalledWith(0);
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
it('turns rules and groups on and off', async () => {
|
|
390
|
+
writeSite({
|
|
391
|
+
'index.mdx': '---\ntitle: Home\n---\n\nline<br>\n',
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
// Without void-tags, nothing makes the page parseable
|
|
395
|
+
expect(rules(await report('validate', '--no-build', '--disable', 'content'))).toEqual([
|
|
396
|
+
'parse-error',
|
|
397
|
+
]);
|
|
398
|
+
expect(rules(await report('validate', '--no-build', '--disable', 'all'))).toEqual([
|
|
399
|
+
'parse-error',
|
|
400
|
+
]);
|
|
401
|
+
expect(
|
|
402
|
+
rules(await report('validate', '--no-build', '--disable', 'all', '--enable', 'void-tags'))
|
|
403
|
+
).toEqual(['void-tags']);
|
|
404
|
+
expect(
|
|
405
|
+
rules(await report('validate', '--no-build', '--disable', 'openapi, missing-nav-page'))
|
|
406
|
+
).toEqual(['void-tags']);
|
|
407
|
+
});
|
|
408
|
+
|
|
103
409
|
it('rejects unknown rules and disabling parse-error', async () => {
|
|
104
410
|
writeSite({ 'index.mdx': HOME });
|
|
105
411
|
|
|
106
412
|
await runCommand('validate', '--disable', 'nope');
|
|
107
413
|
expect(logged()).toContain('unknown rule or group');
|
|
108
|
-
expect(processExitMock).toHaveBeenLastCalledWith(
|
|
414
|
+
expect(processExitMock).toHaveBeenLastCalledWith(2);
|
|
109
415
|
|
|
110
416
|
await runCommand('validate', '--disable', 'parse-error');
|
|
111
417
|
expect(logged()).toContain("parse-error always runs and can't be disabled");
|
|
112
|
-
expect(processExitMock).toHaveBeenLastCalledWith(
|
|
113
|
-
expect(validateBuild).not.toHaveBeenCalled();
|
|
418
|
+
expect(processExitMock).toHaveBeenLastCalledWith(2);
|
|
114
419
|
});
|
|
115
420
|
|
|
116
421
|
it('limits page findings to --files', async () => {
|
|
@@ -122,11 +427,67 @@ describe('mint validate', () => {
|
|
|
122
427
|
{ navigation: { pages: ['index', 'other'] } }
|
|
123
428
|
);
|
|
124
429
|
|
|
125
|
-
await
|
|
430
|
+
const result = await report('validate', '--no-build', '--files', 'other.mdx');
|
|
126
431
|
|
|
127
|
-
expect(
|
|
128
|
-
|
|
129
|
-
|
|
432
|
+
expect(result.diagnostics.map(({ file }: { file: string }) => file)).toEqual([
|
|
433
|
+
'other.mdx',
|
|
434
|
+
'other.mdx',
|
|
435
|
+
]);
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
it('posix-normalizes Windows paths in build warnings', async () => {
|
|
439
|
+
writeSite({ 'index.mdx': HOME, 'snippets/card.mdx': 'Card\n' });
|
|
440
|
+
vi.mocked(checkBuild).mockResolvedValue({
|
|
441
|
+
passed: false,
|
|
442
|
+
error: 'Build validation failed with 1 warning(s). See above for details.',
|
|
443
|
+
strict: true,
|
|
444
|
+
warnings: [{ type: 'parse-error', message: '.\\snippets\\card.mdx:2:1 Unexpected token' }],
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
const result = await report('validate');
|
|
448
|
+
|
|
449
|
+
expect(result.diagnostics).toEqual([
|
|
450
|
+
expect.objectContaining({ rule: 'parse-error', file: 'snippets/card.mdx', line: 2 }),
|
|
451
|
+
]);
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
it('checks every OpenAPI spec and sorts findings by file', async () => {
|
|
455
|
+
writeSite({ 'index.mdx': HOME }, { api: { openapi: ['b.json', 'a.json'] } });
|
|
456
|
+
fs.writeFileSync(path.join(dir, 'a.json'), '{ not json');
|
|
457
|
+
fs.writeFileSync(path.join(dir, 'b.json'), '{ not json');
|
|
458
|
+
|
|
459
|
+
const result = await report('validate', '--no-build');
|
|
460
|
+
|
|
461
|
+
expect(result.diagnostics.map(({ rule, file }) => [rule, file])).toEqual([
|
|
462
|
+
['openapi-spec', 'a.json'],
|
|
463
|
+
['openapi-spec', 'b.json'],
|
|
464
|
+
]);
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
it('reports invalid OpenAPI specs and skips them with --disable openapi', async () => {
|
|
468
|
+
writeSite({ 'index.mdx': HOME }, { api: { openapi: 'openapi.json' } });
|
|
469
|
+
fs.writeFileSync(path.join(dir, 'openapi.json'), '{ not json');
|
|
470
|
+
|
|
471
|
+
expect(rules(await report('validate', '--no-build'))).toEqual(['openapi-spec']);
|
|
472
|
+
expect(rules(await report('validate', '--no-build', '--disable', 'openapi'))).toEqual([]);
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
it('checks the OpenAPI specs a mint.json lists', async () => {
|
|
476
|
+
writeSite({ 'index.mdx': HOME });
|
|
477
|
+
fs.removeSync(path.join(dir, 'docs.json'));
|
|
478
|
+
fs.writeJSONSync(path.join(dir, 'mint.json'), {
|
|
479
|
+
name: 'Test',
|
|
480
|
+
colors: { primary: '#000000' },
|
|
481
|
+
navigation: [{ group: 'Home', pages: ['index'] }],
|
|
482
|
+
openapi: 'openapi.json',
|
|
483
|
+
});
|
|
484
|
+
fs.writeFileSync(path.join(dir, 'openapi.json'), '{ not json');
|
|
485
|
+
|
|
486
|
+
const result = await report('validate', '--no-build');
|
|
487
|
+
|
|
488
|
+
expect(result.diagnostics).toEqual([
|
|
489
|
+
expect.objectContaining({ rule: 'openapi-spec', file: 'openapi.json' }),
|
|
490
|
+
]);
|
|
130
491
|
});
|
|
131
492
|
|
|
132
493
|
it('rejects --files that match nothing', async () => {
|
|
@@ -135,7 +496,29 @@ describe('mint validate', () => {
|
|
|
135
496
|
await runCommand('validate', '--files', 'missing.mdx');
|
|
136
497
|
|
|
137
498
|
expect(logged()).toContain('No matching files');
|
|
499
|
+
expect(processExitMock).toHaveBeenCalledWith(2);
|
|
500
|
+
expect(checkBuild).not.toHaveBeenCalled();
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
it('rejects the removed --disable-openapi flag', async () => {
|
|
504
|
+
writeSite({ 'index.mdx': HOME });
|
|
505
|
+
const error = vi.spyOn(console, 'error').mockImplementation(() => undefined);
|
|
506
|
+
|
|
507
|
+
await expect(runCommand('validate', '--no-build', '--disable-openapi')).rejects.toThrow();
|
|
508
|
+
|
|
509
|
+
expect(error).toHaveBeenCalledWith(expect.stringContaining('Unknown argument'));
|
|
510
|
+
error.mockRestore();
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
it('logs diagnostics by file and a verdict in text mode', async () => {
|
|
514
|
+
writeSite({ 'index.mdx': '---\ntitle: Home\n---\n\nline<br>\n' });
|
|
515
|
+
|
|
516
|
+
await runCommand('validate', '--no-build');
|
|
517
|
+
|
|
518
|
+
const text = logged();
|
|
519
|
+
expect(text).toContain('index.mdx');
|
|
520
|
+
expect(text).toContain('must be self-closed');
|
|
521
|
+
expect(text).toContain('1 error');
|
|
138
522
|
expect(processExitMock).toHaveBeenCalledWith(1);
|
|
139
|
-
expect(validateBuild).not.toHaveBeenCalled();
|
|
140
523
|
});
|
|
141
524
|
});
|