From a027d15aff7982da3aa90ef9ae50c6cbb9f2009e Mon Sep 17 00:00:00 2001 From: Nuno Campos Date: Thu, 12 May 2016 19:27:05 +0100 Subject: [PATCH 1/3] added isProfiling() to ReactDebugTool and isRunning() to PerfTools --- src/isomorphic/ReactDebugTool.js | 3 +++ src/isomorphic/ReactPerf.js | 5 +++++ src/isomorphic/__tests__/ReactDebugTool-test.js | 10 ++++++++++ src/isomorphic/__tests__/ReactPerf-test.js | 10 ++++++++++ 4 files changed, 28 insertions(+) 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..81e5131855282 100644 --- a/src/isomorphic/__tests__/ReactPerf-test.js +++ b/src/isomorphic/__tests__/ReactPerf-test.js @@ -16,6 +16,7 @@ describe('ReactPerf', function() { var ReactDOM; var ReactPerf; var ReactTestUtils; + var ReactDebugTool; var App; var Box; @@ -36,6 +37,7 @@ describe('ReactPerf', function() { ReactDOM = require('ReactDOM'); ReactPerf = require('ReactPerf'); ReactTestUtils = require('ReactTestUtils'); + ReactDebugTool = require('ReactDebugTool'); App = React.createClass({ render: function() { @@ -283,4 +285,12 @@ describe('ReactPerf', function() { ReactPerf.printDOM(measurements); expect(console.error.calls.length).toBe(1); }); + + it('returns isRunning state', () => { + spyOn(ReactDebugTool, 'isProfiling'); + + ReactPerf.isRunning(); + expect(ReactDebugTool.isProfiling.calls.length).toBe(1); + expect(ReactPerf.isRunning()).toBe(ReactDebugTool.isProfiling()); + }); }); From 201d03268eba263684a756f1f114ec8e8a2ecc35 Mon Sep 17 00:00:00 2001 From: Nuno Campos Date: Fri, 13 May 2016 08:24:25 +0100 Subject: [PATCH 2/3] changed test --- src/isomorphic/__tests__/ReactPerf-test.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/isomorphic/__tests__/ReactPerf-test.js b/src/isomorphic/__tests__/ReactPerf-test.js index 81e5131855282..fd727672741b3 100644 --- a/src/isomorphic/__tests__/ReactPerf-test.js +++ b/src/isomorphic/__tests__/ReactPerf-test.js @@ -16,7 +16,6 @@ describe('ReactPerf', function() { var ReactDOM; var ReactPerf; var ReactTestUtils; - var ReactDebugTool; var App; var Box; @@ -37,7 +36,6 @@ describe('ReactPerf', function() { ReactDOM = require('ReactDOM'); ReactPerf = require('ReactPerf'); ReactTestUtils = require('ReactTestUtils'); - ReactDebugTool = require('ReactDebugTool'); App = React.createClass({ render: function() { @@ -287,10 +285,12 @@ describe('ReactPerf', function() { }); it('returns isRunning state', () => { - spyOn(ReactDebugTool, 'isProfiling'); + expect(ReactPerf.isRunning()).toBe(false); - ReactPerf.isRunning(); - expect(ReactDebugTool.isProfiling.calls.length).toBe(1); - expect(ReactPerf.isRunning()).toBe(ReactDebugTool.isProfiling()); + ReactPerf.start(); + expect(ReactPerf.isRunning()).toBe(true); + + ReactPerf.stop(); + expect(ReactPerf.isRunning()).toBe(false); }); }); From 5b93a2bdbec4878991d47ef7189032ac98bdbe33 Mon Sep 17 00:00:00 2001 From: Nuno Campos Date: Fri, 13 May 2016 20:28:14 +0100 Subject: [PATCH 3/3] added tests for repeated calls to ReactPerf.start/stop --- src/isomorphic/__tests__/ReactPerf-test.js | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/isomorphic/__tests__/ReactPerf-test.js b/src/isomorphic/__tests__/ReactPerf-test.js index fd727672741b3..0a24bb9919d7f 100644 --- a/src/isomorphic/__tests__/ReactPerf-test.js +++ b/src/isomorphic/__tests__/ReactPerf-test.js @@ -293,4 +293,27 @@ describe('ReactPerf', function() { 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); + }); });