Update custom "exports" conditions in Jest environment

Summary:
Updates the default set of `"exports"` condition names in our `ReactNativeEnv` for Jest, so that it aligns with the defaults in React Native CLI (https://github.com/react-native-community/cli/pull/1862).

Also includes a subtle update to how this is accomplished. Instead of overriding `exportConditions()`, we assign to the underlying class property — this allows users (once https://github.com/facebook/jest/pull/13989 is merged) to override `customExportConditions` via [`testEnvironmentOptions`](https://jestjs.io/docs/configuration#testenvironmentoptions-object).

```js
  preset: 'react-native',
  testEnvironmentOptions: {
    customExportConditions: ['test', 'react-native'],
  },
```

Changelog: [Internal]

Reviewed By: jacdebug

Differential Revision: D43879056

fbshipit-source-id: 86fffe2b5fdf9d8492d25b8b12a78be75b5fa3be
This commit is contained in:
Alex Hunt 2023-03-15 17:18:08 -07:00 committed by Facebook GitHub Bot
parent b1b6673796
commit 0a3c55562b

View File

@ -12,7 +12,5 @@
const NodeEnv = require('jest-environment-node').TestEnvironment;
module.exports = class ReactNativeEnv extends NodeEnv {
exportConditions() {
return ['react-native'];
}
customExportConditions = ['import', 'require', 'react-native'];
};