-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
src/renderers/shared/__tests__/ReactDebugFiberPerf-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* Copyright 2016-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @emails react-core | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var ReactDOMFeatureFlags = require('ReactDOMFeatureFlags'); | ||
|
||
describe('ReactDebugFiberPerf', () => { | ||
var React; | ||
var ReactDOM; | ||
|
||
var currentPeriod = { | ||
name: null, | ||
label: null, | ||
parent: null, | ||
children: [], | ||
}; | ||
|
||
function getFlameChart() { | ||
return JSON.stringify(currentPeriod.children[0], null, 2); | ||
} | ||
|
||
beforeEach(() => { | ||
global.performance = { | ||
mark(markName) { | ||
var period = { | ||
name: markName, | ||
label: null, | ||
parent: currentPeriod, | ||
children: [], | ||
toJSON() { | ||
return [this.label, ...this.children.map(c => c.toJSON())]; | ||
} | ||
}; | ||
currentPeriod.children.push(period); | ||
currentPeriod = period; | ||
}, | ||
measure(label, markName) { | ||
if (markName !== currentPeriod.name) { | ||
throw new Error('Unexpected measure() call.'); | ||
} | ||
currentPeriod.label = label; | ||
currentPeriod = currentPeriod.parent; | ||
}, | ||
clearMarks() {}, | ||
clearMeasures() {}, | ||
}; | ||
React = require('react'); | ||
ReactDOM = require('react-dom'); | ||
}); | ||
|
||
function Row() { | ||
return <div />; | ||
} | ||
|
||
it('runs', () => { | ||
if (!ReactDOMFeatureFlags.useFiber) { | ||
return; | ||
} | ||
const container = document.createElement('div'); | ||
ReactDOM.render(<Row />, container); | ||
expect(getFlameChart()).toMatchSnapshot(); | ||
}); | ||
}); |
19 changes: 19 additions & 0 deletions
19
src/renderers/shared/__tests__/__snapshots__/ReactDebugFiberPerf-test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`ReactDebugFiberPerf runs 1`] = ` | ||
"[ | ||
\\"⚛ (React Tree Reconciliation)\\", | ||
[ | ||
\\"⚛ Row [mount]\\" | ||
], | ||
[ | ||
\\"⚛ (Committing Changes)\\", | ||
[ | ||
\\"⚛ (Committing Host Effects: 1 Total)\\" | ||
], | ||
[ | ||
\\"⚛ (Calling Lifecycle Methods: 1 Total)\\" | ||
] | ||
] | ||
]" | ||
`; |