Skip to content

Commit

Permalink
Bugfix: TypeError: client.sourceContents is not a function (firefox-d…
Browse files Browse the repository at this point in the history
  • Loading branch information
codehag authored and jasonLaster committed Jul 28, 2017
1 parent 26a28ff commit 74ba2aa
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 103 deletions.
3 changes: 2 additions & 1 deletion src/actions/tests/breakpoints.js
Expand Up @@ -4,10 +4,11 @@ import {
actions,
makeSource
} from "../../utils/test-head";

import {
simulateCorrectThreadClient,
simpleMockThreadClient
} from "./helpers/breakpoints.js";
} from "./helpers/threadClient.js";

describe("breakpoints", () => {
it("should add a breakpoint", async () => {
Expand Down
62 changes: 0 additions & 62 deletions src/actions/tests/helpers/breakpoints.js
@@ -1,16 +1,3 @@
import { makeLocationId } from "../../../utils/breakpoint";

const sourceFixtures = {
foo1: {
source: "function foo1() {\n return 5;\n}",
contentType: "text/javascript"
},
foo2: {
source: "function foo2(x, y) {\n return x + y;\n}",
contentType: "text/javascript"
}
};

export function mockPendingBreakpoint(overrides = {}) {
const { sourceUrl, line, column, condition, disabled } = overrides;
return {
Expand All @@ -29,35 +16,6 @@ export function mockPendingBreakpoint(overrides = {}) {
};
}

function generateCorrectingThreadClient(offset = 0) {
return {
getBreakpointByLocation: jest.fn(),
setBreakpoint: (location, condition) => {
const actualLocation = Object.assign({}, location, {
line: location.line + offset
});

return Promise.resolve({
id: makeLocationId(location),
actualLocation,
condition
});
}
};
}

/* in some cases, a breakpoint may be added, but the source will respond
* with a different breakpoint location. This is due to the breakpoint being
* added between functions, or somewhere that doesnt make sense. This function
* simulates that behavior.
* */
export function simulateCorrectThreadClient(offset, location) {
const correctedThreadClient = generateCorrectingThreadClient(offset);
const offsetLine = { line: location.line + offset };
const correctedLocation = Object.assign({}, location, offsetLine);
return { correctedThreadClient, correctedLocation };
}

export function generateBreakpoint(filename) {
return {
location: {
Expand All @@ -69,23 +27,3 @@ export function generateBreakpoint(filename) {
disabled: false
};
}

export const simpleMockThreadClient = {
getBreakpointByLocation: jest.fn(),
setBreakpoint: (location, _condition) =>
Promise.resolve({ id: "hi", actualLocation: location }),

removeBreakpoint: _id => Promise.resolve(),

setBreakpointCondition: (_id, _location, _condition, _noSliding) =>
Promise.resolve({ sourceId: "a", line: 5 }),

sourceContents: sourceId =>
new Promise((resolve, reject) => {
if (sourceFixtures[sourceId]) {
resolve(sourceFixtures[sourceId]);
}

reject(`unknown source: ${sourceId}`);
})
};
116 changes: 116 additions & 0 deletions src/actions/tests/helpers/threadClient.js
@@ -0,0 +1,116 @@
import { makeLocationId } from "../../../utils/breakpoint";

const sourceFixtures = {
foo1: {
source: "function foo1() {\n return 5;\n}",
contentType: "text/javascript"
},
foo2: {
source: "function foo2(x, y) {\n return x + y;\n}",
contentType: "text/javascript"
}
};

export const simpleMockThreadClient = {
getBreakpointByLocation: jest.fn(),
setBreakpoint: (location, _condition) =>
Promise.resolve({ id: "hi", actualLocation: location }),

removeBreakpoint: _id => Promise.resolve(),

setBreakpointCondition: (_id, _location, _condition, _noSliding) =>
Promise.resolve({ sourceId: "a", line: 5 }),

sourceContents: sourceId =>
new Promise((resolve, reject) => {
if (sourceFixtures[sourceId]) {
resolve(sourceFixtures[sourceId]);
}

reject(`unknown source: ${sourceId}`);
})
};

// Breakpoint Sliding
function generateCorrectingThreadClient(offset = 0) {
return {
getBreakpointByLocation: jest.fn(),
setBreakpoint: (location, condition) => {
const actualLocation = Object.assign({}, location, {
line: location.line + offset
});

return Promise.resolve({
id: makeLocationId(location),
actualLocation,
condition
});
}
};
}

/* in some cases, a breakpoint may be added, but the source will respond
* with a different breakpoint location. This is due to the breakpoint being
* added between functions, or somewhere that doesnt make sense. This function
* simulates that behavior.
* */
export function simulateCorrectThreadClient(offset, location) {
const correctedThreadClient = generateCorrectingThreadClient(offset);
const offsetLine = { line: location.line + offset };
const correctedLocation = Object.assign({}, location, offsetLine);
return { correctedThreadClient, correctedLocation };
}

// sources and tabs
export const sourceThreadClient = {
sourceContents: function(sourceId) {
return new Promise((resolve, reject) => {
switch (sourceId) {
case "foo1":
resolve({
source: "function foo1() {\n return 5;\n}",
contentType: "text/javascript"
});
break;
case "foo2":
resolve({
source: "function foo2(x, y) {\n return x + y;\n}",
contentType: "text/javascript"
});
break;
case "foobar.js":
resolve({
source: "function foo() {\n return 2;\n}",
contentType: "text/javascript"
});
break;
case "barfoo.js":
resolve({
source: "function bar() {\n return 3;\n}",
contentType: "text/javascript"
});
break;
case "foo.js":
resolve({
source: "function bar() {\n return 3;\n}",
contentType: "text/javascript"
});
break;
case "bar.js":
resolve({
source: "function bar() {\n return 3;\n}",
contentType: "text/javascript"
});
break;
case "bazz.js":
resolve({
source: "function bar() {\n return 3;\n}",
contentType: "text/javascript"
});
break;
}

reject(`unknown source: ${sourceId}`);
});
}
};
7 changes: 5 additions & 2 deletions src/actions/tests/pending-breakpoints.js
@@ -1,10 +1,13 @@
// TODO: we would like to mock this in the local tests
import {
generateBreakpoint,
mockPendingBreakpoint,
mockPendingBreakpoint
} from "./helpers/breakpoints.js";

import {
simulateCorrectThreadClient,
simpleMockThreadClient
} from "./helpers/breakpoints.js";
} from "./helpers/threadClient.js";

import { prefs } from "../../utils/prefs";

Expand Down
35 changes: 1 addition & 34 deletions src/actions/tests/sources.js
Expand Up @@ -13,40 +13,7 @@ const {
getSelectedLocation
} = selectors;

const threadClient = {
sourceContents: function(sourceId) {
return new Promise((resolve, reject) => {
switch (sourceId) {
case "foo1":
resolve({
source: "function foo1() {\n return 5;\n}",
contentType: "text/javascript"
});
break;
case "foo2":
resolve({
source: "function foo2(x, y) {\n return x + y;\n}",
contentType: "text/javascript"
});
break;
case "foobar.js":
resolve({
source: "function foo() {\n return 2;\n}",
contentType: "text/javascript"
});
break;
case "barfoo.js":
resolve({
source: "function bar() {\n return 3;\n}",
contentType: "text/javascript"
});
break;
}

reject(`unknown source: ${sourceId}`);
});
}
};
import { sourceThreadClient as threadClient } from "./helpers/threadClient.js";

process.on("unhandledRejection", (reason, p) => {});

Expand Down
8 changes: 4 additions & 4 deletions src/actions/tests/tabs.js
Expand Up @@ -6,7 +6,7 @@ import {
} from "../../utils/test-head";
const { getSelectedSource, getSourceTabs } = selectors;

const threadClient = {};
import { sourceThreadClient as threadClient } from "./helpers/threadClient.js";

describe("closing tabs", () => {
it("closing a tab", async () => {
Expand Down Expand Up @@ -54,7 +54,7 @@ describe("closing tabs", () => {
});

it("closing many inactive tabs", async () => {
const { dispatch, getState } = createStore({});
const { dispatch, getState } = createStore(threadClient);
await dispatch(actions.newSource(makeSource("foo.js")));
await dispatch(actions.newSource(makeSource("bar.js")));
await dispatch(actions.newSource(makeSource("bazz.js")));
Expand All @@ -73,7 +73,7 @@ describe("closing tabs", () => {
});

it("closing many tabs including the active tab", async () => {
const { dispatch, getState } = createStore({});
const { dispatch, getState } = createStore(threadClient);
await dispatch(actions.newSource(makeSource("foo.js")));
await dispatch(actions.newSource(makeSource("bar.js")));
await dispatch(actions.newSource(makeSource("bazz.js")));
Expand All @@ -92,7 +92,7 @@ describe("closing tabs", () => {
});

it("closing all the tabs", async () => {
const { dispatch, getState } = createStore({});
const { dispatch, getState } = createStore(threadClient);
await dispatch(actions.newSource(makeSource("foo.js")));
await dispatch(actions.newSource(makeSource("bar.js")));
dispatch(actions.selectSource("foo.js"));
Expand Down

0 comments on commit 74ba2aa

Please sign in to comment.