mirror of
https://github.com/zhigang1992/react-native-web.git
synced 2026-04-22 19:58:25 +08:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ba96e457b4 | ||
|
|
bdfe943bd5 | ||
|
|
3870445b7e | ||
|
|
5395a3e8bc | ||
|
|
45b3d8b0df | ||
|
|
f1ee3c003a | ||
|
|
606181406c | ||
|
|
b537400f38 | ||
|
|
0a4fdc155e | ||
|
|
0b8e59974b | ||
|
|
22eebea633 | ||
|
|
5dd414f9aa | ||
|
|
72c72f6530 | ||
|
|
de970f9dbb | ||
|
|
e8d6c5b4dd | ||
|
|
e91a5ae13e | ||
|
|
b08bfb9ad5 | ||
|
|
5353011ee4 |
@@ -5,5 +5,5 @@ before_script:
|
|||||||
- export DISPLAY=:99.0
|
- export DISPLAY=:99.0
|
||||||
- sh -e /etc/init.d/xvfb start
|
- sh -e /etc/init.d/xvfb start
|
||||||
script:
|
script:
|
||||||
- npm run lint
|
- yarn lint
|
||||||
- npm test
|
- yarn test:ci
|
||||||
|
|||||||
@@ -103,3 +103,59 @@ const { InvalidThing, TouchableOpacity } = require('react-native');
|
|||||||
const TouchableOpacity = require('react-native-web/dist/components/Touchable/TouchableOpacity');
|
const TouchableOpacity = require('react-native-web/dist/components/Touchable/TouchableOpacity');
|
||||||
"
|
"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`10. Rewrite react-native paths for react-native-web 1`] = `
|
||||||
|
"
|
||||||
|
export { View } from 'react-native';
|
||||||
|
|
||||||
|
↓ ↓ ↓ ↓ ↓ ↓
|
||||||
|
|
||||||
|
export { default as View } from 'react-native-web/dist/components/View';
|
||||||
|
"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`11. Rewrite react-native paths for react-native-web 1`] = `
|
||||||
|
"
|
||||||
|
export { Switch, Text, View as MyView, ViewPropTypes } from 'react-native';
|
||||||
|
|
||||||
|
↓ ↓ ↓ ↓ ↓ ↓
|
||||||
|
|
||||||
|
export { default as Switch } from 'react-native-web/dist/components/Switch';
|
||||||
|
export { default as Text } from 'react-native-web/dist/components/Text';
|
||||||
|
export { default as MyView } from 'react-native-web/dist/components/View';
|
||||||
|
export { default as ViewPropTypes } from 'react-native-web/dist/components/View/ViewPropTypes';
|
||||||
|
"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`12. Rewrite react-native paths for react-native-web 1`] = `
|
||||||
|
"
|
||||||
|
export { createElement, Switch, StyleSheet } from 'react-native';
|
||||||
|
|
||||||
|
↓ ↓ ↓ ↓ ↓ ↓
|
||||||
|
|
||||||
|
export { default as createElement } from 'react-native-web/dist/modules/createElement';
|
||||||
|
export { default as Switch } from 'react-native-web/dist/components/Switch';
|
||||||
|
export { default as StyleSheet } from 'react-native-web/dist/apis/StyleSheet';
|
||||||
|
"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`13. Rewrite react-native paths for react-native-web 1`] = `
|
||||||
|
"
|
||||||
|
export { InvalidThing, TouchableOpacity } from 'react-native';
|
||||||
|
|
||||||
|
↓ ↓ ↓ ↓ ↓ ↓
|
||||||
|
|
||||||
|
export { InvalidThing } from 'react-native-web';
|
||||||
|
export { default as TouchableOpacity } from 'react-native-web/dist/components/Touchable/TouchableOpacity';
|
||||||
|
"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`14. Rewrite react-native paths for react-native-web 1`] = `
|
||||||
|
"
|
||||||
|
export { default as RNW } from 'react-native';
|
||||||
|
|
||||||
|
↓ ↓ ↓ ↓ ↓ ↓
|
||||||
|
|
||||||
|
export { default as RNW } from 'react-native-web';
|
||||||
|
"
|
||||||
|
`;
|
||||||
|
|||||||
@@ -30,6 +30,13 @@ pluginTester({
|
|||||||
// "let { Switch, Text, View: MyView } = require('react-native-web');",
|
// "let { Switch, Text, View: MyView } = require('react-native-web');",
|
||||||
// "var { createElement, Switch, StyleSheet } = require('react-native-web');",
|
// "var { createElement, Switch, StyleSheet } = require('react-native-web');",
|
||||||
// "const { InvalidThing, TouchableOpacity } = require('react-native-web');",
|
// "const { InvalidThing, TouchableOpacity } = require('react-native-web');",
|
||||||
|
|
||||||
|
// export react-native
|
||||||
|
"export { View } from 'react-native';",
|
||||||
|
"export { Switch, Text, View as MyView, ViewPropTypes } from 'react-native';",
|
||||||
|
"export { createElement, Switch, StyleSheet } from 'react-native';",
|
||||||
|
"export { InvalidThing, TouchableOpacity } from 'react-native';",
|
||||||
|
"export { default as RNW } from 'react-native';",
|
||||||
{
|
{
|
||||||
code: "const RNW = require('react-native');",
|
code: "const RNW = require('react-native');",
|
||||||
output: "const RNW = require('react-native');",
|
output: "const RNW = require('react-native');",
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ const getDistLocation = importName => {
|
|||||||
case 'AppRegistry':
|
case 'AppRegistry':
|
||||||
case 'AppState':
|
case 'AppState':
|
||||||
case 'AsyncStorage':
|
case 'AsyncStorage':
|
||||||
case 'BackAndroid':
|
case 'BackHandler':
|
||||||
case 'Clipboard':
|
case 'Clipboard':
|
||||||
case 'Dimensions':
|
case 'Dimensions':
|
||||||
case 'Easing':
|
case 'Easing':
|
||||||
@@ -106,7 +106,7 @@ module.exports = function({ types: t }) {
|
|||||||
visitor: {
|
visitor: {
|
||||||
ImportDeclaration(path) {
|
ImportDeclaration(path) {
|
||||||
const { source, specifiers } = path.node;
|
const { source, specifiers } = path.node;
|
||||||
if (source.value === 'react-native' && specifiers.length) {
|
if (source && source.value === 'react-native' && specifiers.length) {
|
||||||
const imports = specifiers
|
const imports = specifiers
|
||||||
.map(specifier => {
|
.map(specifier => {
|
||||||
if (t.isImportSpecifier(specifier)) {
|
if (t.isImportSpecifier(specifier)) {
|
||||||
@@ -127,6 +127,35 @@ module.exports = function({ types: t }) {
|
|||||||
path.replaceWithMultiple(imports);
|
path.replaceWithMultiple(imports);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
ExportNamedDeclaration(path) {
|
||||||
|
const { source, specifiers } = path.node;
|
||||||
|
if (source && source.value === 'react-native' && specifiers.length) {
|
||||||
|
const exports = specifiers
|
||||||
|
.map(specifier => {
|
||||||
|
if (t.isExportSpecifier(specifier)) {
|
||||||
|
const exportName = specifier.exported.name;
|
||||||
|
const localName = specifier.local.name;
|
||||||
|
const distLocation = getDistLocation(localName);
|
||||||
|
|
||||||
|
if (distLocation) {
|
||||||
|
return t.exportNamedDeclaration(
|
||||||
|
null,
|
||||||
|
[t.exportSpecifier(t.identifier('default'), t.identifier(exportName))],
|
||||||
|
t.stringLiteral(distLocation)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return t.exportNamedDeclaration(
|
||||||
|
null,
|
||||||
|
[specifier],
|
||||||
|
t.stringLiteral('react-native-web')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.filter(Boolean);
|
||||||
|
|
||||||
|
path.replaceWithMultiple(exports);
|
||||||
|
}
|
||||||
|
},
|
||||||
VariableDeclaration(path) {
|
VariableDeclaration(path) {
|
||||||
if (isReactNativeRequire(t, path.node)) {
|
if (isReactNativeRequire(t, path.node)) {
|
||||||
const { id } = path.node.declarations[0];
|
const { id } = path.node.declarations[0];
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ const babelLoaderConfiguration = {
|
|||||||
cacheDirectory: true,
|
cacheDirectory: true,
|
||||||
// This aliases 'react-native' to 'react-native-web' and includes only
|
// This aliases 'react-native' to 'react-native-web' and includes only
|
||||||
// the modules needed by the app
|
// the modules needed by the app
|
||||||
plugins: ['react-native-web/babel']
|
plugins: ['react-native-web/babel'],
|
||||||
// The 'react-native' preset is recommended (or use your own .babelrc)
|
// The 'react-native' preset is recommended (or use your own .babelrc)
|
||||||
presets: ['react-native']
|
presets: ['react-native']
|
||||||
}
|
}
|
||||||
@@ -198,10 +198,20 @@ target platform.
|
|||||||
|
|
||||||
## Testing with Jest
|
## Testing with Jest
|
||||||
|
|
||||||
[Jest](https://facebook.github.io/jest/) also needs to map `react-native` to `react-native-web`.
|
[Jest](https://facebook.github.io/jest/) can be configured to improve snapshots
|
||||||
|
of `react-native-web` components.
|
||||||
|
|
||||||
```
|
```
|
||||||
"jest": {
|
{
|
||||||
|
"snapshotSerializers": [ "enzyme-to-json/serializer", "react-native-web/jest/serializer" ]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Jest also needs to map `react-native` to `react-native-web` (unless you are
|
||||||
|
using Babel with the `react-native-web/babel` plugin).
|
||||||
|
|
||||||
|
```
|
||||||
|
{
|
||||||
"moduleNameMapper": {
|
"moduleNameMapper": {
|
||||||
"react-native": "<rootDir>/node_modules/react-native-web"
|
"react-native": "<rootDir>/node_modules/react-native-web"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ const DimensionsScreen = () => (
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<DocItem
|
<DocItem
|
||||||
name="static addEventLitener"
|
name="static addEventListener"
|
||||||
typeInfo="(type: string, handler: function) => void"
|
typeInfo="(type: string, handler: function) => void"
|
||||||
description={[
|
description={[
|
||||||
<AppText>Add an event handler. Supported events:</AppText>,
|
<AppText>Add an event handler. Supported events:</AppText>,
|
||||||
@@ -65,7 +65,7 @@ const DimensionsScreen = () => (
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<DocItem
|
<DocItem
|
||||||
name="static removeEventLitener"
|
name="static removeEventListener"
|
||||||
typeInfo="(type: string, handler: function) => void"
|
typeInfo="(type: string, handler: function) => void"
|
||||||
description="Remove an event handler."
|
description="Remove an event handler."
|
||||||
/>
|
/>
|
||||||
|
|||||||
299
jest/__tests__/__snapshots__/serializer-test.js.snap
Normal file
299
jest/__tests__/__snapshots__/serializer-test.js.snap
Normal file
@@ -0,0 +1,299 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`enzyme.mount complex 1`] = `
|
||||||
|
<Box
|
||||||
|
element={
|
||||||
|
<View>
|
||||||
|
<View
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"padding": 20,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Text>
|
||||||
|
Nested
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<View
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"backgroundColor": "red",
|
||||||
|
"padding": 10,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="rn-alignItems-1oszu61 rn-backgroundColor-1mjtqww rn-borderTopStyle-1efd50x rn-borderRightStyle-14skgim rn-borderBottomStyle-rull8r rn-borderLeftStyle-mm0ijv rn-borderTopWidth-13yce4e rn-borderRightWidth-fnigne rn-borderBottomWidth-ndvcnb rn-borderLeftWidth-gxnn5r rn-boxSizing-deolkf rn-display-6koalj rn-flexShrink-1pxmb3b rn-flexBasis-7vfszb rn-flexDirection-eqz5dr rn-marginTop-1mnahxq rn-marginRight-61z16t rn-marginBottom-p1pxzi rn-marginLeft-11wrixw rn-minHeight-ifefl9 rn-minWidth-bcqeeo rn-paddingTop-m611by rn-paddingRight-1qfoi16 rn-paddingBottom-1mi0q7o rn-paddingLeft-1hfyk0a rn-position-bnwqim"
|
||||||
|
>
|
||||||
|
<Title>
|
||||||
|
<Text
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"color": "black",
|
||||||
|
"fontSize": 16,
|
||||||
|
"textAlignVertical": "center",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="rn-borderTopWidth-13yce4e rn-borderRightWidth-fnigne rn-borderBottomWidth-ndvcnb rn-borderLeftWidth-gxnn5r rn-boxSizing-deolkf rn-color-1bodaif rn-display-1471scf rn-font-1lw9tu2 rn-fontFamily-10u92zi rn-fontSize-ubezar rn-marginTop-1mnahxq rn-marginRight-61z16t rn-marginBottom-p1pxzi rn-marginLeft-11wrixw rn-paddingTop-wk8lta rn-paddingRight-9aemit rn-paddingBottom-1mdbw0j rn-paddingLeft-gy4na3 rn-verticalAlign-9iso6 rn-textDecoration-bauka4 rn-whiteSpace-q42fyq rn-wordWrap-qvutc0"
|
||||||
|
dir="auto"
|
||||||
|
>
|
||||||
|
Hello World
|
||||||
|
</div>
|
||||||
|
</Text>
|
||||||
|
</Title>
|
||||||
|
<View>
|
||||||
|
<div
|
||||||
|
className="rn-alignItems-1oszu61 rn-borderTopStyle-1efd50x rn-borderRightStyle-14skgim rn-borderBottomStyle-rull8r rn-borderLeftStyle-mm0ijv rn-borderTopWidth-13yce4e rn-borderRightWidth-fnigne rn-borderBottomWidth-ndvcnb rn-borderLeftWidth-gxnn5r rn-boxSizing-deolkf rn-display-6koalj rn-flexShrink-1pxmb3b rn-flexBasis-7vfszb rn-flexDirection-eqz5dr rn-marginTop-1mnahxq rn-marginRight-61z16t rn-marginBottom-p1pxzi rn-marginLeft-11wrixw rn-minHeight-ifefl9 rn-minWidth-bcqeeo rn-paddingTop-wk8lta rn-paddingRight-9aemit rn-paddingBottom-1mdbw0j rn-paddingLeft-gy4na3 rn-position-bnwqim"
|
||||||
|
>
|
||||||
|
<View
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"padding": 20,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="rn-alignItems-1oszu61 rn-borderTopStyle-1efd50x rn-borderRightStyle-14skgim rn-borderBottomStyle-rull8r rn-borderLeftStyle-mm0ijv rn-borderTopWidth-13yce4e rn-borderRightWidth-fnigne rn-borderBottomWidth-ndvcnb rn-borderLeftWidth-gxnn5r rn-boxSizing-deolkf rn-display-6koalj rn-flexShrink-1pxmb3b rn-flexBasis-7vfszb rn-flexDirection-eqz5dr rn-marginTop-1mnahxq rn-marginRight-61z16t rn-marginBottom-p1pxzi rn-marginLeft-11wrixw rn-minHeight-ifefl9 rn-minWidth-bcqeeo rn-paddingTop-1knelpx rn-paddingRight-1ah4tor rn-paddingBottom-k8qxaj rn-paddingLeft-b5h31w rn-position-bnwqim"
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
<Text>
|
||||||
|
<div
|
||||||
|
className="rn-borderTopWidth-13yce4e rn-borderRightWidth-fnigne rn-borderBottomWidth-ndvcnb rn-borderLeftWidth-gxnn5r rn-boxSizing-deolkf rn-color-homxoj rn-display-1471scf rn-font-1lw9tu2 rn-fontFamily-10u92zi rn-fontSize-1b43r93 rn-marginTop-1mnahxq rn-marginRight-61z16t rn-marginBottom-p1pxzi rn-marginLeft-11wrixw rn-paddingTop-wk8lta rn-paddingRight-9aemit rn-paddingBottom-1mdbw0j rn-paddingLeft-gy4na3 rn-textDecoration-bauka4 rn-whiteSpace-q42fyq rn-wordWrap-qvutc0"
|
||||||
|
dir="auto"
|
||||||
|
>
|
||||||
|
Nested
|
||||||
|
</div>
|
||||||
|
</Text>
|
||||||
|
</div>
|
||||||
|
</View>
|
||||||
|
</div>
|
||||||
|
</View>
|
||||||
|
</Box>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`enzyme.mount composite 1`] = `
|
||||||
|
<Box>
|
||||||
|
<View
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"backgroundColor": "red",
|
||||||
|
"padding": 10,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="rn-alignItems-1oszu61 rn-backgroundColor-1mjtqww rn-borderTopStyle-1efd50x rn-borderRightStyle-14skgim rn-borderBottomStyle-rull8r rn-borderLeftStyle-mm0ijv rn-borderTopWidth-13yce4e rn-borderRightWidth-fnigne rn-borderBottomWidth-ndvcnb rn-borderLeftWidth-gxnn5r rn-boxSizing-deolkf rn-display-6koalj rn-flexShrink-1pxmb3b rn-flexBasis-7vfszb rn-flexDirection-eqz5dr rn-marginTop-1mnahxq rn-marginRight-61z16t rn-marginBottom-p1pxzi rn-marginLeft-11wrixw rn-minHeight-ifefl9 rn-minWidth-bcqeeo rn-paddingTop-m611by rn-paddingRight-1qfoi16 rn-paddingBottom-1mi0q7o rn-paddingLeft-1hfyk0a rn-position-bnwqim"
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
</Box>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`enzyme.mount nested 1`] = `
|
||||||
|
<Box>
|
||||||
|
<View
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"backgroundColor": "red",
|
||||||
|
"padding": 10,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="rn-alignItems-1oszu61 rn-backgroundColor-1mjtqww rn-borderTopStyle-1efd50x rn-borderRightStyle-14skgim rn-borderBottomStyle-rull8r rn-borderLeftStyle-mm0ijv rn-borderTopWidth-13yce4e rn-borderRightWidth-fnigne rn-borderBottomWidth-ndvcnb rn-borderLeftWidth-gxnn5r rn-boxSizing-deolkf rn-display-6koalj rn-flexShrink-1pxmb3b rn-flexBasis-7vfszb rn-flexDirection-eqz5dr rn-marginTop-1mnahxq rn-marginRight-61z16t rn-marginBottom-p1pxzi rn-marginLeft-11wrixw rn-minHeight-ifefl9 rn-minWidth-bcqeeo rn-paddingTop-m611by rn-paddingRight-1qfoi16 rn-paddingBottom-1mi0q7o rn-paddingLeft-1hfyk0a rn-position-bnwqim"
|
||||||
|
>
|
||||||
|
<Title>
|
||||||
|
<Text
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"color": "black",
|
||||||
|
"fontSize": 16,
|
||||||
|
"textAlignVertical": "center",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="rn-borderTopWidth-13yce4e rn-borderRightWidth-fnigne rn-borderBottomWidth-ndvcnb rn-borderLeftWidth-gxnn5r rn-boxSizing-deolkf rn-color-1bodaif rn-display-1471scf rn-font-1lw9tu2 rn-fontFamily-10u92zi rn-fontSize-ubezar rn-marginTop-1mnahxq rn-marginRight-61z16t rn-marginBottom-p1pxzi rn-marginLeft-11wrixw rn-paddingTop-wk8lta rn-paddingRight-9aemit rn-paddingBottom-1mdbw0j rn-paddingLeft-gy4na3 rn-verticalAlign-9iso6 rn-textDecoration-bauka4 rn-whiteSpace-q42fyq rn-wordWrap-qvutc0"
|
||||||
|
dir="auto"
|
||||||
|
>
|
||||||
|
Hello World
|
||||||
|
</div>
|
||||||
|
</Text>
|
||||||
|
</Title>
|
||||||
|
</div>
|
||||||
|
</View>
|
||||||
|
</Box>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`enzyme.mount noop 1`] = `
|
||||||
|
<View>
|
||||||
|
<div
|
||||||
|
className="rn-alignItems-1oszu61 rn-borderTopStyle-1efd50x rn-borderRightStyle-14skgim rn-borderBottomStyle-rull8r rn-borderLeftStyle-mm0ijv rn-borderTopWidth-13yce4e rn-borderRightWidth-fnigne rn-borderBottomWidth-ndvcnb rn-borderLeftWidth-gxnn5r rn-boxSizing-deolkf rn-display-6koalj rn-flexShrink-1pxmb3b rn-flexBasis-7vfszb rn-flexDirection-eqz5dr rn-marginTop-1mnahxq rn-marginRight-61z16t rn-marginBottom-p1pxzi rn-marginLeft-11wrixw rn-minHeight-ifefl9 rn-minWidth-bcqeeo rn-paddingTop-wk8lta rn-paddingRight-9aemit rn-paddingBottom-1mdbw0j rn-paddingLeft-gy4na3 rn-position-bnwqim"
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`enzyme.render complex 1`] = `
|
||||||
|
<div
|
||||||
|
class="rn-alignItems-1oszu61 rn-backgroundColor-1mjtqww rn-borderTopStyle-1efd50x rn-borderRightStyle-14skgim rn-borderBottomStyle-rull8r rn-borderLeftStyle-mm0ijv rn-borderTopWidth-13yce4e rn-borderRightWidth-fnigne rn-borderBottomWidth-ndvcnb rn-borderLeftWidth-gxnn5r rn-boxSizing-deolkf rn-display-6koalj rn-flexShrink-1pxmb3b rn-flexBasis-7vfszb rn-flexDirection-eqz5dr rn-marginTop-1mnahxq rn-marginRight-61z16t rn-marginBottom-p1pxzi rn-marginLeft-11wrixw rn-minHeight-ifefl9 rn-minWidth-bcqeeo rn-paddingTop-m611by rn-paddingRight-1qfoi16 rn-paddingBottom-1mi0q7o rn-paddingLeft-1hfyk0a rn-position-bnwqim"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="rn-borderTopWidth-13yce4e rn-borderRightWidth-fnigne rn-borderBottomWidth-ndvcnb rn-borderLeftWidth-gxnn5r rn-boxSizing-deolkf rn-color-1bodaif rn-display-1471scf rn-font-1lw9tu2 rn-fontFamily-10u92zi rn-fontSize-ubezar rn-marginTop-1mnahxq rn-marginRight-61z16t rn-marginBottom-p1pxzi rn-marginLeft-11wrixw rn-paddingTop-wk8lta rn-paddingRight-9aemit rn-paddingBottom-1mdbw0j rn-paddingLeft-gy4na3 rn-verticalAlign-9iso6 rn-textDecoration-bauka4 rn-whiteSpace-q42fyq rn-wordWrap-qvutc0"
|
||||||
|
dir="auto"
|
||||||
|
>
|
||||||
|
Hello World
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="rn-alignItems-1oszu61 rn-borderTopStyle-1efd50x rn-borderRightStyle-14skgim rn-borderBottomStyle-rull8r rn-borderLeftStyle-mm0ijv rn-borderTopWidth-13yce4e rn-borderRightWidth-fnigne rn-borderBottomWidth-ndvcnb rn-borderLeftWidth-gxnn5r rn-boxSizing-deolkf rn-display-6koalj rn-flexShrink-1pxmb3b rn-flexBasis-7vfszb rn-flexDirection-eqz5dr rn-marginTop-1mnahxq rn-marginRight-61z16t rn-marginBottom-p1pxzi rn-marginLeft-11wrixw rn-minHeight-ifefl9 rn-minWidth-bcqeeo rn-paddingTop-wk8lta rn-paddingRight-9aemit rn-paddingBottom-1mdbw0j rn-paddingLeft-gy4na3 rn-position-bnwqim"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="rn-alignItems-1oszu61 rn-borderTopStyle-1efd50x rn-borderRightStyle-14skgim rn-borderBottomStyle-rull8r rn-borderLeftStyle-mm0ijv rn-borderTopWidth-13yce4e rn-borderRightWidth-fnigne rn-borderBottomWidth-ndvcnb rn-borderLeftWidth-gxnn5r rn-boxSizing-deolkf rn-display-6koalj rn-flexShrink-1pxmb3b rn-flexBasis-7vfszb rn-flexDirection-eqz5dr rn-marginTop-1mnahxq rn-marginRight-61z16t rn-marginBottom-p1pxzi rn-marginLeft-11wrixw rn-minHeight-ifefl9 rn-minWidth-bcqeeo rn-paddingTop-1knelpx rn-paddingRight-1ah4tor rn-paddingBottom-k8qxaj rn-paddingLeft-b5h31w rn-position-bnwqim"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
class="rn-borderTopWidth-13yce4e rn-borderRightWidth-fnigne rn-borderBottomWidth-ndvcnb rn-borderLeftWidth-gxnn5r rn-boxSizing-deolkf rn-color-homxoj rn-display-1471scf rn-font-1lw9tu2 rn-fontFamily-10u92zi rn-fontSize-1b43r93 rn-marginTop-1mnahxq rn-marginRight-61z16t rn-marginBottom-p1pxzi rn-marginLeft-11wrixw rn-paddingTop-wk8lta rn-paddingRight-9aemit rn-paddingBottom-1mdbw0j rn-paddingLeft-gy4na3 rn-textDecoration-bauka4 rn-whiteSpace-q42fyq rn-wordWrap-qvutc0"
|
||||||
|
dir="auto"
|
||||||
|
>
|
||||||
|
Nested
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`enzyme.render composite 1`] = `
|
||||||
|
<div
|
||||||
|
class="rn-alignItems-1oszu61 rn-backgroundColor-1mjtqww rn-borderTopStyle-1efd50x rn-borderRightStyle-14skgim rn-borderBottomStyle-rull8r rn-borderLeftStyle-mm0ijv rn-borderTopWidth-13yce4e rn-borderRightWidth-fnigne rn-borderBottomWidth-ndvcnb rn-borderLeftWidth-gxnn5r rn-boxSizing-deolkf rn-display-6koalj rn-flexShrink-1pxmb3b rn-flexBasis-7vfszb rn-flexDirection-eqz5dr rn-marginTop-1mnahxq rn-marginRight-61z16t rn-marginBottom-p1pxzi rn-marginLeft-11wrixw rn-minHeight-ifefl9 rn-minWidth-bcqeeo rn-paddingTop-m611by rn-paddingRight-1qfoi16 rn-paddingBottom-1mi0q7o rn-paddingLeft-1hfyk0a rn-position-bnwqim"
|
||||||
|
/>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`enzyme.render nested 1`] = `
|
||||||
|
<div
|
||||||
|
class="rn-alignItems-1oszu61 rn-backgroundColor-1mjtqww rn-borderTopStyle-1efd50x rn-borderRightStyle-14skgim rn-borderBottomStyle-rull8r rn-borderLeftStyle-mm0ijv rn-borderTopWidth-13yce4e rn-borderRightWidth-fnigne rn-borderBottomWidth-ndvcnb rn-borderLeftWidth-gxnn5r rn-boxSizing-deolkf rn-display-6koalj rn-flexShrink-1pxmb3b rn-flexBasis-7vfszb rn-flexDirection-eqz5dr rn-marginTop-1mnahxq rn-marginRight-61z16t rn-marginBottom-p1pxzi rn-marginLeft-11wrixw rn-minHeight-ifefl9 rn-minWidth-bcqeeo rn-paddingTop-m611by rn-paddingRight-1qfoi16 rn-paddingBottom-1mi0q7o rn-paddingLeft-1hfyk0a rn-position-bnwqim"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="rn-borderTopWidth-13yce4e rn-borderRightWidth-fnigne rn-borderBottomWidth-ndvcnb rn-borderLeftWidth-gxnn5r rn-boxSizing-deolkf rn-color-1bodaif rn-display-1471scf rn-font-1lw9tu2 rn-fontFamily-10u92zi rn-fontSize-ubezar rn-marginTop-1mnahxq rn-marginRight-61z16t rn-marginBottom-p1pxzi rn-marginLeft-11wrixw rn-paddingTop-wk8lta rn-paddingRight-9aemit rn-paddingBottom-1mdbw0j rn-paddingLeft-gy4na3 rn-verticalAlign-9iso6 rn-textDecoration-bauka4 rn-whiteSpace-q42fyq rn-wordWrap-qvutc0"
|
||||||
|
dir="auto"
|
||||||
|
>
|
||||||
|
Hello World
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`enzyme.render noop 1`] = `
|
||||||
|
<div
|
||||||
|
class="rn-alignItems-1oszu61 rn-borderTopStyle-1efd50x rn-borderRightStyle-14skgim rn-borderBottomStyle-rull8r rn-borderLeftStyle-mm0ijv rn-borderTopWidth-13yce4e rn-borderRightWidth-fnigne rn-borderBottomWidth-ndvcnb rn-borderLeftWidth-gxnn5r rn-boxSizing-deolkf rn-display-6koalj rn-flexShrink-1pxmb3b rn-flexBasis-7vfszb rn-flexDirection-eqz5dr rn-marginTop-1mnahxq rn-marginRight-61z16t rn-marginBottom-p1pxzi rn-marginLeft-11wrixw rn-minHeight-ifefl9 rn-minWidth-bcqeeo rn-paddingTop-wk8lta rn-paddingRight-9aemit rn-paddingBottom-1mdbw0j rn-paddingLeft-gy4na3 rn-position-bnwqim"
|
||||||
|
/>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`enzyme.shallow complex 1`] = `
|
||||||
|
<View
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"backgroundColor": "red",
|
||||||
|
"padding": 10,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Title>
|
||||||
|
Hello World
|
||||||
|
</Title>
|
||||||
|
<View>
|
||||||
|
<View
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"padding": 20,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Text>
|
||||||
|
Nested
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`enzyme.shallow composite 1`] = `
|
||||||
|
<View
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"backgroundColor": "red",
|
||||||
|
"padding": 10,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`enzyme.shallow nested 1`] = `
|
||||||
|
<View
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"backgroundColor": "red",
|
||||||
|
"padding": 10,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Title>
|
||||||
|
Hello World
|
||||||
|
</Title>
|
||||||
|
</View>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`enzyme.shallow noop 1`] = `
|
||||||
|
<div
|
||||||
|
className="rn-alignItems-1oszu61 rn-borderTopStyle-1efd50x rn-borderRightStyle-14skgim rn-borderBottomStyle-rull8r rn-borderLeftStyle-mm0ijv rn-borderTopWidth-13yce4e rn-borderRightWidth-fnigne rn-borderBottomWidth-ndvcnb rn-borderLeftWidth-gxnn5r rn-boxSizing-deolkf rn-display-6koalj rn-flexShrink-1pxmb3b rn-flexBasis-7vfszb rn-flexDirection-eqz5dr rn-marginTop-1mnahxq rn-marginRight-61z16t rn-marginBottom-p1pxzi rn-marginLeft-11wrixw rn-minHeight-ifefl9 rn-minWidth-bcqeeo rn-paddingTop-wk8lta rn-paddingRight-9aemit rn-paddingBottom-1mdbw0j rn-paddingLeft-gy4na3 rn-position-bnwqim"
|
||||||
|
/>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`react-test-renderer complex 1`] = `
|
||||||
|
<div
|
||||||
|
className="rn-alignItems-1oszu61 rn-backgroundColor-1mjtqww rn-borderTopStyle-1efd50x rn-borderRightStyle-14skgim rn-borderBottomStyle-rull8r rn-borderLeftStyle-mm0ijv rn-borderTopWidth-13yce4e rn-borderRightWidth-fnigne rn-borderBottomWidth-ndvcnb rn-borderLeftWidth-gxnn5r rn-boxSizing-deolkf rn-display-6koalj rn-flexShrink-1pxmb3b rn-flexBasis-7vfszb rn-flexDirection-eqz5dr rn-marginTop-1mnahxq rn-marginRight-61z16t rn-marginBottom-p1pxzi rn-marginLeft-11wrixw rn-minHeight-ifefl9 rn-minWidth-bcqeeo rn-paddingTop-m611by rn-paddingRight-1qfoi16 rn-paddingBottom-1mi0q7o rn-paddingLeft-1hfyk0a rn-position-bnwqim"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="rn-borderTopWidth-13yce4e rn-borderRightWidth-fnigne rn-borderBottomWidth-ndvcnb rn-borderLeftWidth-gxnn5r rn-boxSizing-deolkf rn-color-1bodaif rn-display-1471scf rn-font-1lw9tu2 rn-fontFamily-10u92zi rn-fontSize-ubezar rn-marginTop-1mnahxq rn-marginRight-61z16t rn-marginBottom-p1pxzi rn-marginLeft-11wrixw rn-paddingTop-wk8lta rn-paddingRight-9aemit rn-paddingBottom-1mdbw0j rn-paddingLeft-gy4na3 rn-verticalAlign-9iso6 rn-textDecoration-bauka4 rn-whiteSpace-q42fyq rn-wordWrap-qvutc0"
|
||||||
|
dir="auto"
|
||||||
|
>
|
||||||
|
Hello World
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="rn-alignItems-1oszu61 rn-borderTopStyle-1efd50x rn-borderRightStyle-14skgim rn-borderBottomStyle-rull8r rn-borderLeftStyle-mm0ijv rn-borderTopWidth-13yce4e rn-borderRightWidth-fnigne rn-borderBottomWidth-ndvcnb rn-borderLeftWidth-gxnn5r rn-boxSizing-deolkf rn-display-6koalj rn-flexShrink-1pxmb3b rn-flexBasis-7vfszb rn-flexDirection-eqz5dr rn-marginTop-1mnahxq rn-marginRight-61z16t rn-marginBottom-p1pxzi rn-marginLeft-11wrixw rn-minHeight-ifefl9 rn-minWidth-bcqeeo rn-paddingTop-wk8lta rn-paddingRight-9aemit rn-paddingBottom-1mdbw0j rn-paddingLeft-gy4na3 rn-position-bnwqim"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="rn-alignItems-1oszu61 rn-borderTopStyle-1efd50x rn-borderRightStyle-14skgim rn-borderBottomStyle-rull8r rn-borderLeftStyle-mm0ijv rn-borderTopWidth-13yce4e rn-borderRightWidth-fnigne rn-borderBottomWidth-ndvcnb rn-borderLeftWidth-gxnn5r rn-boxSizing-deolkf rn-display-6koalj rn-flexShrink-1pxmb3b rn-flexBasis-7vfszb rn-flexDirection-eqz5dr rn-marginTop-1mnahxq rn-marginRight-61z16t rn-marginBottom-p1pxzi rn-marginLeft-11wrixw rn-minHeight-ifefl9 rn-minWidth-bcqeeo rn-paddingTop-1knelpx rn-paddingRight-1ah4tor rn-paddingBottom-k8qxaj rn-paddingLeft-b5h31w rn-position-bnwqim"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
className="rn-borderTopWidth-13yce4e rn-borderRightWidth-fnigne rn-borderBottomWidth-ndvcnb rn-borderLeftWidth-gxnn5r rn-boxSizing-deolkf rn-color-homxoj rn-display-1471scf rn-font-1lw9tu2 rn-fontFamily-10u92zi rn-fontSize-1b43r93 rn-marginTop-1mnahxq rn-marginRight-61z16t rn-marginBottom-p1pxzi rn-marginLeft-11wrixw rn-paddingTop-wk8lta rn-paddingRight-9aemit rn-paddingBottom-1mdbw0j rn-paddingLeft-gy4na3 rn-textDecoration-bauka4 rn-whiteSpace-q42fyq rn-wordWrap-qvutc0"
|
||||||
|
dir="auto"
|
||||||
|
>
|
||||||
|
Nested
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`react-test-renderer composite 1`] = `
|
||||||
|
<div
|
||||||
|
className="rn-alignItems-1oszu61 rn-backgroundColor-1mjtqww rn-borderTopStyle-1efd50x rn-borderRightStyle-14skgim rn-borderBottomStyle-rull8r rn-borderLeftStyle-mm0ijv rn-borderTopWidth-13yce4e rn-borderRightWidth-fnigne rn-borderBottomWidth-ndvcnb rn-borderLeftWidth-gxnn5r rn-boxSizing-deolkf rn-display-6koalj rn-flexShrink-1pxmb3b rn-flexBasis-7vfszb rn-flexDirection-eqz5dr rn-marginTop-1mnahxq rn-marginRight-61z16t rn-marginBottom-p1pxzi rn-marginLeft-11wrixw rn-minHeight-ifefl9 rn-minWidth-bcqeeo rn-paddingTop-m611by rn-paddingRight-1qfoi16 rn-paddingBottom-1mi0q7o rn-paddingLeft-1hfyk0a rn-position-bnwqim"
|
||||||
|
/>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`react-test-renderer nested 1`] = `
|
||||||
|
<div
|
||||||
|
className="rn-alignItems-1oszu61 rn-backgroundColor-1mjtqww rn-borderTopStyle-1efd50x rn-borderRightStyle-14skgim rn-borderBottomStyle-rull8r rn-borderLeftStyle-mm0ijv rn-borderTopWidth-13yce4e rn-borderRightWidth-fnigne rn-borderBottomWidth-ndvcnb rn-borderLeftWidth-gxnn5r rn-boxSizing-deolkf rn-display-6koalj rn-flexShrink-1pxmb3b rn-flexBasis-7vfszb rn-flexDirection-eqz5dr rn-marginTop-1mnahxq rn-marginRight-61z16t rn-marginBottom-p1pxzi rn-marginLeft-11wrixw rn-minHeight-ifefl9 rn-minWidth-bcqeeo rn-paddingTop-m611by rn-paddingRight-1qfoi16 rn-paddingBottom-1mi0q7o rn-paddingLeft-1hfyk0a rn-position-bnwqim"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="rn-borderTopWidth-13yce4e rn-borderRightWidth-fnigne rn-borderBottomWidth-ndvcnb rn-borderLeftWidth-gxnn5r rn-boxSizing-deolkf rn-color-1bodaif rn-display-1471scf rn-font-1lw9tu2 rn-fontFamily-10u92zi rn-fontSize-ubezar rn-marginTop-1mnahxq rn-marginRight-61z16t rn-marginBottom-p1pxzi rn-marginLeft-11wrixw rn-paddingTop-wk8lta rn-paddingRight-9aemit rn-paddingBottom-1mdbw0j rn-paddingLeft-gy4na3 rn-verticalAlign-9iso6 rn-textDecoration-bauka4 rn-whiteSpace-q42fyq rn-wordWrap-qvutc0"
|
||||||
|
dir="auto"
|
||||||
|
>
|
||||||
|
Hello World
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`react-test-renderer noop 1`] = `
|
||||||
|
<div
|
||||||
|
className="rn-alignItems-1oszu61 rn-borderTopStyle-1efd50x rn-borderRightStyle-14skgim rn-borderBottomStyle-rull8r rn-borderLeftStyle-mm0ijv rn-borderTopWidth-13yce4e rn-borderRightWidth-fnigne rn-borderBottomWidth-ndvcnb rn-borderLeftWidth-gxnn5r rn-boxSizing-deolkf rn-display-6koalj rn-flexShrink-1pxmb3b rn-flexBasis-7vfszb rn-flexDirection-eqz5dr rn-marginTop-1mnahxq rn-marginRight-61z16t rn-marginBottom-p1pxzi rn-marginLeft-11wrixw rn-minHeight-ifefl9 rn-minWidth-bcqeeo rn-paddingTop-wk8lta rn-paddingRight-9aemit rn-paddingBottom-1mdbw0j rn-paddingLeft-gy4na3 rn-position-bnwqim"
|
||||||
|
/>
|
||||||
|
`;
|
||||||
95
jest/__tests__/serializer-test.js
Normal file
95
jest/__tests__/serializer-test.js
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
/* eslint-env jasmine, jest */
|
||||||
|
/* eslint-disable react/prop-types */
|
||||||
|
|
||||||
|
import { mount, render, shallow } from 'enzyme';
|
||||||
|
import React from 'react';
|
||||||
|
import renderer from 'react-test-renderer';
|
||||||
|
import serializer from '../serializer';
|
||||||
|
import { StyleSheet, Text, View } from '../../dist';
|
||||||
|
import toJson from 'enzyme-to-json';
|
||||||
|
|
||||||
|
expect.addSnapshotSerializer(serializer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fixtures
|
||||||
|
*/
|
||||||
|
|
||||||
|
const Box = ({ children, element, style, ...rest }) => (
|
||||||
|
<View {...rest} style={[styles.box, style]}>
|
||||||
|
{children}
|
||||||
|
{element}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
|
||||||
|
const Title = ({ style, ...rest }) => <Text {...rest} style={[styles.title, style]} />;
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
box: {
|
||||||
|
backgroundColor: 'red',
|
||||||
|
padding: 10
|
||||||
|
},
|
||||||
|
boxExtra: {
|
||||||
|
alignItems: 'center'
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
color: 'black',
|
||||||
|
fontSize: 16,
|
||||||
|
textAlignVertical: 'center'
|
||||||
|
},
|
||||||
|
element: {
|
||||||
|
padding: 20
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test cases
|
||||||
|
*/
|
||||||
|
|
||||||
|
const cases = {
|
||||||
|
noop: <View />,
|
||||||
|
composite: <Box />,
|
||||||
|
nested: (
|
||||||
|
<Box>
|
||||||
|
<Title>Hello World</Title>
|
||||||
|
</Box>
|
||||||
|
),
|
||||||
|
complex: (
|
||||||
|
<Box
|
||||||
|
element={
|
||||||
|
<View>
|
||||||
|
<View style={styles.element} />
|
||||||
|
<Text>Nested</Text>
|
||||||
|
</View>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Title>Hello World</Title>
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
const caseNames = Object.keys(cases);
|
||||||
|
|
||||||
|
describe('enzyme', () => {
|
||||||
|
caseNames.forEach(caseName => {
|
||||||
|
test(caseName, () => {
|
||||||
|
const element = cases[caseName];
|
||||||
|
const mountTree = mount(element);
|
||||||
|
const renderTree = render(element);
|
||||||
|
const shallowTree = shallow(element);
|
||||||
|
|
||||||
|
expect(toJson(mountTree)).toMatchSnapshot(`enzyme.mount ${caseName}`);
|
||||||
|
expect(toJson(renderTree)).toMatchSnapshot(`enzyme.render ${caseName}`);
|
||||||
|
expect(toJson(shallowTree)).toMatchSnapshot(`enzyme.shallow ${caseName}`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('react-test-renderer', () => {
|
||||||
|
caseNames.forEach(caseName => {
|
||||||
|
test(caseName, () => {
|
||||||
|
const element = cases[caseName];
|
||||||
|
const tree = renderer.create(element).toJSON();
|
||||||
|
expect(tree).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
61
jest/serializer.js
Normal file
61
jest/serializer.js
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
const React = require('react');
|
||||||
|
const { StyleSheet } = require('../dist');
|
||||||
|
|
||||||
|
function createSerializer(styleSheet) {
|
||||||
|
function flattenNodeStyles(node) {
|
||||||
|
if (node && node.props) {
|
||||||
|
// check for React elements in any props
|
||||||
|
const nextProps = Object.keys(node.props).reduce((acc, curr) => {
|
||||||
|
const value = node.props[curr];
|
||||||
|
if (React.isValidElement(value)) {
|
||||||
|
acc[curr] = flattenNodeStyles(value);
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
// flatten styles and avoid empty objects in snapshots
|
||||||
|
if (node.props.style) {
|
||||||
|
const style = styleSheet.flatten(node.props.style);
|
||||||
|
if (Object.keys(style).length > 0) {
|
||||||
|
nextProps.style = style;
|
||||||
|
} else {
|
||||||
|
delete nextProps.style;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const args = [node, nextProps];
|
||||||
|
|
||||||
|
// recurse over children too
|
||||||
|
const children = node.children || node.props.children;
|
||||||
|
if (children) {
|
||||||
|
if (Array.isArray(children)) {
|
||||||
|
children.forEach(child => {
|
||||||
|
args.push(flattenNodeStyles(child));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
args.push(flattenNodeStyles(children));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return React.cloneElement.apply(React.cloneElement, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
function test(value) {
|
||||||
|
return !!value && value.$$typeof === Symbol.for('react.test.json');
|
||||||
|
}
|
||||||
|
|
||||||
|
function print(value, serializer) {
|
||||||
|
return serializer(flattenNodeStyles(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
return { test, print };
|
||||||
|
}
|
||||||
|
|
||||||
|
const serializer = createSerializer(StyleSheet);
|
||||||
|
createSerializer.test = serializer.test;
|
||||||
|
createSerializer.print = serializer.print;
|
||||||
|
|
||||||
|
module.exports = createSerializer;
|
||||||
13
package.json
13
package.json
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "react-native-web",
|
"name": "react-native-web",
|
||||||
"version": "0.1.4",
|
"version": "0.1.11",
|
||||||
"description": "React Native for Web",
|
"description": "React Native for Web",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"module": "dist/module.js",
|
|
||||||
"files": [
|
"files": [
|
||||||
"babel",
|
"babel",
|
||||||
"dist",
|
"dist",
|
||||||
|
"jest",
|
||||||
"src",
|
"src",
|
||||||
"!**/__tests__"
|
"!**/__tests__"
|
||||||
],
|
],
|
||||||
@@ -19,15 +19,16 @@
|
|||||||
"docs:start": "cd docs && yarn && yarn start",
|
"docs:start": "cd docs && yarn && yarn start",
|
||||||
"docs:release": "cd docs && yarn release",
|
"docs:release": "cd docs && yarn release",
|
||||||
"flow": "flow",
|
"flow": "flow",
|
||||||
"fmt": "find babel benchmarks docs src -name '*.js' | grep -v -E '(node_modules|dist)' | xargs yarn fmt:cmd",
|
"fmt": "find babel benchmarks docs jest src -name '*.js' | grep -v -E '(node_modules|dist)' | xargs yarn fmt:cmd",
|
||||||
"fmt:cmd": "prettier --print-width=100 --single-quote --write",
|
"fmt:cmd": "prettier --print-width=100 --single-quote --write",
|
||||||
"jest": "jest",
|
"jest": "jest",
|
||||||
"jest:watch": "yarn test -- --watch",
|
"jest:watch": "yarn test -- --watch",
|
||||||
"lint": "yarn lint:cmd -- babel benchmarks docs src",
|
"lint": "yarn lint:cmd -- babel benchmarks docs jest src",
|
||||||
"lint:cmd": "eslint --ignore-path .gitignore --fix",
|
"lint:cmd": "eslint --ignore-path .gitignore --fix",
|
||||||
"precommit": "lint-staged",
|
"precommit": "lint-staged",
|
||||||
"release": "yarn clean-dist && yarn lint && yarn test && yarn build && npm publish",
|
"release": "yarn clean-dist && yarn lint && yarn build && yarn test && npm publish",
|
||||||
"test": "flow && jest"
|
"test": "flow && jest",
|
||||||
|
"test:ci": "yarn clean-dist && yarn compile && yarn test"
|
||||||
},
|
},
|
||||||
"babel": {
|
"babel": {
|
||||||
"presets": [
|
"presets": [
|
||||||
|
|||||||
@@ -61,6 +61,11 @@ export default class AsyncStorage {
|
|||||||
}, callback);
|
}, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (stub) Flushes any pending requests using a single batch call to get the data.
|
||||||
|
*/
|
||||||
|
static flushGetRequests() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets *all* keys known to the app, for all callers, libraries, etc.
|
* Gets *all* keys known to the app, for all callers, libraries, etc.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
function emptyFunction() {}
|
function emptyFunction() {}
|
||||||
|
|
||||||
const BackAndroid = {
|
const BackHandler = {
|
||||||
exitApp: emptyFunction,
|
exitApp: emptyFunction,
|
||||||
addEventListener() {
|
addEventListener() {
|
||||||
return {
|
return {
|
||||||
@@ -22,4 +22,4 @@ const BackAndroid = {
|
|||||||
removeEventListener: emptyFunction
|
removeEventListener: emptyFunction
|
||||||
};
|
};
|
||||||
|
|
||||||
export default BackAndroid;
|
export default BackHandler;
|
||||||
@@ -91,6 +91,7 @@ StyleSheetValidation.addValidStylePropTypes({
|
|||||||
borderSpacing: oneOf([number, string]),
|
borderSpacing: oneOf([number, string]),
|
||||||
clear: string,
|
clear: string,
|
||||||
cursor: string,
|
cursor: string,
|
||||||
|
fill: string,
|
||||||
float: oneOf(['left', 'none', 'right']),
|
float: oneOf(['left', 'none', 'right']),
|
||||||
font: string /* @private */,
|
font: string /* @private */,
|
||||||
listStyle: string,
|
listStyle: string,
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ import ViewPropTypes from '../View/ViewPropTypes';
|
|||||||
import { bool, number, oneOf, oneOfType, string } from 'prop-types';
|
import { bool, number, oneOf, oneOfType, string } from 'prop-types';
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
|
|
||||||
|
const createSvgCircle = style => (
|
||||||
|
<circle cx="16" cy="16" fill="none" r="14" strokeWidth="4" style={style} />
|
||||||
|
);
|
||||||
|
|
||||||
class ActivityIndicator extends Component {
|
class ActivityIndicator extends Component {
|
||||||
static displayName = 'ActivityIndicator';
|
static displayName = 'ActivityIndicator';
|
||||||
|
|
||||||
@@ -40,29 +44,15 @@ class ActivityIndicator extends Component {
|
|||||||
|
|
||||||
const svg = (
|
const svg = (
|
||||||
<svg height="100%" viewBox="0 0 32 32" width="100%">
|
<svg height="100%" viewBox="0 0 32 32" width="100%">
|
||||||
<circle
|
{createSvgCircle({
|
||||||
cx="16"
|
stroke: color,
|
||||||
cy="16"
|
opacity: 0.2
|
||||||
fill="none"
|
})}
|
||||||
r="14"
|
{createSvgCircle({
|
||||||
strokeWidth="4"
|
stroke: color,
|
||||||
style={{
|
strokeDasharray: 80,
|
||||||
stroke: color,
|
strokeDashoffset: 60
|
||||||
opacity: 0.2
|
})}
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<circle
|
|
||||||
cx="16"
|
|
||||||
cy="16"
|
|
||||||
fill="none"
|
|
||||||
r="14"
|
|
||||||
strokeWidth="4"
|
|
||||||
style={{
|
|
||||||
stroke: color,
|
|
||||||
strokeDasharray: 80,
|
|
||||||
strokeDashoffset: 60
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</svg>
|
</svg>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -19,21 +19,21 @@ describe('components/Switch', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
|
||||||
describe('onValueChange', () => {
|
describe('onValueChange', () => {
|
||||||
test('when value is "false" it receives "true"', () => {
|
test('when value is "false" it receives "true"', () => {
|
||||||
const handleValueChange = (value) => expect(value === true).toBeTruthy();
|
const onValueChange = jest.fn();
|
||||||
const component = shallow(<Switch onValueChange={handleValueChange} value={false} />);
|
const component = shallow(<Switch onValueChange={onValueChange} value={false} />);
|
||||||
component.find('input').simulate('click');
|
component.find('input').simulate('change', { nativeEvent: { target: { checked: true } } });
|
||||||
|
expect(onValueChange).toHaveBeenCalledWith(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('when value is "true" it receives "false"', () => {
|
test('when value is "true" it receives "false"', () => {
|
||||||
const handleValueChange = (value) => expect(value === false).toBeTruthy();
|
const onValueChange = jest.fn();
|
||||||
const component = shallow(<Switch onValueChange={handleValueChange} value />);
|
const component = shallow(<Switch onValueChange={onValueChange} value />);
|
||||||
component.find('input').simulate('click');
|
component.find('input').simulate('change', { nativeEvent: { target: { checked: false } } });
|
||||||
|
expect(onValueChange).toHaveBeenCalledWith(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
|
|
||||||
describe('value', () => {
|
describe('value', () => {
|
||||||
test('when "false" an unchecked checkbox is rendered', () => {
|
test('when "false" an unchecked checkbox is rendered', () => {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ const TextStylePropTypes = {
|
|||||||
letterSpacing: numberOrString,
|
letterSpacing: numberOrString,
|
||||||
lineHeight: numberOrString,
|
lineHeight: numberOrString,
|
||||||
textAlign: TextAlignPropType,
|
textAlign: TextAlignPropType,
|
||||||
textAlignVertical: oneOf(['auto', 'bottom', 'center', 'top']),
|
textAlignVertical: string,
|
||||||
textDecorationColor: ColorPropType,
|
textDecorationColor: ColorPropType,
|
||||||
textDecorationLine: string,
|
textDecorationLine: string,
|
||||||
textDecorationStyle: string,
|
textDecorationStyle: string,
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import Animated from './apis/Animated';
|
|||||||
import AppRegistry from './apis/AppRegistry';
|
import AppRegistry from './apis/AppRegistry';
|
||||||
import AppState from './apis/AppState';
|
import AppState from './apis/AppState';
|
||||||
import AsyncStorage from './apis/AsyncStorage';
|
import AsyncStorage from './apis/AsyncStorage';
|
||||||
import BackAndroid from './apis/BackAndroid';
|
import BackHandler from './apis/BackHandler';
|
||||||
import Clipboard from './apis/Clipboard';
|
import Clipboard from './apis/Clipboard';
|
||||||
import Dimensions from './apis/Dimensions';
|
import Dimensions from './apis/Dimensions';
|
||||||
import Easing from './apis/Easing';
|
import Easing from './apis/Easing';
|
||||||
@@ -73,7 +73,7 @@ export {
|
|||||||
AppRegistry,
|
AppRegistry,
|
||||||
AppState,
|
AppState,
|
||||||
AsyncStorage,
|
AsyncStorage,
|
||||||
BackAndroid,
|
BackHandler,
|
||||||
Clipboard,
|
Clipboard,
|
||||||
Dimensions,
|
Dimensions,
|
||||||
Easing,
|
Easing,
|
||||||
@@ -138,8 +138,7 @@ const ReactNative = {
|
|||||||
AppRegistry,
|
AppRegistry,
|
||||||
AppState,
|
AppState,
|
||||||
AsyncStorage,
|
AsyncStorage,
|
||||||
BackAndroid,
|
BackHandler,
|
||||||
BackHandler: BackAndroid,
|
|
||||||
Clipboard,
|
Clipboard,
|
||||||
Dimensions,
|
Dimensions,
|
||||||
Easing,
|
Easing,
|
||||||
|
|||||||
Reference in New Issue
Block a user