How to separate tests for web and native? #1967
-
I need separate tests for web and native in a multiplatform project, I just founding something like this:
npm run testWeb
npm run testNative
npm run test |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
@victorfernandesraton Did you able to achieve this? Working on the similar lines and facing some challenges. |
Beta Was this translation helpful? Give feedback.
-
1y after them and same problem... |
Beta Was this translation helpful? Give feedback.
-
You can use jest projects to configure different test environments, and match against different file extensions for platform-specific tests. Configure jest to produce platform-specific snapshots too. Then when you run jest it can correctly run any combination of web-only, native-only, and multiplatform unit tests. For example: // jest.config.js
module.exports = {
projects: [
{
displayName: 'web',
moduleNameMapper: {
// alias react-native
'^react-native$': 'react-native-web'
},
// store DOM snapshots
snapshotResolver: '<rootDir>/configs/jest-web-resolver.js',
// use jsdom
testEnvironment: 'jsdom',
testMatch: [
// all multi-platform tests
'<rootDir>/src/*/__tests__/*-test.js',
// DOM-only tests
'<rootDir>/src/*/__tests__/*-test.web.js'
]
},
{
displayName: 'native',
// store React Native snapshots
snapshotResolver: '<rootDir>/configs/jest-native-resolver.js',
// use Node.js
testEnvironment: 'node',
testMatch: [
// all multi-platform tests
'<rootDir>/packages/react-strict-dom/tests/*-test.js',
// native-only tests
'<rootDir>/packages/react-strict-dom/tests/*-test.native.js'
],
}
]
} If you want platform-specific test commands, you can run individual projects like this:
|
Beta Was this translation helpful? Give feedback.
You can use jest projects to configure different test environments, and match against different file extensions for platform-specific tests. Configure jest to produce platform-specific snapshots too. Then when you run jest it can correctly run any combination of web-only, native-only, and multiplatform unit tests.
For example: