added isProfiling() to ReactDebugTool and isRunning() to PerfTools
Nuno Campos committed
May 12, 2016 at 19:27 UTC
a027d15aff7982da3aa90ef9ae50c6cbb9f2009e
4 files changed
+28
src/isomorphic/ReactDebugTool.js
+3
@@ -115,6 +115,9 @@ var ReactDebugTool = {
115
}
116
}
117
},
118
+ isProfiling() {
119
+ return isProfiling;
120
+ },
121
beginProfiling() {
122
if (__DEV__) {
123
if (isProfiling) {
src/isomorphic/ReactPerf.js
+5
@@ -351,6 +351,10 @@ function stop() {
351
ReactDebugTool.endProfiling();
352
}
353
354
+function isRunning() {
355
+ return ReactDebugTool.isProfiling();
356
+}
357
+
358
var ReactPerfAnalysis = {
359
getLastMeasurements: getFlushHistory,
360
getExclusive,
@@ -363,6 +367,7 @@ var ReactPerfAnalysis = {
367
printOperations,
368
start,
369
stop,
370
+ isRunning,
371
// Deprecated:
372
printDOM,
373
getMeasurementsSummaryMap,
src/isomorphic/__tests__/ReactDebugTool-test.js
+10
@@ -72,4 +72,14 @@ describe('ReactDebugTool', function() {
72
ReactDebugTool.onTestEvent();
73
expect(console.error.calls.length).toBe(1);
74
});
75
+
76
+ it('returns isProfiling state', () => {
77
+ expect(ReactDebugTool.isProfiling()).toBe(false);
78
+
79
+ ReactDebugTool.beginProfiling();
80
+ expect(ReactDebugTool.isProfiling()).toBe(true);
81
+
82
+ ReactDebugTool.endProfiling();
83
+ expect(ReactDebugTool.isProfiling()).toBe(false);
84
+ });
85
});
src/isomorphic/__tests__/ReactPerf-test.js
+10
@@ -16,6 +16,7 @@ describe('ReactPerf', function() {
16
var ReactDOM;
17
var ReactPerf;
18
var ReactTestUtils;
19
+ var ReactDebugTool;
20
21
var App;
22
var Box;
@@ -36,6 +37,7 @@ describe('ReactPerf', function() {
37
ReactDOM = require('ReactDOM');
38
ReactPerf = require('ReactPerf');
39
ReactTestUtils = require('ReactTestUtils');
40
+ ReactDebugTool = require('ReactDebugTool');
41
42
App = React.createClass({
43
render: function() {
@@ -283,4 +285,12 @@ describe('ReactPerf', function() {
285
ReactPerf.printDOM(measurements);
286
expect(console.error.calls.length).toBe(1);
287
});
288
+
289
+ it('returns isRunning state', () => {
290
+ spyOn(ReactDebugTool, 'isProfiling');
291
+
292
+ ReactPerf.isRunning();
293
+ expect(ReactDebugTool.isProfiling.calls.length).toBe(1);
294
+ expect(ReactPerf.isRunning()).toBe(ReactDebugTool.isProfiling());
295
+ });
296
});