mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-05-14 19:49:27 +00:00
[change] Remove jest preset
Also add node-based unit tests for SSR APIs.
This commit is contained in:
7
packages/react-native-web/jest-preset.js
vendored
7
packages/react-native-web/jest-preset.js
vendored
@@ -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
packages/react-native-web/jest/setup.js
vendored
18
packages/react-native-web/jest/setup.js
vendored
@@ -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: [
|
||||
'<rootDir>/packages/benchmarks/',
|
||||
'<rootDir>/packages/docs/',
|
||||
'<rootDir>/packages/examples/',
|
||||
'<rootDir>/packages/react-native-web/dist/'
|
||||
],
|
||||
// resetMocks: true,
|
||||
rootDir: process.cwd(),
|
||||
roots: ['<rootDir>/packages'],
|
||||
setupFiles: ['jest-canvas-mock', require.resolve('./setupFiles.js')],
|
||||
setupFilesAfterEnv: [require.resolve('./setupFramework.js')],
|
||||
setupFiles: ['jest-canvas-mock', require.resolve('./setupFiles.dom.js')],
|
||||
snapshotFormat: {
|
||||
printBasicPrototype: false
|
||||
},
|
||||
testEnvironment: 'jsdom',
|
||||
testMatch: ['**/__tests__/**/?(*-)+(spec|test).[jt]s?(x)'],
|
||||
timers: 'fake'
|
||||
};
|
||||
|
||||
('**/?(*.)+(spec|test).[jt]s?(x)');
|
||||
|
||||
19
scripts/jest/config.node.js
Normal file
19
scripts/jest/config.node.js
Normal file
@@ -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
|
||||
class ResizeObserver {
|
||||
@@ -1 +0,0 @@
|
||||
/* eslint-env jasmine, jest */
|
||||
Reference in New Issue
Block a user