UNPKG

@nx/react-native

Version:

The Nx Plugin for React Native contains generators for managing React Native applications and libraries within an Nx workspace. It provides: -Integration with libraries such as Jest, Detox, and Storybook. -Scaffolding for creating buildable libraries th

49 lines (48 loc) 1.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addJest = addJest; const devkit_1 = require("@nx/devkit"); const jest_1 = require("@nx/jest"); async function addJest(host, unitTestRunner, projectName, appProjectRoot, js, skipPackageJson, addPlugin, runtimeTsconfigFileName) { if (unitTestRunner !== 'jest') { return () => { }; } const jestTask = await (0, jest_1.configurationGenerator)(host, { js, project: projectName, supportTsx: true, skipSerializers: true, setupFile: 'react-native', compiler: 'babel', skipPackageJson, skipFormat: true, addPlugin, runtimeTsconfigFileName, }); // overwrite the jest.config.ts file because react native needs to have special transform property const configPath = `${appProjectRoot}/jest.config.${js ? 'js' : 'ts'}`; const content = `module.exports = { displayName: '${projectName}', preset: 'react-native', resolver: '@nx/jest/plugins/resolver', moduleFileExtensions: ['ts', 'js', 'html', 'tsx', 'jsx'], setupFilesAfterEnv: ['<rootDir>/src/test-setup.${js ? 'js' : 'ts'}'], moduleNameMapper: { '\\\\.svg$': '@nx/react-native/plugins/jest/svg-mock' }, transform: { '^.+\\.(js|ts|tsx)$': [ 'babel-jest', { configFile: __dirname + '/.babelrc.js', }, ], '^.+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$': require.resolve( 'react-native/jest/assetFileTransformer.js' ), }, coverageDirectory: '${(0, devkit_1.offsetFromRoot)(appProjectRoot)}coverage/${appProjectRoot}' };`; host.write(configPath, content); return jestTask; }