Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit 4404a57

Browse files
committed
tweak tests for pause points
1 parent b6083ee commit 4404a57

File tree

6 files changed

+30
-30
lines changed

6 files changed

+30
-30
lines changed

src/test/mochitest/browser_dbg-navigation.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ add_task(async function() {
4747
// Test that the current select source persists across reloads
4848
await selectSource(dbg, "long.js");
4949
await reload(dbg, "long.js");
50+
await waitForSelectedSource(dbg, "long.js");
51+
5052
ok(
5153
getSelectedSource(getState())
5254
.get("url")

src/test/mochitest/browser_dbg-pause-ux.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ add_task(async function() {
2424
let longSrc = findSource(dbg, "long.js");
2525
await addBreakpoint(dbg, longSrc, 66);
2626
invokeInTab("testModel");
27-
await waitForPaused(dbg);
27+
await waitForPaused(dbg, "long.js");
2828

2929
const pauseScrollTop = getScrollTop(dbg);
3030

src/test/mochitest/browser_dbg-reload.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ add_task(async function() {
2323
await selectSource(dbg, "sjs_code_reload");
2424
await addBreakpoint(dbg, "sjs_code_reload", 2);
2525

26-
await reload(dbg, "sjs_code_reload");
26+
await reload(dbg, "sjs_code_reload.sjs");
27+
await waitForSelectedSource(dbg, "sjs_code_reload.sjs")
2728

2829
const source = findSource(dbg, "sjs_code_reload");
2930
const location = { sourceId: source.id, line: 6 };

src/test/mochitest/browser_dbg-stepping.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,10 @@
44
// This test can be really slow on debug platforms
55
requestLongerTimeout(3);
66

7-
function assertSelectedFile(dbg, url) {
8-
const selectedLocation = dbg.selectors.getSelectedSource(dbg.getState());
9-
ok(selectedLocation, "The debugger should be at the paused location")
10-
const selectedUrl = selectedLocation.get("url");
11-
return ok( selectedUrl.includes(url), `The debugger should be paused at ${url}"`);
12-
}
13-
147
add_task(async function test() {
158
const dbg = await initDebugger("big-sourcemap.html", "big-sourcemap");
169
invokeInTab("hitDebugStatement");
17-
await waitForPaused(dbg);
18-
assertSelectedFile(dbg, "bundle.js");
10+
await waitForPaused(dbg, "bundle.js");
1911

2012
await stepIn(dbg);
2113
await stepIn(dbg);
@@ -32,7 +24,6 @@ add_task(async function test() {
3224
await stepIn(dbg);
3325
await stepIn(dbg);
3426

35-
assertSelectedFile(dbg, "bundle.js");
36-
assertDebugLine(dbg, 42309);
27+
assertDebugLine(dbg, 42264);
3728
assertPausedLocation(dbg);
3829
});

src/test/mochitest/head.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -423,21 +423,17 @@ async function waitForLoadedScopes(dbg) {
423423
* @param {Object} dbg
424424
* @static
425425
*/
426-
async function waitForPaused(dbg) {
426+
async function waitForPaused(dbg, url) {
427427
const { getSelectedScope } = dbg.selectors;
428428

429-
const onScopesLoaded = waitForLoadedScopes(dbg);
430-
const onStateChanged = waitForState(
429+
await waitForState(
431430
dbg,
432-
state => {
433-
const paused = isPaused(dbg);
434-
const scope = !!getSelectedScope(state);
435-
return paused && scope;
436-
},
431+
state => isPaused(dbg) && !!getSelectedScope(state),
437432
"paused"
438433
);
439434

440-
await Promise.all([onStateChanged, onScopesLoaded]);
435+
await waitForLoadedScopes(dbg);
436+
await waitForSelectedSource(dbg, url);
441437
}
442438

443439
/*
@@ -628,6 +624,8 @@ function closeTab(dbg, url) {
628624
* @static
629625
*/
630626
async function stepOver(dbg) {
627+
const pauseLine = getVisibleSelectedFrameLine(dbg);
628+
info(`Stepping over from ${pauseLine}`);
631629
await dbg.actions.stepOver();
632630
return waitForPaused(dbg);
633631
}
@@ -641,7 +639,8 @@ async function stepOver(dbg) {
641639
* @static
642640
*/
643641
async function stepIn(dbg) {
644-
info("Stepping in");
642+
const pauseLine = getVisibleSelectedFrameLine(dbg);
643+
info(`Stepping in from ${pauseLine}`);
645644
await dbg.actions.stepIn();
646645
return waitForPaused(dbg);
647646
}
@@ -655,7 +654,8 @@ async function stepIn(dbg) {
655654
* @static
656655
*/
657656
async function stepOut(dbg) {
658-
info("Stepping out");
657+
const pauseLine = getVisibleSelectedFrameLine(dbg);
658+
info(`Stepping out from ${pauseLine}`);
659659
await dbg.actions.stepOut();
660660
return waitForPaused(dbg);
661661
}
@@ -669,7 +669,8 @@ async function stepOut(dbg) {
669669
* @static
670670
*/
671671
function resume(dbg) {
672-
info("Resuming");
672+
const pauseLine = getVisibleSelectedFrameLine(dbg);
673+
info(`Resuming from ${pauseLine}`);
673674
return dbg.actions.resume();
674675
}
675676

src/workers/parser/pausePoints.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import { traverseAst } from "./utils/ast";
88
import * as t from "@babel/types";
99
import isEqual from "lodash/isEqual";
10+
import uniqBy from "lodash/uniqBy";
1011

1112
import type { AstLocation } from "./types";
1213
import type { BabelNode } from "@babel/types";
@@ -44,10 +45,18 @@ const inExpression = (parent, grandParent) =>
4445
const isExport = node =>
4546
t.isExportNamedDeclaration(node) || t.isExportDefaultDeclaration(node);
4647

48+
function removeDuplicatePoints(state) {
49+
return uniqBy(
50+
state,
51+
({ location }) => `${location.line}-$${location.column}`
52+
);
53+
}
54+
4755
export function getPausePoints(sourceId: string) {
4856
const state = [];
4957
traverseAst(sourceId, { enter: onEnter }, state);
50-
return state;
58+
const uniqPoints = removeDuplicatePoints(state);
59+
return uniqPoints;
5160
}
5261

5362
function onEnter(node: BabelNode, ancestors: SimplePath[], state) {
@@ -139,10 +148,6 @@ function addPoint(
139148
location,
140149
types = { breakpoint: true, stepOver: true }
141150
) {
142-
if (state.find(point => isEqual(point.location, location))) {
143-
return;
144-
}
145-
146151
state.push(formatNode(location, types));
147152
}
148153

0 commit comments

Comments
 (0)