mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 00:20:04 +01:00
Enable linting in src/tests, cleanup
This commit is contained in:
parent
8f419c956e
commit
a28325e412
|
|
@ -1,7 +1,5 @@
|
|||
# We can probably lint these later but not important at this point
|
||||
src/shared/vendor
|
||||
# This should be enabled but that folder has too much in it that doesn't belong
|
||||
src/test
|
||||
# But not in docs/_js/examples/*
|
||||
docs/_js/*.js
|
||||
docs/js/
|
||||
|
|
|
|||
|
|
@ -28,7 +28,9 @@ function getRunnerWithResults(describeFunction) {
|
|||
// Execute the tests synchronously.
|
||||
env.updateInterval = 0;
|
||||
var outerGetEnv = jasmine.getEnv;
|
||||
jasmine.getEnv = function() { return env; };
|
||||
jasmine.getEnv = function() {
|
||||
return env;
|
||||
};
|
||||
// TODO: Bring over matchers from the existing environment.
|
||||
var runner = env.currentRunner();
|
||||
try {
|
||||
|
|
@ -116,11 +118,11 @@ var MetaMatchers = {
|
|||
this.message = function() {
|
||||
return [
|
||||
errorMessage,
|
||||
'The specs are equal. Expected them to be different.'
|
||||
'The specs are equal. Expected them to be different.',
|
||||
];
|
||||
};
|
||||
return !errorMessage;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = MetaMatchers;
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ var ReactDefaultPerf = {
|
|||
'Exclusive render time (ms)': roundFloat(item.render),
|
||||
'Mount time per instance (ms)': roundFloat(item.exclusive / item.count),
|
||||
'Render time per instance (ms)': roundFloat(item.render / item.count),
|
||||
'Instances': item.count
|
||||
'Instances': item.count,
|
||||
};
|
||||
}));
|
||||
// TODO: ReactDefaultPerfAnalysis.getTotalTime() does not return the correct
|
||||
|
|
@ -74,7 +74,7 @@ var ReactDefaultPerf = {
|
|||
return {
|
||||
'Owner > component': item.componentName,
|
||||
'Inclusive time (ms)': roundFloat(item.time),
|
||||
'Instances': item.count
|
||||
'Instances': item.count,
|
||||
};
|
||||
}));
|
||||
console.log(
|
||||
|
|
@ -92,7 +92,7 @@ var ReactDefaultPerf = {
|
|||
return {
|
||||
'Owner > component': item.componentName,
|
||||
'Wasted time (ms)': item.time,
|
||||
'Instances': item.count
|
||||
'Instances': item.count,
|
||||
};
|
||||
});
|
||||
},
|
||||
|
|
@ -112,8 +112,8 @@ var ReactDefaultPerf = {
|
|||
console.table(summary.map(function(item) {
|
||||
var result = {};
|
||||
result[DOMProperty.ID_ATTRIBUTE_NAME] = item.id;
|
||||
result['type'] = item.type;
|
||||
result['args'] = JSON.stringify(item.args);
|
||||
result.type = item.type;
|
||||
result.args = JSON.stringify(item.args);
|
||||
return result;
|
||||
}));
|
||||
console.log(
|
||||
|
|
@ -132,7 +132,7 @@ var ReactDefaultPerf = {
|
|||
writes[id].push({
|
||||
type: fnName,
|
||||
time: totalTime,
|
||||
args: args
|
||||
args: args,
|
||||
});
|
||||
},
|
||||
|
||||
|
|
@ -155,7 +155,7 @@ var ReactDefaultPerf = {
|
|||
counts: {},
|
||||
writes: {},
|
||||
displayNames: {},
|
||||
totalTime: 0
|
||||
totalTime: 0,
|
||||
});
|
||||
start = performanceNow();
|
||||
rv = func.apply(this, args);
|
||||
|
|
@ -250,7 +250,7 @@ var ReactDefaultPerf = {
|
|||
current: this.getName(),
|
||||
owner: this._currentElement._owner ?
|
||||
this._currentElement._owner.getName() :
|
||||
'<root>'
|
||||
'<root>',
|
||||
};
|
||||
|
||||
return rv;
|
||||
|
|
@ -258,7 +258,7 @@ var ReactDefaultPerf = {
|
|||
return func.apply(this, args);
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = ReactDefaultPerf;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@
|
|||
* @providesModule ReactDefaultPerfAnalysis
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var assign = require('Object.assign');
|
||||
|
||||
// Don't try to save users less than 1.2ms (a number I made up)
|
||||
|
|
@ -23,7 +25,7 @@ var DOM_OPERATION_TYPES = {
|
|||
'deletePropertyByID': 'delete attribute',
|
||||
'updateStylesByID': 'update styles',
|
||||
'updateInnerHTMLByID': 'set innerHTML',
|
||||
'dangerouslyReplaceNodeWithMarkupByID': 'replace'
|
||||
'dangerouslyReplaceNodeWithMarkupByID': 'replace',
|
||||
};
|
||||
|
||||
function getTotalTime(measurements) {
|
||||
|
|
@ -41,20 +43,17 @@ function getTotalTime(measurements) {
|
|||
|
||||
function getDOMSummary(measurements) {
|
||||
var items = [];
|
||||
for (var i = 0; i < measurements.length; i++) {
|
||||
var measurement = measurements[i];
|
||||
var id;
|
||||
|
||||
for (id in measurement.writes) {
|
||||
measurements.forEach(function(measurement) {
|
||||
Object.keys(measurement.writes).forEach(function(id) {
|
||||
measurement.writes[id].forEach(function(write) {
|
||||
items.push({
|
||||
id: id,
|
||||
type: DOM_OPERATION_TYPES[write.type] || write.type,
|
||||
args: write.args
|
||||
args: write.args,
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
return items;
|
||||
}
|
||||
|
||||
|
|
@ -78,7 +77,7 @@ function getExclusiveSummary(measurements) {
|
|||
inclusive: 0,
|
||||
exclusive: 0,
|
||||
render: 0,
|
||||
count: 0
|
||||
count: 0,
|
||||
};
|
||||
if (measurement.render[id]) {
|
||||
candidates[displayName].render += measurement.render[id];
|
||||
|
|
@ -142,7 +141,7 @@ function getInclusiveSummary(measurements, onlyClean) {
|
|||
candidates[inclusiveKey] = candidates[inclusiveKey] || {
|
||||
componentName: inclusiveKey,
|
||||
time: 0,
|
||||
count: 0
|
||||
count: 0,
|
||||
};
|
||||
|
||||
if (measurement.inclusive[id]) {
|
||||
|
|
@ -198,7 +197,7 @@ var ReactDefaultPerfAnalysis = {
|
|||
getExclusiveSummary: getExclusiveSummary,
|
||||
getInclusiveSummary: getInclusiveSummary,
|
||||
getDOMSummary: getDOMSummary,
|
||||
getTotalTime: getTotalTime
|
||||
getTotalTime: getTotalTime,
|
||||
};
|
||||
|
||||
module.exports = ReactDefaultPerfAnalysis;
|
||||
|
|
|
|||
|
|
@ -81,8 +81,8 @@ var ReactPerf = {
|
|||
*/
|
||||
injectMeasure: function(measure) {
|
||||
ReactPerf.storedMeasure = measure;
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -279,7 +279,7 @@ var ReactTestUtils = {
|
|||
* @return {object} the ReactTestUtils object (for chaining)
|
||||
*/
|
||||
mockComponent: function(module, mockTagName) {
|
||||
mockTagName = mockTagName || module.mockTagName || "div";
|
||||
mockTagName = mockTagName || module.mockTagName || 'div';
|
||||
|
||||
module.prototype.render.mockImplementation(function() {
|
||||
return React.createElement(
|
||||
|
|
@ -328,8 +328,8 @@ var ReactTestUtils = {
|
|||
nativeTouchData: function(x, y) {
|
||||
return {
|
||||
touches: [
|
||||
{pageX: x, pageY: y}
|
||||
]
|
||||
{pageX: x, pageY: y},
|
||||
],
|
||||
};
|
||||
},
|
||||
|
||||
|
|
@ -338,7 +338,7 @@ var ReactTestUtils = {
|
|||
},
|
||||
|
||||
Simulate: null,
|
||||
SimulateNative: {}
|
||||
SimulateNative: {},
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -376,7 +376,7 @@ NoopInternalComponent.prototype = {
|
|||
},
|
||||
|
||||
unmountComponent: function() {
|
||||
}
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
|
|
@ -389,8 +389,8 @@ assign(
|
|||
},
|
||||
_replaceNodeWithMarkupByID: function() {},
|
||||
_renderValidatedComponent:
|
||||
ReactCompositeComponent.Mixin.
|
||||
_renderValidatedComponentWithoutOwnerOrContext
|
||||
ReactCompositeComponent.Mixin
|
||||
._renderValidatedComponentWithoutOwnerOrContext,
|
||||
}
|
||||
);
|
||||
|
||||
|
|
@ -521,7 +521,7 @@ function makeNativeSimulator(eventType) {
|
|||
domComponentOrNode,
|
||||
fakeNativeEvent
|
||||
);
|
||||
} else if (!!domComponentOrNode.tagName) {
|
||||
} else if (domComponentOrNode.tagName) {
|
||||
// Will allow on actual dom nodes.
|
||||
ReactTestUtils.simulateNativeEventOnNode(
|
||||
eventType,
|
||||
|
|
@ -532,8 +532,7 @@ function makeNativeSimulator(eventType) {
|
|||
};
|
||||
}
|
||||
|
||||
var eventType;
|
||||
for (eventType in topLevelTypes) {
|
||||
Object.keys(topLevelTypes).forEach(function(eventType) {
|
||||
// Event type is stored as 'topClick' - we transform that to 'click'
|
||||
var convenienceName = eventType.indexOf('top') === 0 ?
|
||||
eventType.charAt(3).toLowerCase() + eventType.substr(4) : eventType;
|
||||
|
|
@ -543,6 +542,6 @@ for (eventType in topLevelTypes) {
|
|||
*/
|
||||
ReactTestUtils.SimulateNative[convenienceName] =
|
||||
makeNativeSimulator(eventType);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = ReactTestUtils;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@
|
|||
* @emails react-core
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var MetaMatchers = require('MetaMatchers');
|
||||
|
||||
describe('meta-matchers', function() {
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ describe('ReactTestUtils', function() {
|
|||
<span className="child2" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
var shallowRenderer = ReactTestUtils.createRenderer();
|
||||
|
|
@ -45,7 +45,7 @@ describe('ReactTestUtils', function() {
|
|||
expect(result.type).toBe('div');
|
||||
expect(result.props.children).toEqual([
|
||||
<span className="child1" />,
|
||||
<span className="child2" />
|
||||
<span className="child2" />,
|
||||
]);
|
||||
});
|
||||
|
||||
|
|
@ -56,7 +56,7 @@ describe('ReactTestUtils', function() {
|
|||
render: function() {
|
||||
return <div />;
|
||||
},
|
||||
componentWillUnmount
|
||||
componentWillUnmount,
|
||||
});
|
||||
|
||||
var shallowRenderer = ReactTestUtils.createRenderer();
|
||||
|
|
@ -70,7 +70,7 @@ describe('ReactTestUtils', function() {
|
|||
var SomeComponent = React.createClass({
|
||||
render: function() {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
var shallowRenderer = ReactTestUtils.createRenderer();
|
||||
|
|
@ -111,7 +111,7 @@ describe('ReactTestUtils', function() {
|
|||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
var shallowRenderer = ReactTestUtils.createRenderer();
|
||||
|
|
@ -120,7 +120,7 @@ describe('ReactTestUtils', function() {
|
|||
expect(result.type).toBe('div');
|
||||
expect(result.props.children).toEqual([
|
||||
<span className="child1" />,
|
||||
<span className="child2" />
|
||||
<span className="child2" />,
|
||||
]);
|
||||
|
||||
shallowRenderer.render(<SomeComponent aNew="prop" />);
|
||||
|
|
@ -163,7 +163,7 @@ describe('ReactTestUtils', function() {
|
|||
|
||||
var shallowRenderer = ReactTestUtils.createRenderer();
|
||||
shallowRenderer.render(<SimpleComponent />, {
|
||||
name: "foo",
|
||||
name: 'foo',
|
||||
});
|
||||
var result = shallowRenderer.getRenderOutput();
|
||||
expect(result).toEqual(<div>foo</div>);
|
||||
|
|
@ -236,7 +236,7 @@ describe('ReactTestUtils', function() {
|
|||
var Foo = React.createClass({
|
||||
render: function() {
|
||||
return <div />;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
class Bar extends React.Component {
|
||||
|
|
@ -270,15 +270,15 @@ describe('ReactTestUtils', function() {
|
|||
'input',
|
||||
'option',
|
||||
'select',
|
||||
'textarea'
|
||||
'textarea',
|
||||
];
|
||||
|
||||
injectedDOMComponents.forEach(function(type) {
|
||||
var component = ReactTestUtils.renderIntoDocument(
|
||||
var testComponent = ReactTestUtils.renderIntoDocument(
|
||||
React.createElement(type)
|
||||
);
|
||||
expect(component.tagName).toBe(type.toUpperCase());
|
||||
expect(ReactTestUtils.isDOMComponent(component)).toBe(true);
|
||||
expect(testComponent.tagName).toBe(type.toUpperCase());
|
||||
expect(ReactTestUtils.isDOMComponent(testComponent)).toBe(true);
|
||||
});
|
||||
|
||||
// Full-page components (html, head, body) can't be rendered into a div
|
||||
|
|
@ -295,7 +295,7 @@ describe('ReactTestUtils', function() {
|
|||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
var markup = React.renderToString(<Root />);
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ describe('reactComponentExpect', function() {
|
|||
{'This is text'}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
var component = ReactTestUtils.renderIntoDocument(<SomeComponent />);
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@
|
|||
* @providesModule createHierarchyRenderer
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var React = require('React');
|
||||
|
||||
/**
|
||||
|
|
@ -53,15 +55,15 @@ var React = require('React');
|
|||
function createHierarchyRenderer(...renderMethods) {
|
||||
var instances;
|
||||
var Components = renderMethods.reduceRight(
|
||||
function(Components, renderMethod, depth) {
|
||||
function(ComponentsAccumulator, renderMethod, depth) {
|
||||
var Component = React.createClass({
|
||||
displayName: renderMethod.name,
|
||||
render: function() {
|
||||
instances[depth].push(this);
|
||||
return renderMethod.apply(this, Components);
|
||||
}
|
||||
return renderMethod.apply(this, ComponentsAccumulator);
|
||||
},
|
||||
});
|
||||
return [Component].concat(Components);
|
||||
return [Component].concat(ComponentsAccumulator);
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
|
|
|||
|
|
@ -218,7 +218,7 @@ assign(reactComponentExpectInternal.prototype, {
|
|||
.toEqual(contextNameToExpectedValue[contextName]);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = reactComponentExpect;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user