detectJestVersion.js 791 B

1234567891011121314151617181920212223242526272829
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.detectJestVersion = void 0;
  6. let cachedJestVersion = null;
  7. const detectJestVersion = () => {
  8. if (cachedJestVersion) {
  9. return cachedJestVersion;
  10. }
  11. try {
  12. const jestPath = require.resolve('jest/package.json');
  13. const jestPackageJson = // eslint-disable-next-line @typescript-eslint/no-require-imports
  14. require(jestPath);
  15. if (jestPackageJson.version) {
  16. const [majorVersion] = jestPackageJson.version.split('.');
  17. return cachedJestVersion = parseInt(majorVersion, 10);
  18. }
  19. } catch {}
  20. throw new Error('Unable to detect Jest version - please ensure jest package is installed, or otherwise set version explicitly');
  21. };
  22. exports.detectJestVersion = detectJestVersion;