forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpause.spec.js
More file actions
103 lines (87 loc) · 2.99 KB
/
Copy pathpause.spec.js
File metadata and controls
103 lines (87 loc) · 2.99 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
import {
actions,
selectors,
createStore,
waitForState,
makeSource
} from "../../utils/test-head";
const { isStepping } = selectors;
let stepInResolve = null;
const mockThreadClient = {
stepIn: () =>
new Promise(_resolve => {
stepInResolve = _resolve;
}),
evaluate: () => new Promise(_resolve => {}),
getFrameScopes: frame => frame.scope,
sourceContents: sourceId => {
return new Promise((resolve, reject) => {
switch (sourceId) {
case "foo1":
resolve({
source: "function foo1() {\n return 5;\n}",
contentType: "text/javascript"
});
}
});
}
};
function createPauseInfo(overrides = {}) {
return {
frames: [{ id: 1, scope: [], location: { sourceId: "foo1", line: 4 } }],
loadedObjects: [],
why: {},
...overrides
};
}
describe("pause", () => {
describe("stepping", () => {
it("should set and clear the command", async () => {
const { dispatch, getState } = createStore(mockThreadClient);
const mockPauseInfo = createPauseInfo();
await dispatch(actions.newSource(makeSource("foo1")));
await dispatch(actions.paused(mockPauseInfo));
const stepped = dispatch(actions.stepIn());
expect(isStepping(getState())).toBeTruthy();
await stepInResolve();
await stepped;
expect(isStepping(getState())).toBeFalsy();
});
it("should only step when paused", async () => {
const client = { stepIn: jest.fn() };
const { dispatch } = createStore(client);
dispatch(actions.stepIn());
expect(client.stepIn.mock.calls).toHaveLength(0);
});
it("should step when paused", async () => {
const { dispatch, getState } = createStore(mockThreadClient);
const mockPauseInfo = createPauseInfo();
await dispatch(actions.newSource(makeSource("foo1")));
await dispatch(actions.paused(mockPauseInfo));
dispatch(actions.stepIn());
expect(isStepping(getState())).toBeTruthy();
});
});
describe("resumed", () => {
it("should not evaluate expression while stepping", async () => {
const client = { evaluate: jest.fn() };
const { dispatch } = createStore(client);
dispatch(actions.stepIn());
await dispatch(actions.resumed());
expect(client.evaluate.mock.calls).toHaveLength(0);
});
it("resuming - will re-evaluate watch expressions", async () => {
const store = createStore(mockThreadClient);
const { dispatch, getState } = store;
const mockPauseInfo = createPauseInfo();
await dispatch(actions.newSource(makeSource("foo1")));
dispatch(actions.addExpression("foo"));
await waitForState(store, state => selectors.getExpression(state, "foo"));
mockThreadClient.evaluate = () => new Promise(r => r("YAY"));
await dispatch(actions.paused(mockPauseInfo));
await dispatch(actions.resumed());
const expression = selectors.getExpression(getState(), "foo");
expect(expression.value).toEqual("YAY");
});
});
});