Skip to content

Commit

Permalink
Add proof of concept test
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Mar 7, 2017
1 parent 70d25c6 commit 0b97a32
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
72 changes: 72 additions & 0 deletions src/renderers/shared/__tests__/ReactDebugFiberPerf-test.js
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();
});
});
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)\\"
]
]
]"
`;

0 comments on commit 0b97a32

Please sign in to comment.