mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-06-01 01:59:10 +00:00
[change] Remove jest preset
Also add node-based unit tests for SSR APIs.
This commit is contained in:
-7
@@ -1,7 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
moduleNameMapper: {
|
|
||||||
'^react-native$': require.resolve('./dist/cjs')
|
|
||||||
},
|
|
||||||
setupFiles: [require.resolve('./jest/setup.js')],
|
|
||||||
testEnvironment: require.resolve('jest-environment-jsdom')
|
|
||||||
};
|
|
||||||
-18
@@ -1,18 +0,0 @@
|
|||||||
/* eslint-env jasmine, jest */
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
global.__DEV__ = true;
|
|
||||||
|
|
||||||
const mockEmptyObject = {};
|
|
||||||
|
|
||||||
// Make sure snapshots contain the original style objects
|
|
||||||
jest.mock('../dist/cjs/exports/StyleSheet/ReactNativePropRegistry', () => ({
|
|
||||||
register: (id) => id,
|
|
||||||
getByID: () => mockEmptyObject
|
|
||||||
}));
|
|
||||||
|
|
||||||
jest.mock('../dist/exports/StyleSheet/ReactNativePropRegistry', () => ({
|
|
||||||
register: (id) => id,
|
|
||||||
getByID: () => mockEmptyObject
|
|
||||||
}));
|
|
||||||
@@ -5,13 +5,18 @@ module.exports = {
|
|||||||
modulePathIgnorePatterns: [
|
modulePathIgnorePatterns: [
|
||||||
'<rootDir>/packages/benchmarks/',
|
'<rootDir>/packages/benchmarks/',
|
||||||
'<rootDir>/packages/docs/',
|
'<rootDir>/packages/docs/',
|
||||||
|
'<rootDir>/packages/examples/',
|
||||||
'<rootDir>/packages/react-native-web/dist/'
|
'<rootDir>/packages/react-native-web/dist/'
|
||||||
],
|
],
|
||||||
// resetMocks: true,
|
|
||||||
rootDir: process.cwd(),
|
rootDir: process.cwd(),
|
||||||
roots: ['<rootDir>/packages'],
|
roots: ['<rootDir>/packages'],
|
||||||
setupFiles: ['jest-canvas-mock', require.resolve('./setupFiles.js')],
|
setupFiles: ['jest-canvas-mock', require.resolve('./setupFiles.dom.js')],
|
||||||
setupFilesAfterEnv: [require.resolve('./setupFramework.js')],
|
snapshotFormat: {
|
||||||
|
printBasicPrototype: false
|
||||||
|
},
|
||||||
testEnvironment: 'jsdom',
|
testEnvironment: 'jsdom',
|
||||||
|
testMatch: ['**/__tests__/**/?(*-)+(spec|test).[jt]s?(x)'],
|
||||||
timers: 'fake'
|
timers: 'fake'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
('**/?(*.)+(spec|test).[jt]s?(x)');
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
coveragePathIgnorePatterns: ['/node_modules/', '<rootDir>/packages/react-native-web/src/vendor/'],
|
||||||
|
modulePathIgnorePatterns: [
|
||||||
|
'<rootDir>/packages/benchmarks/',
|
||||||
|
'<rootDir>/packages/docs/',
|
||||||
|
'<rootDir>/packages/examples/',
|
||||||
|
'<rootDir>/packages/react-native-web/dist/'
|
||||||
|
],
|
||||||
|
rootDir: process.cwd(),
|
||||||
|
roots: ['<rootDir>/packages'],
|
||||||
|
snapshotFormat: {
|
||||||
|
printBasicPrototype: false
|
||||||
|
},
|
||||||
|
testEnvironment: 'node',
|
||||||
|
testMatch: ['**/__tests__/**/?(*-)+(spec|test).node.[jt]s?(x)'],
|
||||||
|
timers: 'fake'
|
||||||
|
};
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { StyleSheet } from '../../packages/react-native-web/src';
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
export default serializer;
|
|
||||||
@@ -1,4 +1,9 @@
|
|||||||
/* eslint-env jasmine, jest */
|
/**
|
||||||
|
* Copyright (c) Nicolas Gallagher.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
// JSDOM doesn't implement ResizeObserver
|
// JSDOM doesn't implement ResizeObserver
|
||||||
class ResizeObserver {
|
class ResizeObserver {
|
||||||
@@ -1 +0,0 @@
|
|||||||
/* eslint-env jasmine, jest */
|
|
||||||
Reference in New Issue
Block a user