[change] Remove jest preset

Also add node-based unit tests for SSR APIs.
This commit is contained in:
Nicolas Gallagher
2022-03-01 11:50:44 -08:00
parent b27c9820db
commit 9b0c1193a2
7 changed files with 33 additions and 89 deletions

View File

@@ -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')
};

View File

@@ -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
}));

View File

@@ -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)');

View 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'
};

View File

@@ -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;

View File

@@ -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 {

View File

@@ -1 +0,0 @@
/* eslint-env jasmine, jest */