forked from firefox-devtools/profiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs-allocations.test.js
173 lines (154 loc) · 5.61 KB
/
js-allocations.test.js
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
/* 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/. */
// @flow
import { getProfileWithJsAllocations } from '../fixtures/profiles/processed-profile';
import { formatTree } from '../fixtures/utils';
import { storeWithProfile } from '../fixtures/stores';
import {
changeCallTreeSummaryStrategy,
changeCallTreeSearchString,
changeInvertCallstack,
changeImplementationFilter,
addTransformToStack,
commitRange,
updatePreviewSelection,
} from '../../actions/profile-view';
import { selectedThreadSelectors } from '../../selectors/per-thread';
/**
* Test that the JsAllocationTable structure can by used with all of the call tree
* functionality, and that it obeys all of the transformation pipeline.
*/
describe('JS allocation call trees', function () {
function setup() {
const { profile, funcNamesDict } = getProfileWithJsAllocations();
// Create the store and switch to the JS allocations view.
const store = storeWithProfile(profile);
store.dispatch(changeCallTreeSummaryStrategy('js-allocations'));
return { ...store, funcNamesDict };
}
it('can create a call tree from JS allocations', function () {
const { getState } = setup();
const callTree = selectedThreadSelectors.getCallTree(getState());
expect(formatTree(callTree)).toEqual([
'- A (total: 15, self: —)',
' - B (total: 15, self: —)',
' - Fjs (total: 12, self: —)',
' - Gjs (total: 12, self: 5)',
' - Hjs (total: 7, self: —)',
' - I (total: 7, self: 7)',
' - C (total: 3, self: —)',
' - D (total: 3, self: —)',
' - E (total: 3, self: 3)',
]);
});
it('can search the allocations', function () {
const { getState, dispatch } = setup();
dispatch(changeCallTreeSearchString('H'));
const callTree = selectedThreadSelectors.getCallTree(getState());
expect(formatTree(callTree)).toEqual([
'- A (total: 7, self: —)',
' - B (total: 7, self: —)',
' - Fjs (total: 7, self: —)',
' - Gjs (total: 7, self: —)',
' - Hjs (total: 7, self: —)',
' - I (total: 7, self: 7)',
]);
});
it('can invert the allocation tree', function () {
const { getState, dispatch } = setup();
dispatch(changeInvertCallstack(true));
const callTree = selectedThreadSelectors.getCallTree(getState());
expect(formatTree(callTree)).toEqual([
'- I (total: 7, self: 7)',
' - Hjs (total: 7, self: —)',
' - Gjs (total: 7, self: —)',
' - Fjs (total: 7, self: —)',
' - B (total: 7, self: —)',
' - A (total: 7, self: —)',
'- Gjs (total: 5, self: 5)',
' - Fjs (total: 5, self: —)',
' - B (total: 5, self: —)',
' - A (total: 5, self: —)',
'- E (total: 3, self: 3)',
' - D (total: 3, self: —)',
' - C (total: 3, self: —)',
' - B (total: 3, self: —)',
' - A (total: 3, self: —)',
]);
});
it('can use an implementation filter', function () {
const { getState, dispatch } = setup();
dispatch(changeImplementationFilter('js'));
const callTree = selectedThreadSelectors.getCallTree(getState());
expect(formatTree(callTree)).toEqual([
'- Fjs (total: 12, self: —)',
' - Gjs (total: 12, self: 5)',
' - Hjs (total: 7, self: 7)',
]);
});
/**
* This test doesn't go through every single call tree transform, but lightly
* checks out the merge function transform, since the transforms should all go
* through the same stack updating path. This test only checks that one is correctly
* wired up.
*/
it('can apply a call tree transform', function () {
const {
getState,
dispatch,
funcNamesDict: { C },
} = setup();
dispatch(
addTransformToStack(0, {
type: 'merge-function',
funcIndex: C,
})
);
const callTree = selectedThreadSelectors.getCallTree(getState());
expect(formatTree(callTree)).toEqual([
'- A (total: 15, self: —)',
' - B (total: 15, self: —)',
' - Fjs (total: 12, self: —)',
' - Gjs (total: 12, self: 5)',
' - Hjs (total: 7, self: —)',
' - I (total: 7, self: 7)',
' - D (total: 3, self: —)',
' - E (total: 3, self: 3)',
]);
});
it('will apply a committed range selection', function () {
const { getState, dispatch } = setup();
dispatch(commitRange(0, 1.5));
const callTree = selectedThreadSelectors.getCallTree(getState());
expect(formatTree(callTree)).toEqual([
'- A (total: 8, self: —)',
' - B (total: 8, self: —)',
' - Fjs (total: 5, self: —)',
' - Gjs (total: 5, self: 5)',
' - C (total: 3, self: —)',
' - D (total: 3, self: —)',
' - E (total: 3, self: 3)',
]);
});
it('will apply a preview selection', function () {
const { getState, dispatch } = setup();
dispatch(commitRange(0, 1.5));
dispatch(
updatePreviewSelection({
hasSelection: true,
isModifying: false,
selectionStart: 0,
selectionEnd: 1,
})
);
const callTree = selectedThreadSelectors.getCallTree(getState());
expect(formatTree(callTree)).toEqual([
'- A (total: 3, self: —)',
' - B (total: 3, self: —)',
' - C (total: 3, self: —)',
' - D (total: 3, self: —)',
' - E (total: 3, self: 3)',
]);
});
});