@mintlify/cli 4.0.1647 → 4.0.1649

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,81 @@
1
+ import fs from 'fs';
2
+
3
+ import { checkMdxAccessibility } from '../src/mdxAccessibility.js';
4
+
5
+ vi.mock('@mintlify/prebuild', async (importOriginal) => {
6
+ const mod = await importOriginal<typeof import('@mintlify/prebuild')>();
7
+ return {
8
+ ...mod,
9
+ getMintIgnore: vi.fn(async () => []),
10
+ categorizeFilePaths: vi.fn(async () => ({ contentFilenames: ['test.mdx'] })),
11
+ };
12
+ });
13
+
14
+ vi.mock('fs');
15
+
16
+ const mockReadFileSync = vi.mocked(fs.readFileSync);
17
+
18
+ beforeEach(() => {
19
+ vi.clearAllMocks();
20
+ });
21
+
22
+ describe('checkMdxAccessibility', () => {
23
+ it('detects missing alt on markdown image', async () => {
24
+ mockReadFileSync.mockReturnValueOnce('![](image.png)' as unknown as Buffer);
25
+ const result = await checkMdxAccessibility('/docs');
26
+ expect(result.missingAltAttributes).toHaveLength(1);
27
+ expect(result.missingAltAttributes[0]?.element).toBe('img');
28
+ });
29
+
30
+ it('detects missing alt on JSX img', async () => {
31
+ mockReadFileSync.mockReturnValueOnce('<img src="image.png" />' as unknown as Buffer);
32
+ const result = await checkMdxAccessibility('/docs');
33
+ expect(result.missingAltAttributes).toHaveLength(1);
34
+ expect(result.missingAltAttributes[0]?.element).toBe('img');
35
+ });
36
+
37
+ it('detects missing alt on JSX video', async () => {
38
+ mockReadFileSync.mockReturnValueOnce('<video src="clip.mp4" />' as unknown as Buffer);
39
+ const result = await checkMdxAccessibility('/docs');
40
+ expect(result.missingAltAttributes).toHaveLength(1);
41
+ expect(result.missingAltAttributes[0]?.element).toBe('video');
42
+ });
43
+
44
+ it('detects empty anchor', async () => {
45
+ mockReadFileSync.mockReturnValueOnce('<a href="/page"></a>' as unknown as Buffer);
46
+ const result = await checkMdxAccessibility('/docs');
47
+ expect(result.missingAltAttributes).toHaveLength(1);
48
+ expect(result.missingAltAttributes[0]?.element).toBe('a');
49
+ });
50
+
51
+ it('passes when alt text is present', async () => {
52
+ mockReadFileSync.mockReturnValueOnce('![A cat](cat.png)' as unknown as Buffer);
53
+ const result = await checkMdxAccessibility('/docs');
54
+ expect(result.missingAltAttributes).toHaveLength(0);
55
+ });
56
+
57
+ it('does not skip files containing {#id} heading syntax', async () => {
58
+ const content = '## Heading {#custom-id}\n\n<img src="image.png" />';
59
+ mockReadFileSync.mockReturnValueOnce(content as unknown as Buffer);
60
+ const result = await checkMdxAccessibility('/docs');
61
+ expect(result.missingAltAttributes).toHaveLength(1);
62
+ expect(result.missingAltAttributes[0]?.element).toBe('img');
63
+ });
64
+
65
+ it('reports accurate line numbers when {#id} heading precedes the issue', async () => {
66
+ const content = '## Heading {#custom-id}\n\n<img src="image.png" />';
67
+ mockReadFileSync.mockReturnValueOnce(content as unknown as Buffer);
68
+ const result = await checkMdxAccessibility('/docs');
69
+ expect(result.missingAltAttributes[0]?.line).toBe(2);
70
+ });
71
+
72
+ it('returns correct totals', async () => {
73
+ mockReadFileSync.mockReturnValueOnce(
74
+ '<img src="a.png" />\n<img src="b.png" />' as unknown as Buffer
75
+ );
76
+ const result = await checkMdxAccessibility('/docs');
77
+ expect(result.totalFiles).toBe(1);
78
+ expect(result.filesWithIssues).toBe(1);
79
+ expect(result.missingAltAttributes).toHaveLength(2);
80
+ });
81
+ });
@@ -75,7 +75,8 @@ const checkAltAttributes = (filePath, content) => {
75
75
  };
76
76
  };
77
77
  try {
78
- coreRemark().use(visitElements).processSync(content);
78
+ const stripped = content.replace(/^( {0,3}#{1,6}\s+.+?)\s*\{#[^}]+\}\s*$/gm, '$1');
79
+ coreRemark().use(visitElements).processSync(stripped);
79
80
  }
80
81
  catch (error) {
81
82
  console.warn(`Warning: Could not parse ${filePath}: ${error}`);