diff --git a/src/isomorphic/ReactDebugTool.js b/src/isomorphic/ReactDebugTool.js index 63f3251847ac1..5145f8ab314f2 100644 --- a/src/isomorphic/ReactDebugTool.js +++ b/src/isomorphic/ReactDebugTool.js @@ -115,6 +115,9 @@ var ReactDebugTool = { } } }, + isProfiling() { + return isProfiling; + }, beginProfiling() { if (__DEV__) { if (isProfiling) { diff --git a/src/isomorphic/ReactPerf.js b/src/isomorphic/ReactPerf.js index 01f1aee388807..209651e21693c 100644 --- a/src/isomorphic/ReactPerf.js +++ b/src/isomorphic/ReactPerf.js @@ -351,6 +351,10 @@ function stop() { ReactDebugTool.endProfiling(); } +function isRunning() { + return ReactDebugTool.isProfiling(); +} + var ReactPerfAnalysis = { getLastMeasurements: getFlushHistory, getExclusive, @@ -363,6 +367,7 @@ var ReactPerfAnalysis = { printOperations, start, stop, + isRunning, // Deprecated: printDOM, getMeasurementsSummaryMap, diff --git a/src/isomorphic/__tests__/ReactDebugTool-test.js b/src/isomorphic/__tests__/ReactDebugTool-test.js index bae09516f5186..889b9097982b5 100644 --- a/src/isomorphic/__tests__/ReactDebugTool-test.js +++ b/src/isomorphic/__tests__/ReactDebugTool-test.js @@ -72,4 +72,14 @@ describe('ReactDebugTool', function() { ReactDebugTool.onTestEvent(); expect(console.error.calls.length).toBe(1); }); + + it('returns isProfiling state', () => { + expect(ReactDebugTool.isProfiling()).toBe(false); + + ReactDebugTool.beginProfiling(); + expect(ReactDebugTool.isProfiling()).toBe(true); + + ReactDebugTool.endProfiling(); + expect(ReactDebugTool.isProfiling()).toBe(false); + }); }); diff --git a/src/isomorphic/__tests__/ReactPerf-test.js b/src/isomorphic/__tests__/ReactPerf-test.js index 644bc618b849f..0a24bb9919d7f 100644 --- a/src/isomorphic/__tests__/ReactPerf-test.js +++ b/src/isomorphic/__tests__/ReactPerf-test.js @@ -283,4 +283,37 @@ describe('ReactPerf', function() { ReactPerf.printDOM(measurements); expect(console.error.calls.length).toBe(1); }); + + it('returns isRunning state', () => { + expect(ReactPerf.isRunning()).toBe(false); + + ReactPerf.start(); + expect(ReactPerf.isRunning()).toBe(true); + + ReactPerf.stop(); + expect(ReactPerf.isRunning()).toBe(false); + }); + + it('start has no effect when already running', () => { + expect(ReactPerf.isRunning()).toBe(false); + + ReactPerf.start(); + expect(ReactPerf.isRunning()).toBe(true); + + ReactPerf.start(); + expect(ReactPerf.isRunning()).toBe(true); + + ReactPerf.stop(); + expect(ReactPerf.isRunning()).toBe(false); + }); + + it('stop has no effect when already stopped', () => { + expect(ReactPerf.isRunning()).toBe(false); + + ReactPerf.stop(); + expect(ReactPerf.isRunning()).toBe(false); + + ReactPerf.stop(); + expect(ReactPerf.isRunning()).toBe(false); + }); });