summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/src/selectors/test
diff options
context:
space:
mode:
Diffstat (limited to 'devtools/client/debugger/src/selectors/test')
-rw-r--r--devtools/client/debugger/src/selectors/test/__snapshots__/visibleColumnBreakpoints.spec.js.snap165
-rw-r--r--devtools/client/debugger/src/selectors/test/getCallStackFrames.spec.js166
-rw-r--r--devtools/client/debugger/src/selectors/test/visibleColumnBreakpoints.spec.js145
3 files changed, 476 insertions, 0 deletions
diff --git a/devtools/client/debugger/src/selectors/test/__snapshots__/visibleColumnBreakpoints.spec.js.snap b/devtools/client/debugger/src/selectors/test/__snapshots__/visibleColumnBreakpoints.spec.js.snap
new file mode 100644
index 0000000000..845d228d41
--- /dev/null
+++ b/devtools/client/debugger/src/selectors/test/__snapshots__/visibleColumnBreakpoints.spec.js.snap
@@ -0,0 +1,165 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`visible column breakpoints doesnt show breakpoints to the right 1`] = `
+Array [
+ Object {
+ "breakpoint": Object {
+ "disabled": false,
+ "generatedLocation": Object {
+ "column": 1,
+ "line": 1,
+ "source": Object {
+ "id": "foo",
+ },
+ "sourceId": "foo",
+ },
+ "id": "breakpoint",
+ "location": Object {
+ "column": 1,
+ "line": 1,
+ "source": Object {
+ "id": "foo",
+ },
+ "sourceId": "foo",
+ },
+ "options": Object {},
+ "originalText": "text",
+ "text": "text",
+ },
+ "location": Object {
+ "column": 1,
+ "line": 1,
+ "sourceId": "foo",
+ },
+ },
+]
+`;
+
+exports[`visible column breakpoints ignores single breakpoints 1`] = `
+Array [
+ Object {
+ "breakpoint": Object {
+ "disabled": false,
+ "generatedLocation": Object {
+ "column": 1,
+ "line": 1,
+ "source": Object {
+ "id": "foo",
+ },
+ "sourceId": "foo",
+ },
+ "id": "breakpoint",
+ "location": Object {
+ "column": 1,
+ "line": 1,
+ "source": Object {
+ "id": "foo",
+ },
+ "sourceId": "foo",
+ },
+ "options": Object {},
+ "originalText": "text",
+ "text": "text",
+ },
+ "location": Object {
+ "column": 1,
+ "line": 1,
+ "sourceId": "foo",
+ },
+ },
+ Object {
+ "breakpoint": null,
+ "location": Object {
+ "column": 3,
+ "line": 1,
+ "sourceId": "foo",
+ },
+ },
+]
+`;
+
+exports[`visible column breakpoints only shows visible breakpoints 1`] = `
+Array [
+ Object {
+ "breakpoint": Object {
+ "disabled": false,
+ "generatedLocation": Object {
+ "column": 1,
+ "line": 1,
+ "source": Object {
+ "id": "foo",
+ },
+ "sourceId": "foo",
+ },
+ "id": "breakpoint",
+ "location": Object {
+ "column": 1,
+ "line": 1,
+ "source": Object {
+ "id": "foo",
+ },
+ "sourceId": "foo",
+ },
+ "options": Object {},
+ "originalText": "text",
+ "text": "text",
+ },
+ "location": Object {
+ "column": 1,
+ "line": 1,
+ "sourceId": "foo",
+ },
+ },
+ Object {
+ "breakpoint": null,
+ "location": Object {
+ "column": 3,
+ "line": 1,
+ "sourceId": "foo",
+ },
+ },
+]
+`;
+
+exports[`visible column breakpoints simple 1`] = `
+Array [
+ Object {
+ "breakpoint": Object {
+ "disabled": false,
+ "generatedLocation": Object {
+ "column": 1,
+ "line": 1,
+ "source": Object {
+ "id": "foo",
+ },
+ "sourceId": "foo",
+ },
+ "id": "breakpoint",
+ "location": Object {
+ "column": 1,
+ "line": 1,
+ "source": Object {
+ "id": "foo",
+ },
+ "sourceId": "foo",
+ },
+ "options": Object {},
+ "originalText": "text",
+ "text": "text",
+ },
+ "location": Object {
+ "column": 1,
+ "line": 1,
+ "sourceId": "foo",
+ },
+ },
+ Object {
+ "breakpoint": null,
+ "location": Object {
+ "column": 5,
+ "line": 1,
+ "sourceId": "foo",
+ },
+ },
+]
+`;
diff --git a/devtools/client/debugger/src/selectors/test/getCallStackFrames.spec.js b/devtools/client/debugger/src/selectors/test/getCallStackFrames.spec.js
new file mode 100644
index 0000000000..7d31446e48
--- /dev/null
+++ b/devtools/client/debugger/src/selectors/test/getCallStackFrames.spec.js
@@ -0,0 +1,166 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
+
+import { getCallStackFrames } from "../getCallStackFrames";
+
+describe("getCallStackFrames selector", () => {
+ describe("library annotation", () => {
+ it("annotates React frames", () => {
+ const source1 = { id: "source1", url: "webpack:///src/App.js" };
+ const source2 = {
+ id: "source2",
+ url: "webpack:///foo/node_modules/react-dom/lib/ReactCompositeComponent.js",
+ };
+ const state = {
+ frames: [
+ { location: { sourceId: "source1", source: source1 } },
+ { location: { sourceId: "source2", source: source2 } },
+ { location: { sourceId: "source2", source: source2 } },
+ ],
+ selectedSource: {
+ id: "sourceId-originalSource",
+ isOriginal: true,
+ },
+ };
+
+ const frames = getCallStackFrames.resultFunc(
+ state.frames,
+ state.selectedSource,
+ {}
+ );
+
+ expect(frames[0]).not.toHaveProperty("library");
+ expect(frames[1]).toHaveProperty("library", "React");
+ expect(frames[2]).toHaveProperty("library", "React");
+ });
+
+ // Multiple Babel async frame groups occur when you have an async function
+ // calling another async function (a common case).
+ //
+ // There are two possible frame groups that can occur depending on whether
+ // one sets a breakpoint before or after an await
+ it("annotates frames related to Babel async transforms", () => {
+ const appSource = { id: "app", url: "webpack///app.js" };
+ const bundleSource = { id: "bundle", url: "https://foo.com/bundle.js" };
+ const regeneratorSource = {
+ id: "regenerator",
+ url: "webpack:///foo/node_modules/regenerator-runtime/runtime.js",
+ };
+ const microtaskSource = {
+ id: "microtask",
+ url: "webpack:///foo/node_modules/core-js/modules/_microtask.js",
+ };
+ const promiseSource = {
+ id: "promise",
+ url: "webpack///foo/node_modules/core-js/modules/es6.promise.js",
+ };
+ const preAwaitGroup = [
+ {
+ displayName: "asyncAppFunction",
+ location: { source: bundleSource },
+ },
+ {
+ displayName: "tryCatch",
+ location: { source: regeneratorSource },
+ },
+ {
+ displayName: "invoke",
+ location: { source: regeneratorSource },
+ },
+ {
+ displayName: "defineIteratorMethods/</prototype[method]",
+ location: { source: regeneratorSource },
+ },
+ {
+ displayName: "step",
+ location: { source: bundleSource },
+ },
+ {
+ displayName: "_asyncToGenerator/</<",
+ location: { source: bundleSource },
+ },
+ {
+ displayName: "Promise",
+ location: { source: promiseSource },
+ },
+ {
+ displayName: "_asyncToGenerator/<",
+ location: { source: bundleSource },
+ },
+ {
+ displayName: "asyncAppFunction",
+ location: { source: appSource },
+ },
+ ];
+
+ const postAwaitGroup = [
+ {
+ displayName: "asyncAppFunction",
+ location: { source: bundleSource },
+ },
+ {
+ displayName: "tryCatch",
+ location: { source: regeneratorSource },
+ },
+ {
+ displayName: "invoke",
+ location: { source: regeneratorSource },
+ },
+ {
+ displayName: "defineIteratorMethods/</prototype[method]",
+ location: { source: regeneratorSource },
+ },
+ {
+ displayName: "step",
+ location: { source: bundleSource },
+ },
+ {
+ displayName: "step/<",
+ location: { source: bundleSource },
+ },
+ {
+ displayName: "run",
+ location: { source: bundleSource },
+ },
+ {
+ displayName: "notify/<",
+ location: { source: bundleSource },
+ },
+ {
+ displayName: "flush",
+ location: { source: microtaskSource },
+ },
+ ];
+
+ const state = {
+ frames: [...preAwaitGroup, ...postAwaitGroup],
+ selectedSource: {
+ id: "sourceId-originalSource",
+ isOriginal: true,
+ },
+ };
+
+ const frames = getCallStackFrames.resultFunc(
+ state.frames,
+ state.selectedSource,
+ {}
+ );
+
+ // frames from 1-8 and 10-17 are babel frames.
+ const babelFrames = [...frames.slice(1, 7), ...frames.slice(10, 7)];
+ const otherFrames = frames.filter(frame => !babelFrames.includes(frame));
+
+ expect(babelFrames).toEqual(
+ Array(babelFrames.length).fill(
+ expect.objectContaining({ library: "Babel" })
+ )
+ );
+ expect(otherFrames).not.toEqual(
+ Array(babelFrames.length).fill(
+ expect.objectContaining({ library: "Babel" })
+ )
+ );
+ });
+ });
+});
diff --git a/devtools/client/debugger/src/selectors/test/visibleColumnBreakpoints.spec.js b/devtools/client/debugger/src/selectors/test/visibleColumnBreakpoints.spec.js
new file mode 100644
index 0000000000..276851b1ef
--- /dev/null
+++ b/devtools/client/debugger/src/selectors/test/visibleColumnBreakpoints.spec.js
@@ -0,0 +1,145 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
+
+import { actions, createStore, makeSource } from "../../utils/test-head";
+import { createLocation } from "../../utils/location";
+
+import {
+ getColumnBreakpoints,
+ getFirstBreakpointPosition,
+} from "../visibleColumnBreakpoints";
+import {
+ makeMockSource,
+ makeMockSourceWithContent,
+ makeMockBreakpoint,
+} from "../../utils/test-mockup";
+
+function pp(line, column) {
+ return {
+ location: { sourceId: "foo", line, column },
+ generatedLocation: { sourceId: "foo", line, column },
+ };
+}
+
+function defaultSource() {
+ return makeMockSource(undefined, "foo");
+}
+
+function bp(line, column) {
+ return makeMockBreakpoint(defaultSource(), line, column);
+}
+
+const source = makeMockSourceWithContent(
+ undefined,
+ "foo.js",
+ undefined,
+ `function foo() {
+ console.log("hello");
+}
+console.log('bye');
+`
+);
+
+describe("visible column breakpoints", () => {
+ it("simple", () => {
+ const viewport = {
+ start: { line: 1, column: 0 },
+ end: { line: 10, column: 10 },
+ };
+ const pausePoints = [pp(1, 1), pp(1, 5), pp(3, 1)];
+ const breakpoints = [bp(1, 1), bp(4, 0), bp(4, 3)];
+
+ const columnBps = getColumnBreakpoints(
+ pausePoints,
+ breakpoints,
+ viewport,
+ source,
+ source.content
+ );
+ expect(columnBps).toMatchSnapshot();
+ });
+
+ it("ignores single breakpoints", () => {
+ const viewport = {
+ start: { line: 1, column: 0 },
+ end: { line: 10, column: 10 },
+ };
+ const pausePoints = [pp(1, 1), pp(1, 3), pp(2, 1)];
+ const breakpoints = [bp(1, 1)];
+ const columnBps = getColumnBreakpoints(
+ pausePoints,
+ breakpoints,
+ viewport,
+ source,
+ source.content
+ );
+ expect(columnBps).toMatchSnapshot();
+ });
+
+ it("only shows visible breakpoints", () => {
+ const viewport = {
+ start: { line: 1, column: 0 },
+ end: { line: 10, column: 10 },
+ };
+ const pausePoints = [pp(1, 1), pp(1, 3), pp(20, 1)];
+ const breakpoints = [bp(1, 1)];
+
+ const columnBps = getColumnBreakpoints(
+ pausePoints,
+ breakpoints,
+ viewport,
+ source,
+ source.content
+ );
+ expect(columnBps).toMatchSnapshot();
+ });
+
+ it("doesnt show breakpoints to the right", () => {
+ const viewport = {
+ start: { line: 1, column: 0 },
+ end: { line: 10, column: 10 },
+ };
+ const pausePoints = [pp(1, 1), pp(1, 15), pp(20, 1)];
+ const breakpoints = [bp(1, 1), bp(1, 15)];
+
+ const columnBps = getColumnBreakpoints(
+ pausePoints,
+ breakpoints,
+ viewport,
+ source,
+ source.content
+ );
+ expect(columnBps).toMatchSnapshot();
+ });
+});
+
+describe("getFirstBreakpointPosition", () => {
+ it("sorts the positions by column", async () => {
+ const store = createStore();
+ const { dispatch, getState } = store;
+
+ const fooSource = await dispatch(
+ actions.newGeneratedSource(makeSource("foo1"))
+ );
+
+ dispatch({
+ type: "ADD_BREAKPOINT_POSITIONS",
+ positions: [pp(1, 5), pp(1, 3)],
+ source: fooSource,
+ });
+
+ const position = getFirstBreakpointPosition(
+ getState(),
+ createLocation({
+ line: 1,
+ source: fooSource,
+ })
+ );
+
+ if (!position) {
+ throw new Error("There should be a position");
+ }
+ expect(position.location.column).toEqual(3);
+ });
+});