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

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

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

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

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

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

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

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

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

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

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

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

@ -11,12 +11,12 @@ import {
makeSource, makeSource,
} from "../../../utils/test-head"; } from "../../../utils/test-head";
import { createPrettySource } from "../prettyPrint"; import { createPrettySource } from "../prettyPrint";
import { sourceThreadFront } from "../../tests/helpers/threadFront.js"; import { mockCommandClient } from "../../tests/helpers/mockCommandClient";
import { isFulfilled } from "../../../utils/async-value"; import { isFulfilled } from "../../../utils/async-value";
describe("sources - pretty print", () => { describe("sources - pretty print", () => {
it("returns a pretty source for a minified file", async () => { 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 url = "base.js";
const source = await dispatch(actions.newGeneratedSource(makeSource(url))); 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 () => { 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( const source = await dispatch(
actions.newGeneratedSource(makeSource("foobar.js")) 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 () => { 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( const source = await dispatch(
actions.newGeneratedSource(makeSource("foobar.js")) actions.newGeneratedSource(makeSource("foobar.js"))

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

@ -13,11 +13,11 @@ import {
const { getSourcesUrlsInSources } = selectors; const { getSourcesUrlsInSources } = selectors;
// eslint-disable-next-line max-len // 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", () => { describe("sources - sources with querystrings", () => {
it("should find two sources when same source with querystring", async () => { 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=1")));
await dispatch(actions.newGeneratedSource(makeSource("base.js?v=2"))); await dispatch(actions.newGeneratedSource(makeSource("base.js?v=2")));
await dispatch(actions.newGeneratedSource(makeSource("diff.js?v=1"))); await dispatch(actions.newGeneratedSource(makeSource("diff.js?v=1")));

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

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

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

@ -4,11 +4,7 @@
// @flow // @flow
import type { import type { SourceActor } from "../../../types";
SourceActor,
SourceActorLocation,
BreakpointOptions,
} from "../../../types";
export function createSource(name: string, code?: string) { export function createSource(name: string, code?: string) {
name = name.replace(/\..*$/, ""); name = name.replace(/\..*$/, "");
@ -36,33 +32,7 @@ const sources = [
"jquery.js", "jquery.js",
]; ];
export const simpleMockThreadFront = { export const mockCommandClient = {
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 = {
sourceContents: function({ sourceContents: function({
source, source,
}: SourceActor): Promise<{| source: any, contentType: ?string |}> { }: SourceActor): Promise<{| source: any, contentType: ?string |}> {
@ -75,6 +45,7 @@ export const sourceThreadFront = {
}); });
}, },
setBreakpoint: async () => {}, setBreakpoint: async () => {},
removeBreakpoint: (_id: string) => Promise.resolve(),
threadFront: async () => {}, threadFront: async () => {},
getFrameScopes: async () => {}, getFrameScopes: async () => {},
evaluateExpressions: async () => {}, evaluateExpressions: async () => {},

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

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

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

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