Bug 1541631 - Part 1: Rename mock threadFront file to better name since it isn't a Front. r=jlast

Differential Revision: https://phabricator.services.mozilla.com/D42025

--HG--
rename : devtools/client/debugger/src/actions/tests/helpers/threadFront.js => devtools/client/debugger/src/actions/tests/helpers/mockCommandClient.js
extra : moz-landing-system : lando
This commit is contained in:
Logan Smyth 2019-08-15 21:44:47 +00:00
Родитель f21661fdf8
Коммит ec00db2167
12 изменённых файлов: 66 добавлений и 96 удалений

Просмотреть файл

@ -21,7 +21,7 @@ const sourceTexts = {
"scopes.js": readFixture("scopes.js"),
};
const threadFront = {
const mockCommandClient = {
sourceContents: async ({ source }) => ({
source: sourceTexts[source],
contentType: "text/javascript",
@ -34,7 +34,7 @@ const threadFront = {
describe("getInScopeLine", () => {
it("with selected line", async () => {
const store = createStore(threadFront);
const store = createStore(mockCommandClient);
const { dispatch, getState } = store;
const source = makeMockSource("scopes.js", "scopes.js");

Просмотреть файл

@ -11,7 +11,7 @@ import {
makeSource,
waitForState,
} from "../../../utils/test-head";
import { createSource } from "../../tests/helpers/threadFront";
import { createSource } from "../../tests/helpers/mockCommandClient";
describe("breakpointPositions", () => {
it("fetches positions", async () => {

Просмотреть файл

@ -12,11 +12,11 @@ import {
getTelemetryEvents,
} from "../../../utils/test-head";
import { simpleMockThreadFront } from "../../tests/helpers/threadFront.js";
import { mockCommandClient } from "../../tests/helpers/mockCommandClient";
function mockClient(positionsResponse = {}) {
return {
...simpleMockThreadFront,
...mockCommandClient,
getBreakpointPositions: async () => positionsResponse,
getBreakableLines: async () => [],
};

Просмотреть файл

@ -22,7 +22,7 @@ import { features } from "../../../utils/prefs";
const { isStepping } = selectors;
let stepInResolve = null;
const mockThreadFront = {
const mockCommandClient = {
stepIn: () =>
new Promise(_resolve => {
stepInResolve = _resolve;
@ -104,7 +104,7 @@ function createPauseInfo(
describe("pause", () => {
describe("stepping", () => {
it("should set and clear the command", async () => {
const { dispatch, getState } = createStore(mockThreadFront);
const { dispatch, getState } = createStore(mockCommandClient);
const mockPauseInfo = createPauseInfo();
await dispatch(actions.newGeneratedSource(makeSource("foo1")));
@ -129,7 +129,7 @@ describe("pause", () => {
});
it("should step when paused", async () => {
const { dispatch, getState } = createStore(mockThreadFront);
const { dispatch, getState } = createStore(mockCommandClient);
const mockPauseInfo = createPauseInfo();
await dispatch(actions.newGeneratedSource(makeSource("foo1")));
@ -140,7 +140,7 @@ describe("pause", () => {
});
it("should step over when paused", async () => {
const store = createStore(mockThreadFront);
const store = createStore(mockCommandClient);
const { dispatch, getState } = store;
const mockPauseInfo = createPauseInfo();
@ -155,7 +155,7 @@ describe("pause", () => {
it("should step over when paused before an await", async () => {
features.asyncStepping = true;
const store = createStore(mockThreadFront);
const store = createStore(mockCommandClient);
const { dispatch, getState } = store;
const mockPauseInfo = createPauseInfo({
sourceId: "await",
@ -175,7 +175,7 @@ describe("pause", () => {
it("should step over when paused after an await", async () => {
const store = createStore({
...mockThreadFront,
...mockCommandClient,
getBreakpointPositions: async () => ({ [2]: [1] }),
});
const { dispatch, getState } = store;
@ -202,7 +202,7 @@ describe("pause", () => {
column: 0,
};
const store = createStore(mockThreadFront, {});
const store = createStore(mockCommandClient, {});
const { dispatch, getState } = store;
const mockPauseInfo = createPauseInfo(generatedLocation, {
scope: {
@ -279,7 +279,7 @@ describe("pause", () => {
getGeneratedLocation: async location => location,
};
const store = createStore(mockThreadFront, {}, sourceMapsMock);
const store = createStore(mockCommandClient, {}, sourceMapsMock);
const { dispatch, getState } = store;
const mockPauseInfo = createPauseInfo(generatedLocation);
@ -340,7 +340,7 @@ describe("pause", () => {
getGeneratedRangesForOriginal: async () => [],
};
const store = createStore(mockThreadFront, {}, sourceMapsMock);
const store = createStore(mockCommandClient, {}, sourceMapsMock);
const { dispatch, getState } = store;
const mockPauseInfo = createPauseInfo(generatedLocation);
@ -383,7 +383,7 @@ describe("pause", () => {
describe("resumed", () => {
it("should not evaluate expression while stepping", async () => {
const client = { ...mockThreadFront, evaluateExpressions: jest.fn() };
const client = { ...mockCommandClient, evaluateExpressions: jest.fn() };
const { dispatch, getState } = createStore(client);
const mockPauseInfo = createPauseInfo();
@ -392,12 +392,12 @@ describe("pause", () => {
const cx = selectors.getThreadContext(getState());
dispatch(actions.stepIn(cx));
await dispatch(actions.resumed(mockThreadFront.actorID));
await dispatch(actions.resumed(mockCommandClient.actorID));
expect(client.evaluateExpressions.mock.calls).toHaveLength(1);
});
it("resuming - will re-evaluate watch expressions", async () => {
const client = { ...mockThreadFront, evaluateExpressions: jest.fn() };
const client = { ...mockCommandClient, evaluateExpressions: jest.fn() };
const store = createStore(client);
const { dispatch, getState, cx } = store;
const mockPauseInfo = createPauseInfo();
@ -410,7 +410,7 @@ describe("pause", () => {
client.evaluateExpressions.mockReturnValue(Promise.resolve(["YAY"]));
await dispatch(actions.paused(mockPauseInfo));
await dispatch(actions.resumed(mockThreadFront.actorID));
await dispatch(actions.resumed(mockCommandClient.actorID));
const expression = selectors.getExpression(getState(), "foo");
expect(expression && expression.value).toEqual("YAY");
});

Просмотреть файл

@ -14,14 +14,14 @@ import {
} from "../../../utils/test-head";
import {
createSource,
sourceThreadFront,
} from "../../tests/helpers/threadFront.js";
mockCommandClient,
} from "../../tests/helpers/mockCommandClient";
import { getBreakpointsList } from "../../../selectors";
import { isFulfilled, isRejected } from "../../../utils/async-value";
describe("loadSourceText", () => {
it("should load source text", async () => {
const store = createStore(sourceThreadFront);
const store = createStore(mockCommandClient);
const { dispatch, getState, cx } = store;
const foo1Source = await dispatch(
@ -59,7 +59,7 @@ describe("loadSourceText", () => {
const store = createStore(
{
...sourceThreadFront,
...mockCommandClient,
sourceContents: async () => fooGenContent,
getBreakpointPositions: async () => ({ "1": [0] }),
getBreakableLines: async () => [],
@ -223,7 +223,7 @@ describe("loadSourceText", () => {
});
it("should cache subsequent source text loads", async () => {
const { dispatch, getState, cx } = createStore(sourceThreadFront);
const { dispatch, getState, cx } = createStore(mockCommandClient);
const source = await dispatch(
actions.newGeneratedSource(makeSource("foo1"))
@ -238,7 +238,7 @@ describe("loadSourceText", () => {
});
it("should indicate a loading source", async () => {
const store = createStore(sourceThreadFront);
const store = createStore(mockCommandClient);
const { dispatch, cx } = store;
const source = await dispatch(
@ -255,7 +255,7 @@ describe("loadSourceText", () => {
});
it("should indicate an errored source text", async () => {
const { dispatch, getState, cx } = createStore(sourceThreadFront);
const { dispatch, getState, cx } = createStore(mockCommandClient);
const source = await dispatch(
actions.newGeneratedSource(makeSource("bad-id"))

Просмотреть файл

@ -20,12 +20,11 @@ const {
} = selectors;
import sourceQueue from "../../../utils/source-queue";
// eslint-disable-next-line max-len
import { sourceThreadFront as threadFront } from "../../tests/helpers/threadFront.js";
import { mockCommandClient } from "../../tests/helpers/mockCommandClient";
describe("sources - new sources", () => {
it("should add sources to state", async () => {
const { dispatch, getState } = createStore(threadFront);
const { dispatch, getState } = createStore(mockCommandClient);
await dispatch(actions.newGeneratedSource(makeSource("base.js")));
await dispatch(actions.newGeneratedSource(makeSource("jquery.js")));
@ -37,7 +36,7 @@ describe("sources - new sources", () => {
});
it("should not add multiple identical sources", async () => {
const { dispatch, getState } = createStore(threadFront);
const { dispatch, getState } = createStore(mockCommandClient);
await dispatch(actions.newGeneratedSource(makeSource("base.js")));
await dispatch(actions.newGeneratedSource(makeSource("base.js")));
@ -46,7 +45,7 @@ describe("sources - new sources", () => {
});
it("should automatically select a pending source", async () => {
const { dispatch, getState, cx } = createStore(threadFront);
const { dispatch, getState, cx } = createStore(mockCommandClient);
const baseSourceURL = makeSourceURL("base.js");
await dispatch(actions.selectSourceURL(cx, baseSourceURL));
@ -61,7 +60,7 @@ describe("sources - new sources", () => {
it("should add original sources", async () => {
const { dispatch, getState } = createStore(
threadFront,
mockCommandClient,
{},
{
getOriginalURLs: async () => ["magic.js"],
@ -82,7 +81,7 @@ describe("sources - new sources", () => {
it("should not attempt to fetch original sources if it's missing a source map url", async () => {
const getOriginalURLs = jest.fn();
const { dispatch } = createStore(
threadFront,
mockCommandClient,
{},
{
getOriginalURLs,
@ -97,7 +96,7 @@ describe("sources - new sources", () => {
// eslint-disable-next-line
it("should process new sources immediately, without waiting for source maps to be fetched first", async () => {
const { dispatch, getState } = createStore(
threadFront,
mockCommandClient,
{},
{
getOriginalURLs: async () => new Promise(_ => {}),
@ -117,7 +116,7 @@ describe("sources - new sources", () => {
// eslint-disable-next-line
it("shouldn't let one slow loading source map delay all the other source maps", async () => {
const dbg = createStore(
threadFront,
mockCommandClient,
{},
{
getOriginalURLs: async source => {
@ -153,7 +152,7 @@ describe("sources - new sources", () => {
it(`should find two sources when same source with
querystring`, async () => {
const { getSourcesUrlsInSources } = selectors;
const { dispatch, getState } = createStore(threadFront);
const { dispatch, getState } = createStore(mockCommandClient);
await dispatch(actions.newGeneratedSource(makeSource("base.js?v=1")));
await dispatch(actions.newGeneratedSource(makeSource("base.js?v=2")));
await dispatch(actions.newGeneratedSource(makeSource("diff.js?v=1")));

Просмотреть файл

@ -11,12 +11,12 @@ import {
makeSource,
} from "../../../utils/test-head";
import { createPrettySource } from "../prettyPrint";
import { sourceThreadFront } from "../../tests/helpers/threadFront.js";
import { mockCommandClient } from "../../tests/helpers/mockCommandClient";
import { isFulfilled } from "../../../utils/async-value";
describe("sources - pretty print", () => {
it("returns a pretty source for a minified file", async () => {
const { dispatch, getState, cx } = createStore(sourceThreadFront);
const { dispatch, getState, cx } = createStore(mockCommandClient);
const url = "base.js";
const source = await dispatch(actions.newGeneratedSource(makeSource(url)));
@ -42,7 +42,7 @@ describe("sources - pretty print", () => {
});
it("should create a source when first toggling pretty print", async () => {
const { dispatch, getState, cx } = createStore(sourceThreadFront);
const { dispatch, getState, cx } = createStore(mockCommandClient);
const source = await dispatch(
actions.newGeneratedSource(makeSource("foobar.js"))
@ -54,7 +54,7 @@ describe("sources - pretty print", () => {
});
it("should not make a second source when toggling pretty print", async () => {
const { dispatch, getState, cx } = createStore(sourceThreadFront);
const { dispatch, getState, cx } = createStore(mockCommandClient);
const source = await dispatch(
actions.newGeneratedSource(makeSource("foobar.js"))

Просмотреть файл

@ -13,11 +13,11 @@ import {
const { getSourcesUrlsInSources } = selectors;
// eslint-disable-next-line max-len
import { sourceThreadFront as threadFront } from "../../tests/helpers/threadFront.js";
import { mockCommandClient } from "../../tests/helpers/mockCommandClient";
describe("sources - sources with querystrings", () => {
it("should find two sources when same source with querystring", async () => {
const { dispatch, getState } = createStore(threadFront);
const { dispatch, getState } = createStore(mockCommandClient);
await dispatch(actions.newGeneratedSource(makeSource("base.js?v=1")));
await dispatch(actions.newGeneratedSource(makeSource("base.js?v=2")));
await dispatch(actions.newGeneratedSource(makeSource("diff.js?v=1")));

Просмотреть файл

@ -23,7 +23,7 @@ const {
getSelectedLocation,
} = selectors;
import { sourceThreadFront } from "../../tests/helpers/threadFront.js";
import { mockCommandClient } from "../../tests/helpers/mockCommandClient";
process.on("unhandledRejection", (reason, p) => {});
@ -35,7 +35,7 @@ describe("sources", () => {
it("should select a source", async () => {
// Note that we pass an empty client in because the action checks
// if it exists.
const store = createStore(sourceThreadFront);
const store = createStore(mockCommandClient);
const { dispatch, getState } = store;
const frame = makeFrame({ id: "1", sourceId: "foo1" });
@ -69,7 +69,7 @@ describe("sources", () => {
});
it("should select next tab on tab closed if no previous tab", async () => {
const { dispatch, getState, cx } = createStore(sourceThreadFront);
const { dispatch, getState, cx } = createStore(mockCommandClient);
const fooSource = await dispatch(
actions.newGeneratedSource(makeSource("foo.js"))
@ -98,7 +98,7 @@ describe("sources", () => {
});
it("should open a tab for the source", async () => {
const { dispatch, getState, cx } = createStore(sourceThreadFront);
const { dispatch, getState, cx } = createStore(mockCommandClient);
await dispatch(actions.newGeneratedSource(makeSource("foo.js")));
dispatch(actions.selectLocation(cx, initialLocation("foo.js")));
@ -108,7 +108,7 @@ describe("sources", () => {
});
it("should select previous tab on tab closed", async () => {
const { dispatch, getState, cx } = createStore(sourceThreadFront);
const { dispatch, getState, cx } = createStore(mockCommandClient);
await dispatch(actions.newGeneratedSource(makeSource("foo.js")));
await dispatch(actions.newGeneratedSource(makeSource("bar.js")));
@ -127,7 +127,7 @@ describe("sources", () => {
});
it("should keep the selected source when other tab closed", async () => {
const { dispatch, getState, cx } = createStore(sourceThreadFront);
const { dispatch, getState, cx } = createStore(mockCommandClient);
await dispatch(actions.newGeneratedSource(makeSource("foo.js")));
await dispatch(actions.newGeneratedSource(makeSource("bar.js")));
@ -154,7 +154,7 @@ describe("sources", () => {
});
it("should not select new sources that lack a URL", async () => {
const { dispatch, getState } = createStore(sourceThreadFront);
const { dispatch, getState } = createStore(mockCommandClient);
await dispatch(
actions.newGeneratedSource({
@ -169,7 +169,7 @@ describe("sources", () => {
});
it("sets and clears selected location correctly", async () => {
const { dispatch, getState, cx } = createStore(sourceThreadFront);
const { dispatch, getState, cx } = createStore(mockCommandClient);
const source = await dispatch(
actions.newGeneratedSource(makeSource("testSource"))
);
@ -188,7 +188,7 @@ describe("sources", () => {
});
it("sets and clears pending selected location correctly", () => {
const { dispatch, getState, cx } = createStore(sourceThreadFront);
const { dispatch, getState, cx } = createStore(mockCommandClient);
const url = "testURL";
const options = { location: { line: "testLine" } };
@ -207,7 +207,7 @@ describe("sources", () => {
});
it("should keep the generated the viewing context", async () => {
const store = createStore(sourceThreadFront);
const store = createStore(mockCommandClient);
const { dispatch, getState, cx } = store;
const baseSource = await dispatch(
actions.newGeneratedSource(makeSource("base.js"))
@ -224,7 +224,7 @@ describe("sources", () => {
it("should keep the original the viewing context", async () => {
const { dispatch, getState, cx } = createStore(
sourceThreadFront,
mockCommandClient,
{},
{
getOriginalLocation: async location => ({ ...location, line: 12 }),
@ -258,7 +258,7 @@ describe("sources", () => {
it("should change the original the viewing context", async () => {
const { dispatch, getState, cx } = createStore(
sourceThreadFront,
mockCommandClient,
{},
{
getOriginalLocation: async location => ({ ...location, line: 12 }),
@ -290,7 +290,7 @@ describe("sources", () => {
describe("selectSourceURL", () => {
it("should automatically select a pending source", async () => {
const { dispatch, getState, cx } = createStore(sourceThreadFront);
const { dispatch, getState, cx } = createStore(mockCommandClient);
const baseSourceURL = makeSourceURL("base.js");
await dispatch(actions.selectSourceURL(cx, baseSourceURL));

Просмотреть файл

@ -4,11 +4,7 @@
// @flow
import type {
SourceActor,
SourceActorLocation,
BreakpointOptions,
} from "../../../types";
import type { SourceActor } from "../../../types";
export function createSource(name: string, code?: string) {
name = name.replace(/\..*$/, "");
@ -36,33 +32,7 @@ const sources = [
"jquery.js",
];
export const simpleMockThreadFront = {
getBreakpointByLocation: (jest.fn(): any),
setBreakpoint: (location: SourceActorLocation, _condition: string) =>
Promise.resolve({ id: "hi", actualLocation: location }),
removeBreakpoint: (_id: string) => Promise.resolve(),
setBreakpointOptions: (
_id: string,
_location: SourceActorLocation,
_options: BreakpointOptions,
_noSliding: boolean
) => Promise.resolve({ sourceId: "a", line: 5 }),
sourceContents: ({
source,
}: SourceActor): Promise<{| source: any, contentType: ?string |}> =>
new Promise((resolve, reject) => {
if (sources.includes(source)) {
resolve(createSource(source));
}
reject(`unknown source: ${source}`);
}),
};
// sources and tabs
export const sourceThreadFront = {
export const mockCommandClient = {
sourceContents: function({
source,
}: SourceActor): Promise<{| source: any, contentType: ?string |}> {
@ -75,6 +45,7 @@ export const sourceThreadFront = {
});
},
setBreakpoint: async () => {},
removeBreakpoint: (_id: string) => Promise.resolve(),
threadFront: async () => {},
getFrameScopes: async () => {},
evaluateExpressions: async () => {},

Просмотреть файл

@ -10,7 +10,7 @@ import {
mockPendingBreakpoint,
} from "./helpers/breakpoints.js";
import { simpleMockThreadFront } from "./helpers/threadFront.js";
import { mockCommandClient } from "./helpers/mockCommandClient";
import { asyncStore } from "../../utils/prefs";
@ -47,7 +47,7 @@ import sourceMaps from "devtools-source-map";
import { makePendingLocationId } from "../../utils/breakpoint";
function mockClient(bpPos = {}) {
return {
...simpleMockThreadFront,
...mockCommandClient,
getBreakpointPositions: async () => bpPos,
getBreakableLines: async () => [],

Просмотреть файл

@ -12,11 +12,11 @@ import {
} from "../../utils/test-head";
const { getSelectedSource, getSourceTabs } = selectors;
import { sourceThreadFront as threadFront } from "./helpers/threadFront.js";
import { mockCommandClient } from "./helpers/mockCommandClient";
describe("closing tabs", () => {
it("closing a tab", async () => {
const { dispatch, getState, cx } = createStore(threadFront);
const { dispatch, getState, cx } = createStore(mockCommandClient);
const fooSource = await dispatch(
actions.newGeneratedSource(makeSource("foo.js"))
@ -29,7 +29,7 @@ describe("closing tabs", () => {
});
it("closing the inactive tab", async () => {
const { dispatch, getState, cx } = createStore(threadFront);
const { dispatch, getState, cx } = createStore(mockCommandClient);
const fooSource = await dispatch(
actions.newGeneratedSource(makeSource("foo.js"))
@ -45,7 +45,7 @@ describe("closing tabs", () => {
});
it("closing the only tab", async () => {
const { dispatch, getState, cx } = createStore(threadFront);
const { dispatch, getState, cx } = createStore(mockCommandClient);
const fooSource = await dispatch(
actions.newGeneratedSource(makeSource("foo.js"))
@ -58,7 +58,7 @@ describe("closing tabs", () => {
});
it("closing the active tab", async () => {
const { dispatch, getState, cx } = createStore(threadFront);
const { dispatch, getState, cx } = createStore(mockCommandClient);
await dispatch(actions.newGeneratedSource(makeSource("foo.js")));
const barSource = await dispatch(
@ -74,7 +74,7 @@ describe("closing tabs", () => {
});
it("closing many inactive tabs", async () => {
const { dispatch, getState, cx } = createStore(threadFront);
const { dispatch, getState, cx } = createStore(mockCommandClient);
await dispatch(actions.newGeneratedSource(makeSource("foo.js")));
await dispatch(actions.newGeneratedSource(makeSource("bar.js")));
@ -97,7 +97,7 @@ describe("closing tabs", () => {
});
it("closing many tabs including the active tab", async () => {
const { dispatch, getState, cx } = createStore(threadFront);
const { dispatch, getState, cx } = createStore(mockCommandClient);
await dispatch(actions.newGeneratedSource(makeSource("foo.js")));
await dispatch(actions.newGeneratedSource(makeSource("bar.js")));
@ -119,7 +119,7 @@ describe("closing tabs", () => {
});
it("closing all the tabs", async () => {
const { dispatch, getState, cx } = createStore(threadFront);
const { dispatch, getState, cx } = createStore(mockCommandClient);
await dispatch(actions.newGeneratedSource(makeSource("foo.js")));
await dispatch(actions.newGeneratedSource(makeSource("bar.js")));