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
|
/* 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/>. */
import {
actions,
selectors,
createStore,
makeSource,
makeOriginalSource,
} from "../../../utils/test-head";
const { getSource, getSourceCount } = selectors;
import { mockCommandClient } from "../../tests/helpers/mockCommandClient";
describe("sources - new sources", () => {
it("should add sources to state", async () => {
const { dispatch, getState } = createStore(mockCommandClient);
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 generated sources", async () => {
const { dispatch, getState } = createStore(mockCommandClient);
const generated = await dispatch(
actions.newGeneratedSource(makeSource("base.js"))
);
await dispatch(actions.newOriginalSources([makeOriginalSource(generated)]));
await dispatch(actions.newOriginalSources([makeOriginalSource(generated)]));
expect(getSourceCount(getState())).toEqual(2);
});
it("should not add multiple identical original sources", async () => {
const { dispatch, getState } = createStore(mockCommandClient);
await dispatch(actions.newGeneratedSource(makeSource("base.js")));
await dispatch(actions.newGeneratedSource(makeSource("base.js")));
expect(getSourceCount(getState())).toEqual(1);
});
// eslint-disable-next-line
it("should not attempt to fetch original sources if it's missing a source map url", async () => {
const loadSourceMap = jest.fn();
const { dispatch } = createStore(
mockCommandClient,
{},
{
loadSourceMap,
getOriginalLocations: async items => items,
getOriginalLocation: location => location,
}
);
await dispatch(actions.newGeneratedSource(makeSource("base.js")));
expect(loadSourceMap).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(
mockCommandClient,
{},
{
loadSourceMap: async () => new Promise(_ => {}),
getOriginalLocations: async items => items,
getOriginalLocation: location => location,
}
);
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");
});
});
|