forked from firefox-devtools/profiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJsTracer.test.js
152 lines (131 loc) · 4.25 KB
/
JsTracer.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
/* 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 * as React from 'react';
import { Provider } from 'react-redux';
import { render, screen } from 'firefox-profiler/test/fixtures/testing-library';
import {
TIMELINE_MARGIN_LEFT,
TIMELINE_MARGIN_RIGHT,
} from '../../app-logic/constants';
import { JsTracer } from '../../components/js-tracer';
import { getShowJsTracerSummary } from '../../selectors/url-state';
import {
autoMockCanvasContext,
flushDrawLog,
} from '../fixtures/mocks/canvas-context';
import { mockRaf } from '../fixtures/mocks/request-animation-frame';
import { storeWithProfile } from '../fixtures/stores';
import {
addRootOverlayElement,
removeRootOverlayElement,
fireFullClick,
} from '../fixtures/utils';
import {
getProfileWithJsTracerEvents,
type TestDefinedJsTracerEvent,
} from '../fixtures/profiles/processed-profile';
import { autoMockElementSize } from '../fixtures/mocks/element-size';
jest.useFakeTimers();
const GRAPH_BASE_WIDTH = 200;
const GRAPH_WIDTH =
GRAPH_BASE_WIDTH + TIMELINE_MARGIN_LEFT + TIMELINE_MARGIN_RIGHT;
const GRAPH_HEIGHT = 300;
describe('StackChart', function () {
autoMockCanvasContext();
autoMockElementSize({ width: GRAPH_WIDTH, height: GRAPH_HEIGHT });
beforeEach(addRootOverlayElement);
afterEach(removeRootOverlayElement);
function setup({
skipLoadingScreen,
events,
}: {
skipLoadingScreen: boolean,
events: TestDefinedJsTracerEvent[],
}) {
const flushRafCalls = mockRaf();
const profile = getProfileWithJsTracerEvents(events);
const store = storeWithProfile(profile);
const { getState, dispatch } = store;
const renderResult = render(
<Provider store={store}>
<JsTracer />
</Provider>
);
const { container } = renderResult;
if (skipLoadingScreen) {
flushRafCalls();
}
const getJsTracerChartCanvas = () => container.querySelector('canvas');
const getChangeJsTracerSummaryCheckbox = () =>
screen.getByText(/Show only self time/);
return {
...renderResult,
dispatch,
getState,
flushRafCalls,
getJsTracerChartCanvas,
getChangeJsTracerSummaryCheckbox,
};
}
const simpleTracerEvents = [
['https://mozilla.org', 0, 20],
['Interpreter', 1, 19],
['IonMonkey', 2, 18],
];
it('only computes the chart after the first tick', () => {
const { getJsTracerChartCanvas, flushRafCalls } = setup({
skipLoadingScreen: false,
events: simpleTracerEvents,
});
expect(getJsTracerChartCanvas()).toBeFalsy();
flushRafCalls();
expect(getJsTracerChartCanvas()).toBeTruthy();
});
it('matches the snapshot for the loading screen', () => {
const { container } = setup({
skipLoadingScreen: false,
events: simpleTracerEvents,
});
expect(container.firstChild).toMatchSnapshot();
});
it('matches the snapshot for empty reasons screen', () => {
const { container } = setup({
skipLoadingScreen: true,
events: [],
});
expect(container.firstChild).toMatchSnapshot();
});
it('matches the snapshot for the chart', () => {
const { container } = setup({
skipLoadingScreen: true,
events: simpleTracerEvents,
});
expect(container.firstChild).toMatchSnapshot();
});
it('matches the snapshot a simple chart render', () => {
setup({
skipLoadingScreen: true,
events: simpleTracerEvents,
});
expect(flushDrawLog()).toMatchSnapshot();
});
it('can change to a summary view', function () {
const { getChangeJsTracerSummaryCheckbox, getState } = setup({
skipLoadingScreen: true,
events: simpleTracerEvents,
});
expect(getShowJsTracerSummary(getState())).toEqual(false);
fireFullClick(getChangeJsTracerSummaryCheckbox());
expect(getShowJsTracerSummary(getState())).toEqual(true);
});
it('matches the snapshot for an inverted draw call', function () {
const { getChangeJsTracerSummaryCheckbox } = setup({
skipLoadingScreen: true,
events: simpleTracerEvents,
});
fireFullClick(getChangeJsTracerSummaryCheckbox());
expect(flushDrawLog()).toMatchSnapshot();
});
});