errors.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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) { return obj && obj.__esModule ? obj : { default: obj }; }
  19. /**
  20. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  21. *
  22. * This source code is licensed under the MIT license found in the
  23. * LICENSE file in the root directory of this source tree.
  24. *
  25. *
  26. */
  27. const errorMessage = exports.errorMessage = (option, received, defaultValue, options) => {
  28. const message = ` Option ${(_chalk || _load_chalk()).default.bold(`"${option}"`)} must be of type:
  29. ${(_chalk || _load_chalk()).default.bold.green((0, (_jestGetType || _load_jestGetType()).default)(defaultValue))}
  30. but instead received:
  31. ${(_chalk || _load_chalk()).default.bold.red((0, (_jestGetType || _load_jestGetType()).default)(received))}
  32. Example:
  33. {
  34. ${(_chalk || _load_chalk()).default.bold(`"${option}"`)}: ${(_chalk || _load_chalk()).default.bold((0, (_utils || _load_utils()).format)(defaultValue))}
  35. }`;
  36. const comment = options.comment;
  37. const name = options.title && options.title.error || (_utils || _load_utils()).ERROR;
  38. throw new (_utils || _load_utils()).ValidationError(name, message, comment);
  39. };