Skip to content

Commit

Permalink
Remove breakpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
bvaughn committed Jul 8, 2024
1 parent b9563de commit fd19df6
Show file tree
Hide file tree
Showing 44 changed files with 182 additions and 890 deletions.
26 changes: 7 additions & 19 deletions packages/e2e-tests/helpers/pause-information-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ async function toggleAccordionPane(page: Page, pane: Locator, targetState: "open
}
}

export async function closeBreakpointsAccordionPane(page: Page): Promise<void> {
await toggleAccordionPane(page, getBreakpointsAccordionPane(page), "closed");
}

export async function closeCallStackAccordionPane(page: Page): Promise<void> {
await toggleAccordionPane(page, getCallStackAccordionPane(page), "closed");
}
Expand Down Expand Up @@ -49,7 +45,7 @@ export async function expandAllScopesBlocks(page: Page): Promise<void> {

export async function closeSidePanel(page: Page) {
// Ensure that it's closed by forcing the "Pause" pane to open instead...
const pane = getBreakpointsAccordionPane(page);
const pane = getPrintStatementsAccordionPane(page);
const pauseButton = page.locator('[data-test-name="ToolbarButton-PauseInformation"]');
await pauseButton.click();
const isVisible = await pane.isVisible();
Expand All @@ -58,10 +54,6 @@ export async function closeSidePanel(page: Page) {
}
}

export function getBreakpointsAccordionPane(page: Page): Locator {
return page.locator('[data-test-id="AccordionPane-Breakpoints"]');
}

export function getCallStackAccordionPane(page: Page): Locator {
return page.locator('[data-test-id="AccordionPane-CallStack"]');
}
Expand Down Expand Up @@ -110,17 +102,13 @@ export function getScopesPanel(page: Page): Locator {
return page.locator('[data-test-name="ScopesList"]');
}

export async function openBreakpointsAccordionPane(page: Page): Promise<void> {
await toggleAccordionPane(page, getBreakpointsAccordionPane(page), "open");
}

export async function openCallStackPane(page: Page): Promise<void> {
await toggleAccordionPane(page, getCallStackAccordionPane(page), "open");
}

export async function openPauseInformationPanel(page: Page): Promise<void> {
// Only click if it's not already open; clicking again will collapse the side bar.
const pane = getBreakpointsAccordionPane(page);
const pane = getPrintStatementsAccordionPane(page);

let isVisible = await pane.isVisible();
if (!isVisible) {
Expand Down Expand Up @@ -344,7 +332,7 @@ export async function waitForScopeValue(

export function findPoints(
page: Page,
type: "logpoint" | "breakpoint",
type: "logpoint",
options: {
sourceId?: SourceId;
lineNumber?: number;
Expand All @@ -354,7 +342,7 @@ export function findPoints(
const { columnIndex, lineNumber, sourceId } = options;

const selectorCriteria = [
'[data-test-name="Breakpoint"]',
'[data-test-name="LogPoint"]',
`[data-test-type="${type}"]`,
columnIndex != null ? `[data-test-column-index="${columnIndex}"]` : "",
lineNumber != null ? `[data-test-line-number="${lineNumber}"]` : "",
Expand All @@ -365,17 +353,17 @@ export function findPoints(
}

export async function isPointEditable(pointLocator: Locator) {
const editButton = pointLocator.locator('[data-test-name="RemoveBreakpointButton"]');
const editButton = pointLocator.locator('[data-test-name="RemoveLogPointButton"]');
return (await editButton.count()) > 0;
}

export async function removePoint(pointLocator: Locator) {
await pointLocator.locator('[data-test-name="RemoveBreakpointButton"]').first().click();
await pointLocator.locator('[data-test-name="RemoveLogPointButton"]').first().click();
}

export async function togglePoint(page: Page, pointLocator: Locator, enabled: boolean) {
const targetState = enabled ? POINT_BEHAVIOR_ENABLED : POINT_BEHAVIOR_DISABLED_TEMPORARILY;
const toggle = pointLocator.locator('[data-test-name="BreakpointToggle"]');
const toggle = pointLocator.locator('[data-test-name="LogPointToggle"]');
const currentState = await toggle.getAttribute("date-test-state");
if (targetState !== currentState) {
await debugPrint(page, `Toggling point to ${targetState}`, "togglePoint");
Expand Down
154 changes: 4 additions & 150 deletions packages/e2e-tests/helpers/source-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,12 @@ import chalk from "chalk";

import { Badge } from "shared/client/types";

import { clearText, focus, hideTypeAheadSuggestions, typeLogPoint as typeLexical } from "./lexical";
import { focus, hideTypeAheadSuggestions, typeLogPoint as typeLexical } from "./lexical";
import { findPoints, openPauseInformationPanel, removePoint } from "./pause-information-panel";
import { openSource } from "./source-explorer-panel";
import { clearTextArea, debugPrint, delay, getByTestName, getCommandKey, waitFor } from "./utils";
import { clearTextArea, debugPrint, getByTestName, getCommandKey, waitFor } from "./utils";
import { openDevToolsTab } from ".";

export async function addBreakpoint(
page: Page,
options: {
columnIndex?: number;
lineNumber: number;
url: string;
}
): Promise<void> {
const { lineNumber, url } = options;

await openDevToolsTab(page);

if (url) {
await openSource(page, url);
}

await debugPrint(
page,
`Adding breakpoint at ${chalk.bold(`${url}:${lineNumber}`)}`,
"addBreakpoint"
);

await scrollUntilLineIsVisible(page, lineNumber);
await waitForSourceLineHitCounts(page, lineNumber);

const lineLocator = await getSourceLine(page, lineNumber);

// Account for the fact that SourceListRow doesn't render SourceListRowMouseEvents while scrolling
await waitFor(async () => {
const isScrolling = await lineLocator.getAttribute("data-test-is-scrolling");
expect(isScrolling).toBe(null);
});

const lineNumberLocator = lineLocator.locator('[data-test-name="SourceLine-LineNumber"]');
await lineNumberLocator.waitFor();

const breakpointToggleLocator = lineLocator.locator('[data-test-name="BreakpointToggle"]');

await waitFor(async () => {
// Mouse out then back over
await page.mouse.move(0, 0);
await lineNumberLocator.hover({ force: true });

// Wait for breakpoint toggle from mouse over
await breakpointToggleLocator.waitFor();

const state = await breakpointToggleLocator.getAttribute("data-test-state");
if (state === "off") {
await lineLocator.locator('[data-test-name="SourceLine-LineNumber"]').click({ force: true });
}
});

await waitForBreakpoint(page, options);

// We want to add a slight delay after adding a breakpoint so that the
// breakpoint logic will have time to send protocol commands to the server,
// since that is not guaranteed to happen synchronously on click. This is
// important for cases where we add a breakpoint and then immediately
// attempt to step to the breakpoint location.
await delay(2000);
}

export async function editBadge(
page: Page,
options: {
Expand Down Expand Up @@ -514,20 +452,8 @@ export async function openLogPointPanelContextMenu(
}
}

export async function removeAllBreakpoints(page: Page): Promise<void> {
await debugPrint(page, `Removing all breakpoints for the current source`, "removeBreakpoint");

await openPauseInformationPanel(page);
const points = await findPoints(page, "breakpoint");
const count = await points.count();
for (let index = count - 1; index >= 0; index--) {
const point = points.nth(index);
await removePoint(point);
}
}

export async function removeAllLogpoints(page: Page): Promise<void> {
await debugPrint(page, `Removing all breakpoints for the current source`, "removeBreakpoint");
await debugPrint(page, `Removing all logpoints for the current source`, "removeAllLogpoints");

await openPauseInformationPanel(page);
const points = await findPoints(page, "logpoint");
Expand All @@ -538,45 +464,6 @@ export async function removeAllLogpoints(page: Page): Promise<void> {
}
}

export async function removeBreakpoint(
page: Page,
options: {
lineNumber: number;
url: string;
}
): Promise<void> {
const { lineNumber, url } = options;

await debugPrint(
page,
`Removing breakpoint at ${chalk.bold(`${url}:${lineNumber}`)}`,
"removeBreakpoint"
);

await openDevToolsTab(page);

if (url) {
await openSource(page, url);
}

const lineLocator = await getSourceLine(page, lineNumber);
const numberLocator = lineLocator.locator(`[data-test-name="SourceLine-LineNumber"]`);
await numberLocator.hover({ force: true });
const state = await lineLocator
.locator('[data-test-name="BreakpointToggle"]')
.getAttribute("data-test-state");
if (state !== "off") {
await numberLocator.click({ force: true });
}

// We want to add a slight delay after removing a breakpoint so that the
// breakpoint logic will have time to send protocol commands to the server,
// since that is not guaranteed to happen synchronously on click. This is
// important for cases where we remove a breakpoint and then immediately
// attempt to step across the breakpoint location.
await delay(1000);
}

export async function removeConditional(
page: Page,
options: {
Expand Down Expand Up @@ -698,39 +585,6 @@ export async function toggleMappedSources(page: Page, targetState: "on" | "off")
}
}

export async function waitForBreakpoint(
page: Page,
options: {
columnIndex?: number;
lineNumber: number;
url: string;
}
): Promise<void> {
const { columnIndex, lineNumber, url } = options;

await debugPrint(
page,
`Waiting for breakpoint at ${chalk.bold(`${url}:${lineNumber}`)}`,
"waitForBreakpoint"
);

await openPauseInformationPanel(page);

const breakpointGroup = await page.waitForSelector(
`[data-test-name="BreakpointsList"]:has-text("${url}")`
);

if (columnIndex != null) {
await breakpointGroup.waitForSelector(
`[data-test-name="PointLocation"]:has-text("${lineNumber}:${columnIndex}")`
);
} else {
await breakpointGroup.waitForSelector(
`[data-test-name="PointLocation"]:has-text("${lineNumber}")`
);
}
}

export async function waitForLogpoint(
page: Page,
options: {
Expand Down Expand Up @@ -775,7 +629,7 @@ export async function verifyLogpointStep(

await debugPrint(
page,
`Verifying breakpoint status "${chalk.bold(expectedStatus)}" for line ${chalk.bold(
`Verifying logpoint status "${chalk.bold(expectedStatus)}" for line ${chalk.bold(
options.lineNumber
)}`,
"verifyLogpointStep"
Expand Down
3 changes: 1 addition & 2 deletions packages/e2e-tests/tests/logpoints-01.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
verifyLogpointBadge,
} from "../helpers/console-panel";
import { reverseStepOverToLine } from "../helpers/pause-information-panel";
import { addBreakpoint, addLogpoint } from "../helpers/source-panel";
import { addLogpoint } from "../helpers/source-panel";
import { waitFor } from "../helpers/utils";
import test, { expect } from "../testFixture";

Expand All @@ -21,7 +21,6 @@ test(`logpoints-01: log-points appear in the correct order and allow time warpin
await startTest(page, recordingId, testScope);
await openDevToolsTab(page);

await addBreakpoint(page, { lineNumber: 20, url: exampleKey });
await addLogpoint(page, {
content: '"Logpoint Number " + number',
lineNumber: 20,
Expand Down
35 changes: 14 additions & 21 deletions packages/e2e-tests/tests/node_control_flow.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { startTest } from "../helpers";
import { openSource } from "../helpers/source-explorer-panel";
import { addBreakpoint, fastForwardToLine, rewindToLine } from "../helpers/source-panel";
import test, { Page } from "../testFixture";

async function resumeToBreakpoint(page: Page, line: number) {
await addBreakpoint(page, { url: "control_flow.js", lineNumber: line });
await fastForwardToLine(page, { lineNumber: line });
}
import { fastForwardToLine, rewindToLine } from "../helpers/source-panel";
import test from "../testFixture";

test.use({ exampleKey: "node/control_flow.js" });

Expand All @@ -22,20 +17,18 @@ test("node_control_flow: catch, finally, generators, and async/await", async ({

await rewindToLine(page, { lineNumber: 84 });

await resumeToBreakpoint(page, 10);
await resumeToBreakpoint(page, 12);
await resumeToBreakpoint(page, 18);
await resumeToBreakpoint(page, 20);
await resumeToBreakpoint(page, 32);
await resumeToBreakpoint(page, 27);

await fastForwardToLine(page, { lineNumber: 10 });
await fastForwardToLine(page, { lineNumber: 12 });
await fastForwardToLine(page, { lineNumber: 18 });
await fastForwardToLine(page, { lineNumber: 20 });
await fastForwardToLine(page, { lineNumber: 32 });
await fastForwardToLine(page, { lineNumber: 27 });

await resumeToBreakpoint(page, 42);
await resumeToBreakpoint(page, 44);
await resumeToBreakpoint(page, 50);
await resumeToBreakpoint(page, 54);
await resumeToBreakpoint(page, 65);
await resumeToBreakpoint(page, 72);
await fastForwardToLine(page, { lineNumber: 32 });
await fastForwardToLine(page, { lineNumber: 27 });
await fastForwardToLine(page, { lineNumber: 42 });
await fastForwardToLine(page, { lineNumber: 44 });
await fastForwardToLine(page, { lineNumber: 50 });
await fastForwardToLine(page, { lineNumber: 54 });
await fastForwardToLine(page, { lineNumber: 65 });
await fastForwardToLine(page, { lineNumber: 72 });
});
6 changes: 1 addition & 5 deletions packages/e2e-tests/tests/node_worker-01.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { startTest } from "../helpers";
import { openConsolePanel, warpToMessage } from "../helpers/console-panel";
import { stepOverToLine } from "../helpers/pause-information-panel";
import { addBreakpoint, rewindToLine } from "../helpers/source-panel";
import { rewindToLine } from "../helpers/source-panel";
import test from "../testFixture";

test.use({ exampleKey: "node/run_worker.js" });
Expand All @@ -16,10 +16,6 @@ test("node_worker-01: make sure node workers don't cause crashes", async ({

await warpToMessage(page, "GotWorkerMessage pong");
await stepOverToLine(page, 18);

await addBreakpoint(page, { url: "run_worker.js", lineNumber: 13 });
await rewindToLine(page, { lineNumber: 13 });

await addBreakpoint(page, { url: "run_worker.js", lineNumber: 6 });
await rewindToLine(page, { lineNumber: 6 });
});
2 changes: 0 additions & 2 deletions packages/e2e-tests/tests/object_preview-02.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { openDevToolsTab, startTest } from "../helpers";
import { waitForTerminal, warpToMessage } from "../helpers/console-panel";
import {
closeBreakpointsAccordionPane,
closeCallStackAccordionPane,
closePrintStatementsAccordionPane,
getScopeChildren,
Expand All @@ -25,7 +24,6 @@ test(`object_preview-02: should allow objects in scope to be inspected`, async (

await openPauseInformationPanel(page);

await closeBreakpointsAccordionPane(page);
await closePrintStatementsAccordionPane(page);
await closeCallStackAccordionPane(page);
await openScopesAccordionPane(page);
Expand Down
Loading

0 comments on commit fd19df6

Please sign in to comment.