diff --git a/docs/docs/jest/_category_.json b/docs/docs/jest/_category_.json new file mode 100644 index 00000000..1bc49f44 --- /dev/null +++ b/docs/docs/jest/_category_.json @@ -0,0 +1,4 @@ +{ + "label": "Testing with Jest", + "position": 6 +} diff --git a/docs/docs/jest/custom-plugins.md b/docs/docs/jest/custom-plugins.md new file mode 100644 index 00000000..8597f1a2 --- /dev/null +++ b/docs/docs/jest/custom-plugins.md @@ -0,0 +1,44 @@ +--- +title: Jest +sidebar_position: 3 +slug: /jest +--- + +# Testing with Jest + +`react-native-esbuild/jest` is a [Jest](https://jestjs.io) transformer. + +It can replace [babel-jest](https://github.com/facebook/react-native/blob/v0.72.6/packages/react-native/jest-preset.js#L18) and supports the React Native testing environment. + +## Setup + +Open your `jest.config.js` and set `@react-native-esbuild/jest` as transformer. + + +Some internal of React Native or Libraries are not transformed. + +```js +// Many react-native npm modules unfortunately don't pre-compile their source code before publishing. +// If you have npm dependencies that have to be transformed you can add the package name to list. +const TRANSFORM_PACKAGES = [ + 'react-native', + 'jest-react-native', + '@react-native', + '@react-native-community', + '@react-navigation', + // ... +]; + +/** + * @type {import('jest').Config} + */ +module.exports = { + preset: 'react-native', + transform: { + '^.+\\.(t|j)sx?$': '@react-native-esbuild/jest', + }, + transformIgnorePatterns: [ + `node_modules/(?!${TRANSFORM_PACKAGES.join('|')})/`, + ], +}; +``` diff --git a/docs/docs/limitations/_category_.json b/docs/docs/limitations/_category_.json index 501ce230..b1bed6fd 100644 --- a/docs/docs/limitations/_category_.json +++ b/docs/docs/limitations/_category_.json @@ -1,4 +1,4 @@ { "label": "Limitations", - "position": 7 + "position": 8 } diff --git a/docs/docs/troubleshooting/_category_.json b/docs/docs/troubleshooting/_category_.json index 8cea9df4..c1e1ed73 100644 --- a/docs/docs/troubleshooting/_category_.json +++ b/docs/docs/troubleshooting/_category_.json @@ -1,4 +1,4 @@ { "label": "Troubleshooting", - "position": 6 + "position": 7 }