Skip to content

Commit 812d22e

Browse files
loganfsmythjasonLaster
authored andcommitted
Add initial mochitest for original scope work and fix disabled tests (firefox-devtools#5317)
1 parent c8ebc9d commit 812d22e

16 files changed

Lines changed: 328 additions & 91 deletions

File tree

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
src/workers/parser/tests/fixtures/functionNames.js
2+
src/test/mochitest/examples/babel/fixtures/*/output.js
3+
src/test/mochitest/examples/babel/fixtures/*/output.js.map

src/actions/pause/mapScopes.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,20 @@ async function findGeneratedBinding(
227227
return null;
228228
}
229229

230-
return generatedAstBindings.find(
231-
val =>
232-
val.loc.start.line === gen.line && val.loc.start.column === gen.column
233-
);
230+
return generatedAstBindings.find(val => {
231+
if (val.loc.start.line !== gen.line) {
232+
return false;
233+
}
234+
235+
// Allow the mapping to point anywhere within the generated binding
236+
// location to allow for less than perfect sourcemaps. Since you also
237+
// need at least one character between identifiers, we also give one
238+
// characters of space at the front the generated binding in order
239+
// to increase the probability of finding the right mapping.
240+
const start = val.loc.start.column - 1;
241+
const end = val.loc.end.column;
242+
return gen.column >= start && gen.column <= end;
243+
});
234244
}, null);
235245

236246
if (genContent && genContent.desc) {

src/components/ShortcutsModal.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ export class ShortcutsModal extends Component<Props> {
8686
L10N.getStr("shortcuts.functionSearch"),
8787
formatKeyShortcut(L10N.getStr("functionSearch.key"))
8888
)}
89-
{this.renderShorcutItem(
90-
L10N.getStr("shortcuts.gotoLine"),
91-
formatKeyShortcut(L10N.getStr("gotoLineModal.key"))
92-
)}
89+
{this.renderShorcutItem(
90+
L10N.getStr("shortcuts.gotoLine"),
91+
formatKeyShortcut(L10N.getStr("gotoLineModal.key"))
92+
)}
9393
</ul>
9494
);
9595
}

src/components/shared/ManagedTree.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
display: grid;
1717
grid-template-columns: 1fr;
1818
align-content: start;
19-
2019
}
2120

2221
.managed-tree .tree button {

src/test/mochitest/browser.ini

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ support-files =
66
head.js
77
!/devtools/client/commandline/test/helpers.js
88
!/devtools/client/framework/test/shared-head.js
9+
examples/babel/fixtures/for-of/output.js
10+
examples/babel/fixtures/for-of/output.js.map
911
examples/sourcemaps/bundle.js
1012
examples/sourcemaps/bundle.js.map
1113
examples/sourcemaps2/main.min.js
@@ -37,6 +39,7 @@ support-files =
3739
examples/reload/sjs_code_reload.sjs
3840
examples/doc-async.html
3941
examples/doc-asm.html
42+
examples/doc-babel.html
4043
examples/doc-content-script-sources.html
4144
examples/doc-scripts.html
4245
examples/doc-script-mutate.html
@@ -75,6 +78,7 @@ support-files =
7578

7679
[browser_dbg-asm.js]
7780
[browser_dbg-async-stepping.js]
81+
[browser_dbg-babel-for-of.js]
7882
[browser_dbg-breaking.js]
7983
[browser_dbg-breaking-from-console.js]
8084
[browser_dbg-breakpoints.js]
@@ -108,7 +112,6 @@ skip-if = os == "linux" # bug 1351952
108112
skip-if = os == "win"
109113
[browser_dbg-navigation.js]
110114
[browser_dbg-minified.js]
111-
skip-if = true
112115
[browser_dbg-pretty-print.js]
113116
[browser_dbg-pretty-print-console.js]
114117
[browser_dbg-pretty-print-paused.js]
@@ -128,7 +131,6 @@ skip-if = true # regular failures during release in Bug 1415300
128131
[browser_dbg-sourcemaps-reloading.js]
129132
[browser_dbg-sourcemaps2.js]
130133
[browser_dbg-sourcemaps3.js]
131-
skip-if = true
132134
[browser_dbg-sourcemaps-bogus.js]
133135
[browser_dbg-sources.js]
134136
[browser_dbg-sources-named-eval.js]
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* Any copyright is dedicated to the Public Domain.
2+
* http://creativecommons.org/publicdomain/zero/1.0/ */
3+
4+
// Tests loading sourcemapped sources for Babel's compile for..of output.
5+
6+
add_task(async function() {
7+
await pushPref("devtools.debugger.features.map-scopes", true);
8+
9+
const dbg = await initDebugger("doc-babel.html");
10+
const { selectors: { getBreakpoint, getBreakpoints }, getState } = dbg;
11+
12+
await waitForSources(dbg, "fixtures/for-of/input.js");
13+
14+
ok(true, "Original sources exist");
15+
const sortedSrc = findSource(dbg, "fixtures/for-of/input.js");
16+
17+
await selectSource(dbg, sortedSrc);
18+
19+
// Test that breakpoint is not off by a line.
20+
await addBreakpoint(dbg, sortedSrc, 5);
21+
is(getBreakpoints(getState()).size, 1, "One breakpoint exists");
22+
ok(
23+
getBreakpoint(getState(), { sourceId: sortedSrc.id, line: 5, column: 4 }),
24+
"Breakpoint has correct line"
25+
);
26+
27+
invokeInTab("forOf");
28+
29+
await waitForPaused(dbg);
30+
31+
assertPausedLocation(dbg);
32+
33+
is(getScopeLabel(dbg, 1), "For");
34+
is(getScopeLabel(dbg, 2), "x");
35+
is(getScopeValue(dbg, 2), "1");
36+
37+
is(getScopeLabel(dbg, 3), "forOf");
38+
39+
await toggleScopeNode(dbg, 3);
40+
41+
is(getScopeLabel(dbg, 4), "doThing()");
42+
43+
is(getScopeLabel(dbg, 5), "Module");
44+
45+
await toggleScopeNode(dbg, 5);
46+
47+
is(getScopeLabel(dbg, 6), "forOf");
48+
is(getScopeLabel(dbg, 7), "mod");
49+
});

src/test/mochitest/browser_dbg-minified.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,11 @@ add_task(async function() {
2323

2424
invokeInTab("test");
2525
await waitForPaused(dbg);
26-
await waitForMappedScopes(dbg);
2726

2827
is(getScopeNodeLabel(dbg, 1), "sum", "check scope label");
29-
is(getScopeNodeLabel(dbg, 2), "<this>", "check scope label");
30-
is(getScopeNodeLabel(dbg, 3), "arguments", "check scope label");
31-
32-
is(getScopeNodeLabel(dbg, 4), "first", "check scope label");
33-
is(getScopeNodeValue(dbg, 4), "40", "check scope value");
34-
is(getScopeNodeLabel(dbg, 5), "second", "check scope label");
35-
is(getScopeNodeValue(dbg, 5), "2", "check scope value");
28+
is(getScopeNodeLabel(dbg, 2), "first", "check scope label");
29+
is(getScopeNodeValue(dbg, 2), "40", "check scope value");
30+
is(getScopeNodeLabel(dbg, 3), "second", "check scope label");
31+
is(getScopeNodeValue(dbg, 3), "2", "check scope value");
32+
is(getScopeNodeLabel(dbg, 4), "Window", "check scope label");
3633
});

src/test/mochitest/browser_dbg-sourcemaps3.js

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,6 @@
44
// Tests loading sourcemapped sources, setting breakpoints, and
55
// inspecting restored scopes.
66

7-
function toggleNode(dbg, index) {
8-
clickElement(dbg, "scopeNode", index);
9-
}
10-
11-
function getLabel(dbg, index) {
12-
return findElement(dbg, "scopeNode", index).innerText;
13-
}
14-
15-
function hasScopeNode(dbg, index) {
16-
return !!findElement(dbg, "scopeNode", index);
17-
}
18-
19-
async function waitForScopeNode(dbg, index) {
20-
const selector = getSelector("scopeNode", index);
21-
return waitForElementWithSelector(dbg, selector);
22-
}
23-
247
// This source map does not have source contents, so it's fetched separately
258
add_task(async function() {
269
// NOTE: the CORS call makes the test run times inconsistent
@@ -50,36 +33,27 @@ add_task(async function() {
5033
await waitForPaused(dbg);
5134
assertPausedLocation(dbg);
5235

53-
await waitForDispatch(dbg, "MAP_SCOPES");
36+
is(getScopeLabel(dbg, 1), "Block");
37+
is(getScopeLabel(dbg, 2), "na");
38+
is(getScopeLabel(dbg, 3), "nb");
5439

55-
is(getLabel(dbg, 1), "Block");
56-
is(getLabel(dbg, 2), "<this>");
57-
is(getLabel(dbg, 3), "na");
58-
is(getLabel(dbg, 4), "nb");
40+
is(getScopeLabel(dbg, 4), "Block");
5941

60-
is(getLabel(dbg, 5), "Block");
61-
is(
62-
hasScopeNode(dbg, 8) && !hasScopeNode(dbg, 9),
63-
true,
64-
"scope count before expand"
65-
);
66-
toggleNode(dbg, 5);
42+
await toggleScopeNode(dbg, 4);
6743

68-
await waitForScopeNode(dbg, 9);
44+
is(getScopeLabel(dbg, 5), "ma");
45+
is(getScopeLabel(dbg, 6), "mb");
6946

70-
is(getLabel(dbg, 6), "ma");
71-
is(getLabel(dbg, 7), "mb");
47+
await toggleScopeNode(dbg, 7);
7248

73-
is(
74-
hasScopeNode(dbg, 10) && !hasScopeNode(dbg, 11),
75-
true,
76-
"scope count before expand"
77-
);
78-
toggleNode(dbg, 8);
49+
is(getScopeLabel(dbg, 8), "a");
50+
is(getScopeLabel(dbg, 9), "b");
51+
52+
is(getScopeLabel(dbg, 10), "Module");
7953

80-
await waitForScopeNode(dbg, 11);
54+
await toggleScopeNode(dbg, 10);
8155

82-
is(getLabel(dbg, 9), "a");
83-
is(getLabel(dbg, 10), "arguments");
84-
is(getLabel(dbg, 11), "b");
56+
is(getScopeLabel(dbg, 11), "binaryLookup:o()");
57+
is(getScopeLabel(dbg, 12), "comparer:t()");
58+
is(getScopeLabel(dbg, 13), "fancySort");
8559
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const mod = "module scoped";
2+
3+
export default function forOf() {
4+
for (const x of [1]) {
5+
doThing(x);
6+
}
7+
8+
function doThing(arg) {}
9+
}

src/test/mochitest/examples/babel/fixtures/for-of/output.js

Lines changed: 94 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)