test_worker.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.worker = undefined;
  6. let worker = (exports.worker = (() => {
  7. var _ref2 = _asyncToGenerator(function*(_ref) {
  8. let config = _ref.config,
  9. globalConfig = _ref.globalConfig,
  10. path = _ref.path,
  11. rawModuleMap = _ref.rawModuleMap;
  12. try {
  13. return yield (0,
  14. (_run_test || _load_run_test())
  15. .default)(path, globalConfig, config, getResolver(config, rawModuleMap));
  16. } catch (error) {
  17. throw formatError(error);
  18. }
  19. });
  20. return function worker(_x) {
  21. return _ref2.apply(this, arguments);
  22. };
  23. })());
  24. var _exit;
  25. function _load_exit() {
  26. return (_exit = _interopRequireDefault(require('exit')));
  27. }
  28. var _jestHasteMap;
  29. function _load_jestHasteMap() {
  30. return (_jestHasteMap = _interopRequireDefault(require('jest-haste-map')));
  31. }
  32. var _jestMessageUtil;
  33. function _load_jestMessageUtil() {
  34. return (_jestMessageUtil = require('jest-message-util'));
  35. }
  36. var _jestRuntime;
  37. function _load_jestRuntime() {
  38. return (_jestRuntime = _interopRequireDefault(require('jest-runtime')));
  39. }
  40. var _run_test;
  41. function _load_run_test() {
  42. return (_run_test = _interopRequireDefault(require('./run_test')));
  43. }
  44. function _interopRequireDefault(obj) {
  45. return obj && obj.__esModule ? obj : {default: obj};
  46. }
  47. function _asyncToGenerator(fn) {
  48. return function() {
  49. var gen = fn.apply(this, arguments);
  50. return new Promise(function(resolve, reject) {
  51. function step(key, arg) {
  52. try {
  53. var info = gen[key](arg);
  54. var value = info.value;
  55. } catch (error) {
  56. reject(error);
  57. return;
  58. }
  59. if (info.done) {
  60. resolve(value);
  61. } else {
  62. return Promise.resolve(value).then(
  63. function(value) {
  64. step('next', value);
  65. },
  66. function(err) {
  67. step('throw', err);
  68. }
  69. );
  70. }
  71. }
  72. return step('next');
  73. });
  74. };
  75. }
  76. /**
  77. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  78. *
  79. * This source code is licensed under the MIT license found in the
  80. * LICENSE file in the root directory of this source tree.
  81. *
  82. *
  83. */
  84. // Make sure uncaught errors are logged before we exit.
  85. process.on('uncaughtException', err => {
  86. console.error(err.stack);
  87. (0, (_exit || _load_exit()).default)(1);
  88. });
  89. const formatError = error => {
  90. if (typeof error === 'string') {
  91. var _separateMessageFromS = (0,
  92. (_jestMessageUtil || _load_jestMessageUtil()).separateMessageFromStack)(
  93. error
  94. );
  95. const message = _separateMessageFromS.message,
  96. stack = _separateMessageFromS.stack;
  97. return {
  98. message: message,
  99. stack: stack,
  100. type: 'Error'
  101. };
  102. }
  103. return {
  104. code: error.code || undefined,
  105. message: error.message,
  106. stack: error.stack,
  107. type: 'Error'
  108. };
  109. };
  110. const resolvers = Object.create(null);
  111. const getResolver = (config, rawModuleMap) => {
  112. // In watch mode, the raw module map with all haste modules is passed from
  113. // the test runner to the watch command. This is because jest-haste-map's
  114. // watch mode does not persist the haste map on disk after every file change.
  115. // To make this fast and consistent, we pass it from the TestRunner.
  116. if (rawModuleMap) {
  117. return (_jestRuntime || _load_jestRuntime()).default.createResolver(
  118. config,
  119. new (_jestHasteMap || _load_jestHasteMap()).default.ModuleMap(
  120. rawModuleMap
  121. )
  122. );
  123. } else {
  124. const name = config.name;
  125. if (!resolvers[name]) {
  126. resolvers[name] = (
  127. _jestRuntime || _load_jestRuntime()
  128. ).default.createResolver(
  129. config,
  130. (_jestRuntime || _load_jestRuntime()).default
  131. .createHasteMap(config)
  132. .readModuleMap()
  133. );
  134. }
  135. return resolvers[name];
  136. }
  137. };