runtimeErrorsAndWarnings.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.makeInvalidTransformerError =
  6. exports.makeInvalidSyncTransformerError =
  7. exports.makeInvalidSourceMapWarning =
  8. exports.makeInvalidReturnValueError =
  9. void 0;
  10. function _chalk() {
  11. const data = _interopRequireDefault(require('chalk'));
  12. _chalk = function () {
  13. return data;
  14. };
  15. return data;
  16. }
  17. function _slash() {
  18. const data = _interopRequireDefault(require('slash'));
  19. _slash = function () {
  20. return data;
  21. };
  22. return data;
  23. }
  24. function _interopRequireDefault(obj) {
  25. return obj && obj.__esModule ? obj : {default: obj};
  26. }
  27. /**
  28. * Copyright (c) Meta Platforms, Inc. and affiliates.
  29. *
  30. * This source code is licensed under the MIT license found in the
  31. * LICENSE file in the root directory of this source tree.
  32. */
  33. const BULLET = '\u25cf ';
  34. const DOCUMENTATION_NOTE = ` ${_chalk().default.bold(
  35. 'Code Transformation Documentation:'
  36. )}
  37. https://jestjs.io/docs/code-transformation
  38. `;
  39. const UPGRADE_NOTE = ` ${_chalk().default.bold(
  40. 'This error may be caused by a breaking change in Jest 28:'
  41. )}
  42. https://jestjs.io/docs/28.x/upgrading-to-jest28#transformer
  43. `;
  44. const makeInvalidReturnValueError = transformPath =>
  45. _chalk().default.red(
  46. [
  47. _chalk().default.bold(`${BULLET}Invalid return value:`),
  48. ' `process()` or/and `processAsync()` method of code transformer found at ',
  49. ` "${(0, _slash().default)(transformPath)}" `,
  50. ' should return an object or a Promise resolving to an object. The object ',
  51. ' must have `code` property with a string of processed code.',
  52. ''
  53. ].join('\n') +
  54. UPGRADE_NOTE +
  55. DOCUMENTATION_NOTE
  56. );
  57. exports.makeInvalidReturnValueError = makeInvalidReturnValueError;
  58. const makeInvalidSourceMapWarning = (filename, transformPath) =>
  59. _chalk().default.yellow(
  60. [
  61. _chalk().default.bold(`${BULLET}Invalid source map:`),
  62. ` The source map for "${(0, _slash().default)(
  63. filename
  64. )}" returned by "${(0, _slash().default)(transformPath)}" is invalid.`,
  65. ' Proceeding without source mapping for that file.'
  66. ].join('\n')
  67. );
  68. exports.makeInvalidSourceMapWarning = makeInvalidSourceMapWarning;
  69. const makeInvalidSyncTransformerError = transformPath =>
  70. _chalk().default.red(
  71. [
  72. _chalk().default.bold(`${BULLET}Invalid synchronous transformer module:`),
  73. ` "${(0, _slash().default)(
  74. transformPath
  75. )}" specified in the "transform" object of Jest configuration`,
  76. ' must export a `process` function.',
  77. ''
  78. ].join('\n') + DOCUMENTATION_NOTE
  79. );
  80. exports.makeInvalidSyncTransformerError = makeInvalidSyncTransformerError;
  81. const makeInvalidTransformerError = transformPath =>
  82. _chalk().default.red(
  83. [
  84. _chalk().default.bold(`${BULLET}Invalid transformer module:`),
  85. ` "${(0, _slash().default)(
  86. transformPath
  87. )}" specified in the "transform" object of Jest configuration`,
  88. ' must export a `process` or `processAsync` or `createTransformer` function.',
  89. ''
  90. ].join('\n') + DOCUMENTATION_NOTE
  91. );
  92. exports.makeInvalidTransformerError = makeInvalidTransformerError;