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
109 lines (94 loc) · 2.96 KB
/
Copy pathsource-map.js
File metadata and controls
109 lines (94 loc) · 2.96 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
/* 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,
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 4ef8c7ec7c1df790781e",
"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("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);
});
});
});