runGlobalHook.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. function _pEachSeries() {
  7. const data = _interopRequireDefault(require('p-each-series'));
  8. _pEachSeries = function _pEachSeries() {
  9. return data;
  10. };
  11. return data;
  12. }
  13. function _transform() {
  14. const data = require('@jest/transform');
  15. _transform = function _transform() {
  16. return data;
  17. };
  18. return data;
  19. }
  20. function _jestUtil() {
  21. const data = require('jest-util');
  22. _jestUtil = function _jestUtil() {
  23. return data;
  24. };
  25. return data;
  26. }
  27. function _interopRequireDefault(obj) {
  28. return obj && obj.__esModule ? obj : {default: obj};
  29. }
  30. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
  31. try {
  32. var info = gen[key](arg);
  33. var value = info.value;
  34. } catch (error) {
  35. reject(error);
  36. return;
  37. }
  38. if (info.done) {
  39. resolve(value);
  40. } else {
  41. Promise.resolve(value).then(_next, _throw);
  42. }
  43. }
  44. function _asyncToGenerator(fn) {
  45. return function() {
  46. var self = this,
  47. args = arguments;
  48. return new Promise(function(resolve, reject) {
  49. var gen = fn.apply(self, args);
  50. function _next(value) {
  51. asyncGeneratorStep(gen, resolve, reject, _next, _throw, 'next', value);
  52. }
  53. function _throw(err) {
  54. asyncGeneratorStep(gen, resolve, reject, _next, _throw, 'throw', err);
  55. }
  56. _next(undefined);
  57. });
  58. };
  59. }
  60. var _default =
  61. /*#__PURE__*/
  62. (function() {
  63. var _ref = _asyncToGenerator(function*({
  64. allTests,
  65. globalConfig,
  66. moduleName
  67. }) {
  68. const globalModulePaths = new Set(
  69. allTests.map(test => test.context.config[moduleName])
  70. );
  71. if (globalConfig[moduleName]) {
  72. globalModulePaths.add(globalConfig[moduleName]);
  73. }
  74. if (globalModulePaths.size > 0) {
  75. yield (0, _pEachSeries().default)(
  76. Array.from(globalModulePaths),
  77. /*#__PURE__*/
  78. (function() {
  79. var _ref2 = _asyncToGenerator(function*(modulePath) {
  80. if (!modulePath) {
  81. return;
  82. }
  83. const correctConfig = allTests.find(
  84. t => t.context.config[moduleName] === modulePath
  85. );
  86. const projectConfig = correctConfig
  87. ? correctConfig.context.config // Fallback to first config
  88. : allTests[0].context.config;
  89. const transformer = new (_transform()).ScriptTransformer(
  90. projectConfig
  91. );
  92. yield transformer.requireAndTranspileModule(
  93. modulePath,
  94. /*#__PURE__*/
  95. (function() {
  96. var _ref3 = _asyncToGenerator(function*(m) {
  97. const globalModule = (0, _jestUtil().interopRequireDefault)(
  98. m
  99. ).default;
  100. if (typeof globalModule !== 'function') {
  101. throw new TypeError(
  102. `${moduleName} file must export a function at ${modulePath}`
  103. );
  104. }
  105. yield globalModule(globalConfig);
  106. });
  107. return function(_x3) {
  108. return _ref3.apply(this, arguments);
  109. };
  110. })()
  111. );
  112. });
  113. return function(_x2) {
  114. return _ref2.apply(this, arguments);
  115. };
  116. })()
  117. );
  118. }
  119. return Promise.resolve();
  120. });
  121. return function(_x) {
  122. return _ref.apply(this, arguments);
  123. };
  124. })();
  125. exports.default = _default;