From da91d4011fc3bdde4c761c68403e8cffeb84906c Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Tue, 24 Jan 2023 19:30:34 +0100 Subject: [PATCH] Fix mobile unit tests --- test/native/jest.config.js | 32 ++++++++++++++++---------------- test/unit/scripts/resolver.js | 3 ++- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/test/native/jest.config.js b/test/native/jest.config.js index 1f4b82492cbe4..7449e7bb8f222 100644 --- a/test/native/jest.config.js +++ b/test/native/jest.config.js @@ -13,50 +13,50 @@ if ( process.env.TEST_RN_PLATFORM ) { console.log( 'Setting RN platform to: default (' + defaultPlatform + ')' ); } -const configPath = 'test/native'; - const transpiledPackageNames = glob( '../../packages/*/src/index.{js,ts}' ).map( ( fileName ) => fileName.split( '/' )[ 3 ] ); module.exports = { verbose: true, - rootDir: '../../', + rootDir: '.', + roots: [ '/../..' ], // Automatically clear mock calls and instances between every test. clearMocks: true, preset: 'react-native', - setupFiles: [ '/' + configPath + '/setup.js' ], - setupFilesAfterEnv: [ '/' + configPath + '/setup-after-env.js' ], + setupFiles: [ '/setup.js' ], + setupFilesAfterEnv: [ '/setup-after-env.js' ], testMatch: [ - '**/test/!(helper)*.native.[jt]s?(x)', - '/packages/react-native-*/**/?(*.)+(spec|test).[jt]s?(x)', + '/../../**/test/!(helper)*.native.[jt]s?(x)', + '/../../packages/react-native-*/**/?(*.)+(spec|test).[jt]s?(x)', ], testPathIgnorePatterns: [ '/node_modules/', '/__device-tests__/', - '/.*/build/', - '/.*/build-module/', + '/../../.*/build/', + '/../../.*/build-module/', ], testEnvironmentOptions: { url: 'http://localhost/', }, + resolver: '/../../test/unit/scripts/resolver.js', // Add the `Libraries/Utilities` subfolder to the module directories, otherwise haste/jest doesn't find Platform.js on Travis, // and add it first so https://github.com/facebook/react-native/blob/v0.60.0/Libraries/react-native/react-native-implementation.js#L324-L326 doesn't pick up the Platform npm module. moduleDirectories: [ - 'node_modules/react-native/Libraries/Utilities', - 'node_modules', + '../../node_modules/react-native/Libraries/Utilities', + '../../node_modules', ], moduleNameMapper: { // Mock the CSS modules. See https://facebook.github.io/jest/docs/en/webpack.html#handling-static-assets - '\\.(scss)$': '/' + configPath + '/__mocks__/styleMock.js', + '\\.(scss)$': '/__mocks__/styleMock.js', '\\.(eot|otf|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': - '/' + configPath + '/__mocks__/fileMock.js', + '/__mocks__/fileMock.js', [ `@wordpress\\/(${ transpiledPackageNames.join( '|' ) })$` ]: - '/packages/$1/src', - 'test/helpers$': '/test/native/helpers.js', + '/../../packages/$1/src', + 'test/helpers$': '/../../test/native/helpers.js', }, modulePathIgnorePatterns: [ - '/packages/react-native-editor/node_modules', + '/../../packages/react-native-editor/node_modules', ], haste: { defaultPlatform: rnPlatform, diff --git a/test/unit/scripts/resolver.js b/test/unit/scripts/resolver.js index eff7be116f87e..ca4bc2b3b4d99 100644 --- a/test/unit/scripts/resolver.js +++ b/test/unit/scripts/resolver.js @@ -23,7 +23,8 @@ module.exports = ( path, options ) => { if ( pkg.name === 'uuid' || pkg.name === 'react-colorful' || - pkg.name === '@eslint/eslintrc' + pkg.name === '@eslint/eslintrc' || + pkg.name === 'expect' ) { delete pkg.exports; delete pkg.module;