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
  • Loading branch information
gaearon committed May 13, 2016
2 parents 20bcabb + 5b93a2b commit 5569d1d
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 5569d1d

Please sign in to comment.