nx/packages/jest/preset/jest-preset.ts
Caleb Ukle 657b2bff5a
feat(testing): support jest 28 (#10857)
* feat(testing): support jest 28

WIP jest migration

* fix(testing): jest-environment-jsdom must be explicitly added now

* fix(testing): add rxjs to the transform lsit

* fix(testing): jest ts-jest updates and resolver issues

* feat(testing): remove test runner for react native jest

* feat(testing): add preprocessor for react native jest

* fix(testing): update query to handle tsx file syntax, remove rxjs transform

* chore(repo): remove file from accident commit

* chore(testing): update migration to target 14.6 for RN jest preprocessor

* fix(testing): call passed in packageFilter if preset

* docs(testing): add resolver env var to troubleshooting guide

* chore(repo): prep resolver for jest 28 migration

* fix(testing): update deps to handle esbuild-wasm service error

* fix(testing): switch to testEnvironmentOptions for cjs loading vs resolver list

* fix(testing): force babel-jest preset in transformer for project transforms

* chore(testing): address PR feedback

* fix(testing): address pr feedback, remove react-native transform

* chore(testing): update createTreeWithEmptyWorkspace calls

* chore(testing): address pr feedback

* feat(testing): add migration script for react native to rename .babelrc to babel.config.json

* chore(testing): nx format after rebase

* chore(testing): fix display name for @nrwl/js

Co-authored-by: Emily Xiong <xiongemi@gmail.com>
2022-08-18 18:40:31 -04:00

27 lines
974 B
TypeScript

export const nxPreset = {
testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'],
resolver: '@nrwl/jest/plugins/resolver',
moduleFileExtensions: ['ts', 'js', 'mjs', 'html'],
coverageReporters: ['html'],
transform: {
'^.+\\.(ts|js|html)$': 'ts-jest',
},
testEnvironment: 'jsdom',
/**
* manually set the exports names to load in common js, to mimic the behaviors of jest 27
* before jest didn't fully support package exports and would load in common js code (typically via main field). now jest 28+ will load in the browser esm code, but jest esm support is not fully supported.
* In this case we will tell jest to load in the common js code regardless of environment.
*
* this can be removed via just overriding this setting in it's usage
*
* @example
* module.exports = {
* ...nxPreset,
* testEnvironmentOptions: {},
* }
*/
testEnvironmentOptions: {
customExportConditions: ['node', 'require', 'default'],
},
};