UNPKG

@callstack/reassure-measure

Version:

Performance measurement library for React and React Native

77 lines (75 loc) 3.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getTestingLibrary = getTestingLibrary; exports.resolveTestingLibrary = resolveTestingLibrary; var logger = _interopRequireWildcard(require("@callstack/reassure-logger")); var _config = require("./config"); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } let RNTL; try { // eslint-disable-next-line import/no-extraneous-dependencies RNTL = require('@testing-library/react-native'); } catch { // Do nothing } let RTL; try { // eslint-disable-next-line import/no-extraneous-dependencies RTL = require('@testing-library/react'); } catch { // Do nothing } function resolveTestingLibrary() { // Explicit testing library option if (_config.config.testingLibrary) { if (_config.config.testingLibrary === 'react-native') { if (!RNTL) { throw new Error(`Unable to import '@testing-library/react-native' dependency`); } logger.verbose(`Using '@testing-library/react-native' to render components`); return RNTL; } if (_config.config.testingLibrary === 'react') { if (!RTL) { throw new Error(`Unable to import '@testing-library/react' dependency`); } logger.verbose(`Using '@testing-library/react' to render components`); return RTL; } if (typeof _config.config.testingLibrary === 'object' && typeof _config.config.testingLibrary.render === 'function' && typeof _config.config.testingLibrary.cleanup === 'function') { logger.verbose(`Using custom 'render' and 'cleanup' functions to render components`); return _config.config.testingLibrary; } throw new Error(`Unsupported 'testingLibrary' value. Please set 'testingLibrary' to one of following values: 'react-native', 'react' or { render, cleanup }.`); } // Testing library auto-detection if (RNTL != null && RTL != null) { logger.warn("Both '@testing-library/react-native' and '@testing-library/react' are installed. Using '@testing-library/react-native' by default.\n\nYou can resolve this warning by explicitly calling 'configure({ testingLibrary: 'react-native' })' or 'configure({ testingLibrary: 'react' })' in your test setup file."); return RNTL; } if (RNTL != null) { logger.verbose(`Using '@testing-library/react-native' to render components`); return RNTL; } if (RTL != null) { logger.verbose(`Using '@testing-library/react' to render components`); return RTL; } throw new Error(`Unable to import neither '@testing-library/react-native' nor '@testing-library/react'.` + `\nAdd either of these testing libraries to your 'package.json'`); } function getTestingLibrary() { if (typeof _config.config.testingLibrary === 'string') { return _config.config.testingLibrary; } if (RNTL != null) { return 'react-native'; } if (RTL != null) { return 'react'; } return null; } //# sourceMappingURL=testing-library.js.map