forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewSources.spec.js
More file actions
70 lines (57 loc) · 2.38 KB
/
Copy pathnewSources.spec.js
File metadata and controls
70 lines (57 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import {
actions,
selectors,
createStore,
makeSource
} from "../../../utils/test-head";
const { getSource, getSources, getSelectedSource } = selectors;
// eslint-disable-next-line max-len
import { sourceThreadClient as threadClient } from "../../tests/helpers/threadClient.js";
describe("sources - new sources", () => {
it("should add sources to state", async () => {
const { dispatch, getState } = createStore(threadClient);
await dispatch(actions.newSource(makeSource("base.js")));
await dispatch(actions.newSource(makeSource("jquery.js")));
expect(getSources(getState()).size).toEqual(2);
const base = getSource(getState(), "base.js");
const jquery = getSource(getState(), "jquery.js");
expect(base.get("id")).toEqual("base.js");
expect(jquery.get("id")).toEqual("jquery.js");
});
it("should not add multiple identical sources", async () => {
const { dispatch, getState } = createStore(threadClient);
await dispatch(actions.newSource(makeSource("base.js")));
await dispatch(actions.newSource(makeSource("base.js")));
expect(getSources(getState()).size).toEqual(1);
});
it("should automatically select a pending source", async () => {
const { dispatch, getState } = createStore(threadClient);
const baseSource = makeSource("base.js");
await dispatch(actions.selectSourceURL(baseSource.url));
expect(getSelectedSource(getState())).toBe(undefined);
await dispatch(actions.newSource(baseSource));
expect(getSelectedSource(getState()).get("url")).toBe(baseSource.url);
});
it("should add original sources", async () => {
const { dispatch, getState } = createStore(
threadClient,
{},
{
getOriginalURLs: () => Promise.resolve(["magic.js"]),
generatedToOriginalId: (a, b) => `${a}/${b}`
}
);
await dispatch(
actions.newSource(makeSource("base.js", { sourceMapURL: "base.js.map" }))
);
const magic = getSource(getState(), "base.js/magic.js");
expect(magic.get("url")).toEqual("magic.js");
});
// eslint-disable-next-line
it("should no attempt to fetch original sources if it's missing a source map url", async () => {
const getOriginalURLs = jest.fn();
const { dispatch } = createStore(threadClient, {}, { getOriginalURLs });
await dispatch(actions.newSource(makeSource("base.js")));
expect(getOriginalURLs).not.toHaveBeenCalled();
});
});