forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathast.spec.js
More file actions
150 lines (129 loc) · 4.61 KB
/
ast.spec.js
File metadata and controls
150 lines (129 loc) · 4.61 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
import {
createStore,
selectors,
actions,
makeSource
} from "../../utils/test-head";
import readFixture from "./helpers/readFixture";
const { getSymbols, getEmptyLines, getOutOfScopeLocations } = selectors;
import getInScopeLines from "../../selectors/linesInScope";
const threadClient = {
sourceContents: function(sourceId) {
return new Promise((resolve, reject) =>
resolve({
source: sourceTexts[sourceId],
contentType: "text/javascript"
})
);
},
getFrameScopes: function() {
return Promise.resolve({});
},
evaluate: function(expression) {
return new Promise((resolve, reject) =>
resolve({ result: evaluationResult[expression] })
);
}
};
const sourceTexts = {
"base.js": "function base(boo) {}",
"foo.js": "function base(boo) { return this.bazz; } outOfScope",
"scopes.js": readFixture("scopes.js")
};
const evaluationResult = {
"this.bazz": { actor: "bazz", preview: {} },
this: { actor: "this", preview: {} }
};
describe("ast", () => {
describe("setEmptyLines", () => {
it("scopes", async () => {
const { dispatch, getState } = createStore(threadClient);
const source = makeSource("scopes.js");
await dispatch(actions.newSource(source));
await dispatch(actions.loadSourceText({ id: "scopes.js" }));
const emptyLines = getEmptyLines(getState(), source);
expect(emptyLines).toMatchSnapshot();
});
});
describe("setSymbols", () => {
describe("when the source is loaded", () => {
it("should be able to set symbols", async () => {
const { dispatch, getState } = createStore(threadClient);
const base = makeSource("base.js");
await dispatch(actions.newSource(base));
await dispatch(actions.loadSourceText({ id: "base.js" }));
const baseSymbols = getSymbols(getState(), base);
expect(baseSymbols).toMatchSnapshot();
});
});
describe("when the source is not loaded", () => {
it("should return an empty set", async () => {
const { getState, dispatch } = createStore(threadClient);
const base = makeSource("base.js");
await dispatch(actions.newSource(base));
const baseSymbols = getSymbols(getState(), base);
expect(baseSymbols).toEqual({ variables: [], functions: [] });
});
});
describe("when there is no source", () => {
it("should return an empty set", async () => {
const { getState } = createStore(threadClient);
const baseSymbols = getSymbols(getState());
expect(baseSymbols).toEqual({ variables: [], functions: [] });
});
});
});
describe("getOutOfScopeLocations", () => {
it("with selected line", async () => {
const { dispatch, getState } = createStore(threadClient);
const source = makeSource("scopes.js");
await dispatch(actions.newSource(source));
await dispatch(
actions.selectSource("scopes.js", { location: { line: 5 } })
);
const locations = getOutOfScopeLocations(getState());
const lines = getInScopeLines(getState());
expect(locations).toMatchSnapshot();
expect(lines).toMatchSnapshot();
});
it("without a selected line", async () => {
const { dispatch, getState } = createStore(threadClient);
const base = makeSource("base.js");
await dispatch(actions.newSource(base));
await dispatch(actions.selectSource("base.js"));
const locations = getOutOfScopeLocations(getState());
const lines = getInScopeLines(getState());
expect(locations).toEqual(null);
expect(lines).toEqual([1]);
});
});
describe("setPreview", () => {
let dispatch = undefined;
let getState = undefined;
beforeEach(async () => {
const store = createStore(threadClient);
dispatch = store.dispatch;
getState = store.getState;
const foo = makeSource("foo.js");
await dispatch(actions.newSource(foo));
await dispatch(actions.loadSourceText({ id: "foo.js" }));
await dispatch(actions.selectSource("foo.js"));
await dispatch(
actions.paused({
why: { type: "resumeLimit" },
frames: [{ id: "frame1", location: { sourceId: "foo.js" } }]
})
);
});
it("member expression", async () => {
await dispatch(actions.setPreview("bazz", { line: 1, column: 34 }));
const preview = selectors.getPreview(getState());
expect(preview).toMatchSnapshot();
});
it("this", async () => {
await dispatch(actions.setPreview("this", { line: 1, column: 30 }));
const preview = selectors.getPreview(getState());
expect(preview).toMatchSnapshot();
});
});
});