Skip to content

Commit

Permalink
Add an instant flag to the scroll, wait for attach instead of timeout
Browse files Browse the repository at this point in the history
- Instead of using a timeout, just wait for the element to be attached. Should be more reliable
  • Loading branch information
mofojed committed Dec 31, 2024
1 parent 1f6ded2 commit 05dd721
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/console/src/Console.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ export class Console extends PureComponent<ConsoleProps, ConsoleState> {
}

window.requestAnimationFrame(() => {
pane.scrollTo({ top: pane.scrollHeight });
pane.scrollTo({ top: pane.scrollHeight, behavior: 'instant' });
});
}

Expand Down
16 changes: 12 additions & 4 deletions tests/console.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ function logMessageLocator(page: Page, text?: string): Locator {
.filter({ hasText: text });
}

function historyContentLocator(page: Page, text?: string): Locator {
return page
.locator('.console-history .console-history-content')
.filter({ hasText: text });
}

function panelTabLocator(page: Page, text: string): Locator {
return page.locator('.lm_tab .lm_title').filter({ hasText: text });
}
Expand Down Expand Up @@ -90,8 +96,9 @@ test.describe('console scroll tests', () => {
await pasteInMonaco(consoleInput, command);
await page.keyboard.press('Enter');

// Allow time for the text to colorize/render
await page.waitForTimeout(100);
await historyContentLocator(page, ids[ids.length - 1]).waitFor({
state: 'attached',
});

// Expect the console to be scrolled to the bottom
const scrollPane = await scrollPanelLocator(page);
Expand All @@ -116,8 +123,9 @@ test.describe('console scroll tests', () => {
await panelTabLocator(page, 'Log').click();

// wait for a bit for the code block to render
// Since it's in the background, we can't use the waitForSelector method. It should render in less than 1s.
await page.waitForTimeout(1000);
await historyContentLocator(page, ids[ids.length - 1]).waitFor({
state: 'attached',
});

// Switch back to the console, and expect it to be scrolled to the bottom
await panelTabLocator(page, 'Console').click();
Expand Down

0 comments on commit 05dd721

Please sign in to comment.