test(cli): refactor tests for async render utilities (#23252)

This commit is contained in:
Tommaso Sciortino
2026-03-20 20:08:29 +00:00
committed by GitHub
parent 86a3a913b5
commit 6c78eb7a39
198 changed files with 3592 additions and 4802 deletions

View File

@@ -35,10 +35,7 @@ describe('colorizeCode', () => {
hideLineNumbers: true,
});
const { lastFrame, waitUntilReady, unmount } = await renderWithProviders(
<>{result}</>,
);
await waitUntilReady();
const { lastFrame, unmount } = await renderWithProviders(<>{result}</>);
// We expect the output to preserve the empty line.
// If the bug exists, it might look like "line 1\nline 3"
// If fixed, it should look like "line 1\n \nline 3" (if we use space) or just have the newline.

View File

@@ -21,20 +21,18 @@ describe('<MarkdownDisplay />', () => {
});
it('renders nothing for empty text', async () => {
const { lastFrame, waitUntilReady, unmount } = await renderWithProviders(
const { lastFrame, unmount } = await renderWithProviders(
<MarkdownDisplay {...baseProps} text="" />,
);
await waitUntilReady();
expect(lastFrame({ allowEmpty: true })).toMatchSnapshot();
unmount();
});
it('renders a simple paragraph', async () => {
const text = 'Hello, world.';
const { lastFrame, waitUntilReady, unmount } = await renderWithProviders(
const { lastFrame, unmount } = await renderWithProviders(
<MarkdownDisplay {...baseProps} text={text} />,
);
await waitUntilReady();
expect(lastFrame()).toMatchSnapshot();
unmount();
});
@@ -52,10 +50,9 @@ describe('<MarkdownDisplay />', () => {
### Header 3
#### Header 4
`.replace(/\n/g, eol);
const { lastFrame, waitUntilReady, unmount } = await renderWithProviders(
const { lastFrame, unmount } = await renderWithProviders(
<MarkdownDisplay {...baseProps} text={text} />,
);
await waitUntilReady();
expect(lastFrame()).toMatchSnapshot();
unmount();
});
@@ -65,30 +62,27 @@ describe('<MarkdownDisplay />', () => {
/\n/g,
eol,
);
const { lastFrame, waitUntilReady, unmount } = await renderWithProviders(
const { lastFrame, unmount } = await renderWithProviders(
<MarkdownDisplay {...baseProps} text={text} />,
);
await waitUntilReady();
expect(lastFrame()).toMatchSnapshot();
unmount();
});
it('renders a fenced code block without a language', async () => {
const text = '```\nplain text\n```'.replace(/\n/g, eol);
const { lastFrame, waitUntilReady, unmount } = await renderWithProviders(
const { lastFrame, unmount } = await renderWithProviders(
<MarkdownDisplay {...baseProps} text={text} />,
);
await waitUntilReady();
expect(lastFrame()).toMatchSnapshot();
unmount();
});
it('handles unclosed (pending) code blocks', async () => {
const text = '```typescript\nlet y = 2;'.replace(/\n/g, eol);
const { lastFrame, waitUntilReady, unmount } = await renderWithProviders(
const { lastFrame, unmount } = await renderWithProviders(
<MarkdownDisplay {...baseProps} text={text} isPending={true} />,
);
await waitUntilReady();
expect(lastFrame()).toMatchSnapshot();
unmount();
});
@@ -99,10 +93,9 @@ describe('<MarkdownDisplay />', () => {
* item B
+ item C
`.replace(/\n/g, eol);
const { lastFrame, waitUntilReady, unmount } = await renderWithProviders(
const { lastFrame, unmount } = await renderWithProviders(
<MarkdownDisplay {...baseProps} text={text} />,
);
await waitUntilReady();
expect(lastFrame()).toMatchSnapshot();
unmount();
});
@@ -113,10 +106,9 @@ describe('<MarkdownDisplay />', () => {
* Level 2
* Level 3
`.replace(/\n/g, eol);
const { lastFrame, waitUntilReady, unmount } = await renderWithProviders(
const { lastFrame, unmount } = await renderWithProviders(
<MarkdownDisplay {...baseProps} text={text} />,
);
await waitUntilReady();
expect(lastFrame()).toMatchSnapshot();
unmount();
});
@@ -126,10 +118,9 @@ describe('<MarkdownDisplay />', () => {
1. First item
2. Second item
`.replace(/\n/g, eol);
const { lastFrame, waitUntilReady, unmount } = await renderWithProviders(
const { lastFrame, unmount } = await renderWithProviders(
<MarkdownDisplay {...baseProps} text={text} />,
);
await waitUntilReady();
expect(lastFrame()).toMatchSnapshot();
unmount();
});
@@ -142,10 +133,9 @@ World
***
Test
`.replace(/\n/g, eol);
const { lastFrame, waitUntilReady, unmount } = await renderWithProviders(
const { lastFrame, unmount } = await renderWithProviders(
<MarkdownDisplay {...baseProps} text={text} />,
);
await waitUntilReady();
expect(lastFrame()).toMatchSnapshot();
unmount();
});
@@ -157,10 +147,9 @@ Test
| Cell 1 | Cell 2 |
| Cell 3 | Cell 4 |
`.replace(/\n/g, eol);
const { lastFrame, waitUntilReady, unmount } = await renderWithProviders(
const { lastFrame, unmount } = await renderWithProviders(
<MarkdownDisplay {...baseProps} text={text} />,
);
await waitUntilReady();
expect(lastFrame()).toMatchSnapshot();
unmount();
});
@@ -171,10 +160,9 @@ Some text before.
| A | B |
|---|
| 1 | 2 |`.replace(/\n/g, eol);
const { lastFrame, waitUntilReady, unmount } = await renderWithProviders(
const { lastFrame, unmount } = await renderWithProviders(
<MarkdownDisplay {...baseProps} text={text} />,
);
await waitUntilReady();
expect(lastFrame()).toMatchSnapshot();
unmount();
});
@@ -183,10 +171,9 @@ Some text before.
const text = `Paragraph 1.
Paragraph 2.`.replace(/\n/g, eol);
const { lastFrame, waitUntilReady, unmount } = await renderWithProviders(
const { lastFrame, unmount } = await renderWithProviders(
<MarkdownDisplay {...baseProps} text={text} />,
);
await waitUntilReady();
expect(lastFrame()).toMatchSnapshot();
unmount();
});
@@ -206,10 +193,9 @@ some code
Another paragraph.
`.replace(/\n/g, eol);
const { lastFrame, waitUntilReady, unmount } = await renderWithProviders(
const { lastFrame, unmount } = await renderWithProviders(
<MarkdownDisplay {...baseProps} text={text} />,
);
await waitUntilReady();
expect(lastFrame()).toMatchSnapshot();
unmount();
});
@@ -229,11 +215,10 @@ Another paragraph.
[],
);
const { lastFrame, waitUntilReady, unmount } = await renderWithProviders(
const { lastFrame, unmount } = await renderWithProviders(
<MarkdownDisplay {...baseProps} text={text} />,
{ settings },
);
await waitUntilReady();
expect(lastFrame()).toMatchSnapshot();
expect(lastFrame()).not.toContain('1 const x = 1;');
unmount();
@@ -241,10 +226,9 @@ Another paragraph.
it('shows line numbers in code blocks by default', async () => {
const text = '```javascript\nconst x = 1;\n```'.replace(/\n/g, eol);
const { lastFrame, waitUntilReady, unmount } = await renderWithProviders(
const { lastFrame, unmount } = await renderWithProviders(
<MarkdownDisplay {...baseProps} text={text} />,
);
await waitUntilReady();
expect(lastFrame()).toMatchSnapshot();
expect(lastFrame()).toContain('1 const x = 1;');
unmount();

View File

@@ -24,9 +24,7 @@ describe('TableRenderer', () => {
terminalWidth={terminalWidth}
/>,
);
const { lastFrame, waitUntilReady, unmount } = renderResult;
await waitUntilReady();
const { lastFrame, unmount } = renderResult;
const output = lastFrame();
expect(output).toContain('Header 1');
expect(output).toContain('Row 1, Col 1');
@@ -56,9 +54,7 @@ describe('TableRenderer', () => {
terminalWidth={terminalWidth}
/>,
);
const { lastFrame, waitUntilReady, unmount } = renderResult;
await waitUntilReady();
const { lastFrame, unmount } = renderResult;
const output = lastFrame();
// Since terminalWidth is 80 and headers are long, they might be truncated.
// We just check for some of the content.
@@ -86,9 +82,7 @@ describe('TableRenderer', () => {
terminalWidth={terminalWidth}
/>,
);
const { lastFrame, waitUntilReady, unmount } = renderResult;
await waitUntilReady();
const { lastFrame, unmount } = renderResult;
const output = lastFrame();
expect(output).toContain('This is a very');
expect(output).toContain('long cell');
@@ -114,9 +108,7 @@ describe('TableRenderer', () => {
terminalWidth={terminalWidth}
/>,
);
const { lastFrame, waitUntilReady, unmount } = renderResult;
await waitUntilReady();
const { lastFrame, unmount } = renderResult;
const output = lastFrame();
expect(output).toContain('wrapping in');
await expect(renderResult).toMatchSvgSnapshot();
@@ -141,9 +133,7 @@ describe('TableRenderer', () => {
terminalWidth={terminalWidth}
/>,
);
const { lastFrame, waitUntilReady, unmount } = renderResult;
await waitUntilReady();
const { lastFrame, unmount } = renderResult;
const output = lastFrame();
expect(output).toContain('Tiny');
expect(output).toContain('definitely needs');
@@ -170,9 +160,7 @@ describe('TableRenderer', () => {
terminalWidth={terminalWidth}
/>,
);
const { lastFrame, waitUntilReady, unmount } = renderResult;
await waitUntilReady();
const { lastFrame, unmount } = renderResult;
const output = lastFrame();
expect(output).toContain('Start. Stop.');
await expect(renderResult).toMatchSvgSnapshot();
@@ -191,9 +179,7 @@ describe('TableRenderer', () => {
terminalWidth={terminalWidth}
/>,
);
const { lastFrame, waitUntilReady, unmount } = renderResult;
await waitUntilReady();
const { lastFrame, unmount } = renderResult;
const output = lastFrame();
// The output should NOT contain the literal '**'
expect(output).not.toContain('**Bold Header**');
@@ -218,9 +204,7 @@ describe('TableRenderer', () => {
terminalWidth={terminalWidth}
/>,
);
const { lastFrame, waitUntilReady, unmount } = renderResult;
await waitUntilReady();
const { lastFrame, unmount } = renderResult;
const output = lastFrame();
// Markers should be gone
expect(output).not.toContain('**');
@@ -263,9 +247,7 @@ describe('TableRenderer', () => {
/>,
{ width: terminalWidth },
);
const { lastFrame, waitUntilReady, unmount } = renderResult;
await waitUntilReady();
const { lastFrame, unmount } = renderResult;
const output = lastFrame();
expect(output).toContain('Comprehensive Architectural');
expect(output).toContain('protocol buffers');
@@ -333,9 +315,7 @@ describe('TableRenderer', () => {
/>,
{ width: terminalWidth },
);
const { lastFrame, waitUntilReady, unmount } = renderResult;
await waitUntilReady();
const { lastFrame, unmount } = renderResult;
const output = lastFrame();
expected.forEach((text) => {
expect(output).toContain(text);
@@ -367,9 +347,7 @@ describe('TableRenderer', () => {
terminalWidth={terminalWidth}
/>,
);
const { lastFrame, waitUntilReady, unmount } = renderResult;
await waitUntilReady();
const { lastFrame, unmount } = renderResult;
const output = lastFrame();
expected.forEach((text) => {
expect(output).toContain(text);
@@ -496,8 +474,7 @@ describe('TableRenderer', () => {
/>,
{ width: terminalWidth },
);
const { lastFrame, waitUntilReady, unmount } = renderResult;
await waitUntilReady();
const { lastFrame, unmount } = renderResult;
const output = lastFrame();
expect(output).toBeDefined();