runGlobalHook.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. function _transform() {
  14. const data = require('@jest/transform');
  15. _transform = function () {
  16. return data;
  17. };
  18. return data;
  19. }
  20. function _jestUtil() {
  21. const data = require('jest-util');
  22. _jestUtil = function () {
  23. return data;
  24. };
  25. return data;
  26. }
  27. function _interopRequireDefault(obj) {
  28. return obj && obj.__esModule ? obj : {default: obj};
  29. }
  30. /**
  31. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  32. *
  33. * This source code is licensed under the MIT license found in the
  34. * LICENSE file in the root directory of this source tree.
  35. */
  36. var _default = async ({allTests, globalConfig, moduleName}) => {
  37. const globalModulePaths = new Set(
  38. allTests.map(test => test.context.config[moduleName])
  39. );
  40. if (globalConfig[moduleName]) {
  41. globalModulePaths.add(globalConfig[moduleName]);
  42. }
  43. if (globalModulePaths.size > 0) {
  44. await (0, _pEachSeries().default)(
  45. Array.from(globalModulePaths),
  46. async modulePath => {
  47. if (!modulePath) {
  48. return;
  49. }
  50. const correctConfig = allTests.find(
  51. t => t.context.config[moduleName] === modulePath
  52. );
  53. const projectConfig = correctConfig
  54. ? correctConfig.context.config // Fallback to first config
  55. : allTests[0].context.config;
  56. const transformer = new (_transform().ScriptTransformer)(projectConfig);
  57. await transformer.requireAndTranspileModule(modulePath, async m => {
  58. const globalModule = (0, _jestUtil().interopRequireDefault)(m)
  59. .default;
  60. if (typeof globalModule !== 'function') {
  61. throw new TypeError(
  62. `${moduleName} file must export a function at ${modulePath}`
  63. );
  64. }
  65. await globalModule(globalConfig);
  66. });
  67. }
  68. );
  69. }
  70. return Promise.resolve();
  71. };
  72. exports.default = _default;