errors.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.errorMessage = undefined;
  6. var _chalk;
  7. function _load_chalk() {
  8. return (_chalk = _interopRequireDefault(require('chalk')));
  9. }
  10. var _jestGetType;
  11. function _load_jestGetType() {
  12. return (_jestGetType = _interopRequireDefault(require('jest-get-type')));
  13. }
  14. var _utils;
  15. function _load_utils() {
  16. return (_utils = require('./utils'));
  17. }
  18. function _interopRequireDefault(obj) {
  19. return obj && obj.__esModule ? obj : {default: obj};
  20. }
  21. /**
  22. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  23. *
  24. * This source code is licensed under the MIT license found in the
  25. * LICENSE file in the root directory of this source tree.
  26. *
  27. *
  28. */
  29. const errorMessage = (exports.errorMessage = (
  30. option,
  31. received,
  32. defaultValue,
  33. options,
  34. path
  35. ) => {
  36. const message = ` Option ${(_chalk || _load_chalk()).default.bold(
  37. `"${path && path.length > 0 ? path.join('.') + '.' : ''}${option}"`
  38. )} must be of type:
  39. ${(_chalk || _load_chalk()).default.bold.green(
  40. (0, (_jestGetType || _load_jestGetType()).default)(defaultValue)
  41. )}
  42. but instead received:
  43. ${(_chalk || _load_chalk()).default.bold.red(
  44. (0, (_jestGetType || _load_jestGetType()).default)(received)
  45. )}
  46. Example:
  47. {
  48. ${(_chalk || _load_chalk()).default.bold(`"${option}"`)}: ${(
  49. _chalk || _load_chalk()
  50. ).default.bold(
  51. (0, (_utils || _load_utils()).formatPrettyObject)(defaultValue)
  52. )}
  53. }`;
  54. const comment = options.comment;
  55. const name =
  56. (options.title && options.title.error) || (_utils || _load_utils()).ERROR;
  57. throw new (_utils || _load_utils()).ValidationError(name, message, comment);
  58. });