forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsource-map.js
More file actions
197 lines (176 loc) · 4.72 KB
/
Copy pathsource-map.js
File metadata and controls
197 lines (176 loc) · 4.72 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/* 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/>. */
jest.mock("devtools-utils/src/network-request");
const networkRequest = require("devtools-utils/src/network-request");
const {
getOriginalURLs,
hasMappedSource,
getOriginalLocation,
getGeneratedRangesForOriginal,
clearSourceMaps
} = require("../source-map");
const { setupBundleFixture } = require("./helpers");
describe("source maps", () => {
beforeEach(() => {
clearSourceMaps();
});
describe("getOriginalURLs", () => {
test("absolute URL", async () => {
const urls = await setupBundleFixture("absolute");
expect(urls).toEqual(["http://example.com/cheese/heart.js"]);
});
test("source with a url", async () => {
const urls = await setupBundleFixture("bundle");
expect(urls).toEqual([
"webpack:///webpack/bootstrap%204ef8c7ec7c1df790781e",
"webpack:///entry.js",
"webpack:///times2.js",
"webpack:///output.js",
"webpack:///opts.js"
]);
});
test("Empty sourceRoot resolution", async () => {
const urls = await setupBundleFixture("empty");
expect(urls).toEqual(["http://example.com/heart.js"]);
});
test("Non-existing sourceRoot resolution", async () => {
const urls = await setupBundleFixture("noroot");
expect(urls).toEqual(["http://example.com/heart.js"]);
});
test("Non-existing sourceRoot resolution with relative URLs", async () => {
const urls = await setupBundleFixture("noroot2");
expect(urls).toEqual(["http://example.com/heart.js"]);
});
});
describe("getGeneratedRangesForOriginal", () => {
test("the overall generated ranges on the source", async () => {
const urls = await setupBundleFixture("intermingled-sources");
const ranges = await getGeneratedRangesForOriginal(
"intermingled-sources.js/originalSource-01",
urls[0]
);
expect(ranges).toEqual([
{
start: {
line: 4,
column: 69
},
end: {
line: 9,
column: Infinity
}
},
{
start: {
line: 11,
column: 0
},
end: {
line: 17,
column: 3
}
},
{
start: {
line: 19,
column: 18
},
end: {
line: 19,
column: 22
}
},
{
start: {
line: 26,
column: 0
},
end: {
line: 26,
column: Infinity
}
},
{
start: {
line: 28,
column: 0
},
end: {
line: 28,
column: Infinity
}
}
]);
});
test("the merged generated ranges on the source", async () => {
const urls = await setupBundleFixture("intermingled-sources");
const ranges = await getGeneratedRangesForOriginal(
"intermingled-sources.js/originalSource-01",
urls[0],
true
);
expect(ranges).toEqual([
{
start: {
line: 4,
column: 69
},
end: {
line: 28,
column: Infinity
}
}
]);
});
});
describe("hasMappedSource", async () => {
test("has original location", async () => {
await setupBundleFixture("bundle");
const location = {
sourceId: "bundle.js",
line: 49
};
const isMapped = await hasMappedSource(location);
expect(isMapped).toBe(true);
});
test("does not have original location", async () => {
const location = {
sourceId: "bundle.js",
line: 94
};
const isMapped = await hasMappedSource(location);
expect(isMapped).toBe(false);
});
});
describe("Error handling", async () => {
test("missing map", async () => {
const source = {
id: "missingmap.js",
sourceMapURL: "missingmap.js.map",
url: "http:://example.com/missingmap.js"
};
networkRequest.mockImplementationOnce(() => {
throw new Error("Not found");
});
let thrown = false;
try {
await getOriginalURLs(source);
} catch (e) {
thrown = true;
}
expect(thrown).toBe(true);
const location = {
sourceId: "missingmap.js",
line: 49
};
thrown = false;
try {
await getOriginalLocation(location);
} catch (e) {
thrown = true;
}
expect(thrown).toBe(false);
});
});
});