diff --git a/packages/react-native-web/jest-preset.js b/packages/react-native-web/jest-preset.js deleted file mode 100644 index f28877d8..00000000 --- a/packages/react-native-web/jest-preset.js +++ /dev/null @@ -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') -}; diff --git a/packages/react-native-web/jest/setup.js b/packages/react-native-web/jest/setup.js deleted file mode 100644 index f2231363..00000000 --- a/packages/react-native-web/jest/setup.js +++ /dev/null @@ -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 -})); diff --git a/scripts/jest/config.js b/scripts/jest/config.js index 19dbf0b5..885181d6 100644 --- a/scripts/jest/config.js +++ b/scripts/jest/config.js @@ -5,13 +5,18 @@ module.exports = { modulePathIgnorePatterns: [ '/packages/benchmarks/', '/packages/docs/', + '/packages/examples/', '/packages/react-native-web/dist/' ], - // resetMocks: true, rootDir: process.cwd(), roots: ['/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)'); diff --git a/scripts/jest/config.node.js b/scripts/jest/config.node.js new file mode 100644 index 00000000..b1b00231 --- /dev/null +++ b/scripts/jest/config.node.js @@ -0,0 +1,19 @@ +'use strict'; + +module.exports = { + coveragePathIgnorePatterns: ['/node_modules/', '/packages/react-native-web/src/vendor/'], + modulePathIgnorePatterns: [ + '/packages/benchmarks/', + '/packages/docs/', + '/packages/examples/', + '/packages/react-native-web/dist/' + ], + rootDir: process.cwd(), + roots: ['/packages'], + snapshotFormat: { + printBasicPrototype: false + }, + testEnvironment: 'node', + testMatch: ['**/__tests__/**/?(*-)+(spec|test).node.[jt]s?(x)'], + timers: 'fake' +}; diff --git a/scripts/jest/serializer.js b/scripts/jest/serializer.js deleted file mode 100644 index b5ee71cd..00000000 --- a/scripts/jest/serializer.js +++ /dev/null @@ -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; diff --git a/scripts/jest/setupFiles.js b/scripts/jest/setupFiles.dom.js similarity index 75% rename from scripts/jest/setupFiles.js rename to scripts/jest/setupFiles.dom.js index 61bf83bd..037994b1 100644 --- a/scripts/jest/setupFiles.js +++ b/scripts/jest/setupFiles.dom.js @@ -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 { diff --git a/scripts/jest/setupFramework.js b/scripts/jest/setupFramework.js deleted file mode 100644 index e28f9559..00000000 --- a/scripts/jest/setupFramework.js +++ /dev/null @@ -1 +0,0 @@ -/* eslint-env jasmine, jest */