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
174 lines (152 loc) · 5.93 KB
/
Copy pathnewSources.spec.js
File metadata and controls
174 lines (152 loc) · 5.93 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/* 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/>. */
// @flow
import {
actions,
selectors,
createStore,
makeSource,
makeSourceURL,
waitForState
} from "../../../utils/test-head";
const {
getSource,
getSourceCount,
getSelectedSource,
getSourceByURL
} = selectors;
import sourceQueue from "../../../utils/source-queue";
// 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.newGeneratedSource(makeSource("base.js")));
await dispatch(actions.newGeneratedSource(makeSource("jquery.js")));
expect(getSourceCount(getState())).toEqual(2);
const base = getSource(getState(), "base.js");
const jquery = getSource(getState(), "jquery.js");
expect(base && base.id).toEqual("base.js");
expect(jquery && jquery.id).toEqual("jquery.js");
});
it("should not add multiple identical sources", async () => {
const { dispatch, getState } = createStore(threadClient);
await dispatch(actions.newGeneratedSource(makeSource("base.js")));
await dispatch(actions.newGeneratedSource(makeSource("base.js")));
expect(getSourceCount(getState())).toEqual(1);
});
it("should automatically select a pending source", async () => {
const { dispatch, getState, cx } = createStore(threadClient);
const baseSourceURL = makeSourceURL("base.js");
await dispatch(actions.selectSourceURL(cx, baseSourceURL));
expect(getSelectedSource(getState())).toBe(undefined);
const baseSource = await dispatch(
actions.newGeneratedSource(makeSource("base.js"))
);
const selected = getSelectedSource(getState());
expect(selected && selected.url).toBe(baseSource.url);
});
it("should add original sources", async () => {
const { dispatch, getState } = createStore(
threadClient,
{},
{
getOriginalURLs: async () => ["magic.js"],
getOriginalLocations: async items => items
}
);
await dispatch(
actions.newGeneratedSource(
makeSource("base.js", { sourceMapURL: "base.js.map" })
)
);
const magic = getSourceByURL(getState(), "magic.js");
expect(magic && magic.url).toEqual("magic.js");
});
// eslint-disable-next-line
it("should not attempt to fetch original sources if it's missing a source map url", async () => {
const getOriginalURLs = jest.fn();
const { dispatch } = createStore(
threadClient,
{},
{
getOriginalURLs,
getOriginalLocations: async items => items
}
);
await dispatch(actions.newGeneratedSource(makeSource("base.js")));
expect(getOriginalURLs).not.toHaveBeenCalled();
});
// eslint-disable-next-line
it("should process new sources immediately, without waiting for source maps to be fetched first", async () => {
const { dispatch, getState } = createStore(
threadClient,
{},
{
getOriginalURLs: async () => new Promise(_ => {}),
getOriginalLocations: async items => items
}
);
await dispatch(
actions.newGeneratedSource(
makeSource("base.js", { sourceMapURL: "base.js.map" })
)
);
expect(getSourceCount(getState())).toEqual(1);
const base = getSource(getState(), "base.js");
expect(base && base.id).toEqual("base.js");
});
// eslint-disable-next-line
it("shouldn't let one slow loading source map delay all the other source maps", async () => {
const dbg = createStore(
threadClient,
{},
{
getOriginalURLs: async source => {
if (source.id == "foo.js") {
// simulate a hang loading foo.js.map
return new Promise(_ => {});
}
return [source.id.replace(".js", ".cljs")];
},
getOriginalLocations: async items => items,
getGeneratedLocation: location => location
}
);
const { dispatch, getState } = dbg;
await dispatch(
actions.newGeneratedSources([
makeSource("foo.js", { sourceMapURL: "foo.js.map" }),
makeSource("bar.js", { sourceMapURL: "bar.js.map" }),
makeSource("bazz.js", { sourceMapURL: "bazz.js.map" })
])
);
await sourceQueue.flush();
await waitForState(dbg, state => getSourceCount(state) == 5);
expect(getSourceCount(getState())).toEqual(5);
const barCljs = getSourceByURL(getState(), "bar.cljs");
expect(barCljs && barCljs.url).toEqual("bar.cljs");
const bazzCljs = getSourceByURL(getState(), "bazz.cljs");
expect(bazzCljs && bazzCljs.url).toEqual("bazz.cljs");
});
describe("sources - sources with querystrings", () => {
it(`should find two sources when same source with
querystring`, async () => {
const { getSourcesUrlsInSources } = selectors;
const { dispatch, getState } = createStore(threadClient);
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")));
const base1 = "http://localhost:8000/examples/base.js?v=1";
const diff1 = "http://localhost:8000/examples/diff.js?v=1";
const diff2 = "http://localhost:8000/examples/diff.js?v=1";
expect(getSourcesUrlsInSources(getState(), base1)).toHaveLength(2);
expect(getSourcesUrlsInSources(getState(), base1)).toMatchSnapshot();
expect(getSourcesUrlsInSources(getState(), diff1)).toHaveLength(1);
await dispatch(actions.newGeneratedSource(makeSource("diff.js?v=2")));
expect(getSourcesUrlsInSources(getState(), diff2)).toHaveLength(2);
expect(getSourcesUrlsInSources(getState(), diff1)).toHaveLength(2);
});
});
});