-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjest.setup.ts
More file actions
95 lines (82 loc) · 2.66 KB
/
Copy pathjest.setup.ts
File metadata and controls
95 lines (82 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import '@testing-library/jest-dom';
import { toHaveNoViolations } from 'jest-axe';
// Extend expect with axe accessibility matchers
expect.extend(toHaveNoViolations);
import { TextEncoder, TextDecoder } from 'util';
// Polyfill TextEncoder/TextDecoder for Node.js environment
global.TextEncoder = TextEncoder as typeof global.TextEncoder;
global.TextDecoder = TextDecoder as typeof global.TextDecoder;
// Mock react-markdown and remark-gfm since they're ESM-only
jest.mock('react-markdown', () => {
const React = require('react');
return {
__esModule: true,
default: ({ children, components }: { children: string; components?: any }) => {
// Parse markdown for code blocks and render custom components
const codeBlockRegex = /```(\w*)\n([\s\S]*?)```/g;
const parts: React.ReactNode[] = [];
let lastIndex = 0;
let match;
let keyIndex = 0;
while ((match = codeBlockRegex.exec(children)) !== null) {
// Add text before code block
if (match.index > lastIndex) {
parts.push(React.createElement('span', { key: `text-${keyIndex++}` }, children.slice(lastIndex, match.index)));
}
const [, lang, content] = match;
// Call custom code component if provided
if (components?.code) {
const CodeComponent = components.code;
parts.push(
React.createElement(
'span',
{ key: `code-${keyIndex++}` },
CodeComponent({
className: lang ? `language-${lang}` : undefined,
children: content,
}),
),
);
} else {
parts.push(React.createElement('span', { key: `code-${keyIndex++}` }, content));
}
lastIndex = match.index + match[0].length;
}
// Add remaining text
if (lastIndex < children.length) {
parts.push(React.createElement('span', { key: `text-${keyIndex++}` }, children.slice(lastIndex)));
}
return parts.length > 0 ? parts : children;
},
};
});
jest.mock('remark-gfm', () => ({
__esModule: true,
default: () => {},
}));
// Mock markmap libraries
jest.mock('markmap-lib', () => ({
Transformer: jest.fn().mockImplementation(() => ({
transform: jest.fn((markdown: string) => ({
root: { data: { content: markdown } },
})),
})),
}));
jest.mock('markmap-view', () => ({
Markmap: {
create: jest.fn(() => ({
rescale: jest.fn(),
fit: jest.fn(),
})),
},
}));
// Mock IntersectionObserver
global.IntersectionObserver = class IntersectionObserver {
constructor() {}
disconnect() {}
observe() {}
takeRecords() {
return [];
}
unobserve() {}
} as any;