Skip to content

Commit

Permalink
Merge pull request facebook#6763 from nfcampos/is-running
Browse files Browse the repository at this point in the history
added isProfiling() to ReactDebugTool and isRunning() to PerfTools
(cherry picked from commit 5569d1d)
  • Loading branch information
gaearon authored and zpao committed Jun 8, 2016
1 parent 660b4f5 commit af0a915
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/isomorphic/ReactDebugTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ var ReactDebugTool = {
}
}
},
isProfiling() {
return isProfiling;
},
beginProfiling() {
if (__DEV__) {
if (isProfiling) {
Expand Down
5 changes: 5 additions & 0 deletions src/isomorphic/ReactPerf.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,10 @@ function stop() {
ReactDebugTool.endProfiling();
}

function isRunning() {
return ReactDebugTool.isProfiling();
}

var ReactPerfAnalysis = {
getLastMeasurements: getFlushHistory,
getExclusive,
Expand All @@ -363,6 +367,7 @@ var ReactPerfAnalysis = {
printOperations,
start,
stop,
isRunning,
// Deprecated:
printDOM,
getMeasurementsSummaryMap,
Expand Down
10 changes: 10 additions & 0 deletions src/isomorphic/__tests__/ReactDebugTool-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
33 changes: 33 additions & 0 deletions src/isomorphic/__tests__/ReactPerf-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit af0a915

Please sign in to comment.