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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
|
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { render } from 'ink-testing-library';
import { MarkdownDisplay } from './MarkdownDisplay.js';
describe('MarkdownDisplay', () => {
describe('Table Rendering', () => {
it('should render a simple table', () => {
const tableMarkdown = `
| Name | Age | City |
|------|-----|------|
| John | 25 | NYC |
| Jane | 30 | LA |
`;
const { lastFrame } = render(
<MarkdownDisplay
text={tableMarkdown}
isPending={false}
terminalWidth={80}
/>,
);
expect(lastFrame()).toContain('Name');
expect(lastFrame()).toContain('Age');
expect(lastFrame()).toContain('City');
expect(lastFrame()).toContain('John');
expect(lastFrame()).toContain('25');
expect(lastFrame()).toContain('NYC');
expect(lastFrame()).toContain('Jane');
expect(lastFrame()).toContain('30');
expect(lastFrame()).toContain('LA');
});
it('should handle tables with varying column widths', () => {
const tableMarkdown = `
| Short | Medium Column | Very Long Column Name |
|-------|---------------|----------------------|
| A | Some text | This is a longer text content |
| B | More content | Another piece of content here |
`;
const { lastFrame } = render(
<MarkdownDisplay
text={tableMarkdown}
isPending={false}
terminalWidth={80}
/>,
);
expect(lastFrame()).toContain('Short');
expect(lastFrame()).toContain('Medium Column');
expect(lastFrame()).toContain('Very Long Column Name');
});
it('should handle empty cells in tables', () => {
const tableMarkdown = `
| Col1 | Col2 | Col3 |
|------|------|------|
| A | | C |
| | B | |
`;
const { lastFrame } = render(
<MarkdownDisplay
text={tableMarkdown}
isPending={false}
terminalWidth={80}
/>,
);
expect(lastFrame()).toContain('Col1');
expect(lastFrame()).toContain('Col2');
expect(lastFrame()).toContain('Col3');
expect(lastFrame()).toContain('A');
expect(lastFrame()).toContain('B');
expect(lastFrame()).toContain('C');
});
it('should handle mixed content with tables', () => {
const mixedMarkdown = `
# Header
Some paragraph text before the table.
| Feature | Status | Notes |
|---------|--------|-------|
| Auth | Done | OAuth |
| API | WIP | REST |
Some text after the table.
`;
const { lastFrame } = render(
<MarkdownDisplay
text={mixedMarkdown}
isPending={false}
terminalWidth={80}
/>,
);
expect(lastFrame()).toContain('Header');
expect(lastFrame()).toContain('Some paragraph text before the table.');
expect(lastFrame()).toContain('Feature');
expect(lastFrame()).toContain('Status');
expect(lastFrame()).toContain('Auth');
expect(lastFrame()).toContain('Done');
expect(lastFrame()).toContain('Some text after the table.');
});
it('should handle tables with empty cells at edges', () => {
const tableMarkdown = `
| | Middle | |
|-|--------|-|
| | Value | |
`;
const { lastFrame } = render(
<MarkdownDisplay
text={tableMarkdown}
isPending={false}
terminalWidth={80}
/>,
);
expect(lastFrame()).toContain('Middle');
expect(lastFrame()).toContain('Value');
// Should maintain column structure even with empty edge cells
});
it('should handle PR reviewer test case 1', () => {
const tableMarkdown = `
| Package | Lines of Code |
|---------|---------------|
| CLI | 18407 |
| Core | 14445 |
`;
const { lastFrame } = render(
<MarkdownDisplay
text={tableMarkdown}
isPending={false}
terminalWidth={80}
/>,
);
const output = lastFrame();
expect(output).toContain('Package');
expect(output).toContain('Lines of Code');
expect(output).toContain('CLI');
expect(output).toContain('18407');
expect(output).toContain('Core');
expect(output).toContain('14445');
});
it('should handle PR reviewer test case 2 - long table', () => {
const tableMarkdown = `
| Letter | Count |
|--------|-------|
| a | 15 |
| b | 2 |
| c | 26 |
| Total | 283 |
`;
const { lastFrame } = render(
<MarkdownDisplay
text={tableMarkdown}
isPending={false}
terminalWidth={80}
/>,
);
const output = lastFrame();
expect(output).toContain('Letter');
expect(output).toContain('Count');
expect(output).toContain('a');
expect(output).toContain('15');
expect(output).toContain('Total');
expect(output).toContain('283');
});
it('should not render malformed tables', () => {
const malformedMarkdown = `
| This looks like a table |
But there's no separator line
| So it shouldn't render as table |
`;
const { lastFrame } = render(
<MarkdownDisplay
text={malformedMarkdown}
isPending={false}
terminalWidth={80}
/>,
);
// Should render as regular text, not a table
expect(lastFrame()).toContain('| This looks like a table |');
expect(lastFrame()).toContain("But there's no separator line");
expect(lastFrame()).toContain("| So it shouldn't render as table |");
});
it('should not crash when rendering a very wide table in a narrow terminal', () => {
const wideTable = `
| Col 1 | Col 2 | Col 3 | Col 4 | Col 5 | Col 6 | Col 7 | Col 8 | Col 9 | Col 10 |
|-------|-------|-------|-------|-------|-------|-------|-------|-------|--------|
| ${'a'.repeat(20)} | ${'b'.repeat(20)} | ${'c'.repeat(20)} | ${'d'.repeat(
20,
)} | ${'e'.repeat(20)} | ${'f'.repeat(20)} | ${'g'.repeat(20)} | ${'h'.repeat(
20,
)} | ${'i'.repeat(20)} | ${'j'.repeat(20)} |
`;
const renderNarrow = () =>
render(
<MarkdownDisplay
text={wideTable}
isPending={false}
terminalWidth={40}
/>,
);
// The important part is that this does not throw an error.
expect(renderNarrow).not.toThrow();
// We can also check that it rendered *something*.
const { lastFrame } = renderNarrow();
expect(lastFrame()).not.toBe('');
});
it('should handle inline markdown in tables', () => {
// Test content from MarkdownDisplay.demo.tsx
const testContent = `
# execSync vs spawn
| Characteristic | \`execSync\` (Old Way) | \`spawn\` (New Way in PR) |
|----------------|------------------------|---------------------------|
| **Execution** | Synchronous (blocks everything) | Asynchronous (non-blocking) |
| **I/O Handling** | Buffers entire output in memory | Streams data in chunks (memory efficient) |
| **Security** | **Vulnerable to shell injection** | **Safe from shell injection** |
| **Use Case** | Simple, quick commands with small, trusted... | Long-running processes, large I/O, and especially for running user-configur... |
`;
const { lastFrame } = render(
<MarkdownDisplay
text={testContent}
isPending={false}
terminalWidth={120}
/>,
);
const output = lastFrame();
// Check header
expect(output).toContain('execSync vs spawn');
// Check table headers - handle possible truncation
expect(output).toMatch(/Cha(racteristic)?/); // Match "Cha" or "Characteristic"
expect(output).toContain('execSync');
expect(output).toContain('spawn');
// Check table content - test keywords rather than full sentences
expect(output).toMatch(/Exe(cution)?/); // Match "Exe" or "Execution"
expect(output).toContain('Synchronous');
expect(output).toContain('Asynchronous');
expect(output).toMatch(/I\/O|Handling/); // Match "I/O" or "Handling"
expect(output).toContain('Buffers');
expect(output).toContain('Streams');
expect(output).toMatch(/Sec(urity)?/); // Match "Sec" or "Security"
expect(output).toContain('Vulnerable');
expect(output).toContain('Safe');
expect(output).toMatch(/Use|Case/); // Match "Use" or "Case"
expect(output).toContain('Simple');
expect(output).toContain('Long-running');
});
});
describe('Existing Functionality', () => {
it('should render headers correctly', () => {
const headerMarkdown = `
# H1 Header
## H2 Header
### H3 Header
#### H4 Header
`;
const { lastFrame } = render(
<MarkdownDisplay
text={headerMarkdown}
isPending={false}
terminalWidth={80}
/>,
);
expect(lastFrame()).toContain('H1 Header');
expect(lastFrame()).toContain('H2 Header');
expect(lastFrame()).toContain('H3 Header');
expect(lastFrame()).toContain('H4 Header');
});
it('should render code blocks correctly', () => {
const codeMarkdown = `
\`\`\`javascript
const x = 42;
console.log(x);
\`\`\`
`;
const { lastFrame } = render(
<MarkdownDisplay
text={codeMarkdown}
isPending={false}
terminalWidth={80}
/>,
);
expect(lastFrame()).toContain('const x = 42;');
expect(lastFrame()).toContain('console.log(x);');
});
});
});
|