web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.0 KiB

  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = expectationResultFactory;
  6. var _prettyFormat = _interopRequireDefault(require('pretty-format'));
  7. function _interopRequireDefault(obj) {
  8. return obj && obj.__esModule ? obj : {default: obj};
  9. }
  10. /**
  11. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  12. *
  13. * This source code is licensed under the MIT license found in the
  14. * LICENSE file in the root directory of this source tree.
  15. */
  16. function messageFormatter({error, message, passed}) {
  17. if (passed) {
  18. return 'Passed.';
  19. }
  20. if (message) {
  21. return message;
  22. }
  23. if (typeof error === 'string') {
  24. return error;
  25. }
  26. if (
  27. // duck-type Error, see #2549
  28. error &&
  29. typeof error === 'object' &&
  30. typeof error.message === 'string' &&
  31. typeof error.name === 'string'
  32. ) {
  33. if (error.message === '') {
  34. return error.name;
  35. }
  36. return `${error.name}: ${error.message}`;
  37. }
  38. return `thrown: ${(0, _prettyFormat.default)(error, {
  39. maxDepth: 3
  40. })}`;
  41. }
  42. function stackFormatter(options, initError, errorMessage) {
  43. if (options.passed) {
  44. return '';
  45. }
  46. if (options.error) {
  47. if (typeof options.error.stack === 'string') {
  48. return options.error.stack;
  49. }
  50. if (options.error === errorMessage) {
  51. return errorMessage;
  52. }
  53. }
  54. if (initError) {
  55. return errorMessage.trimRight() + '\n\n' + initError.stack;
  56. }
  57. return new Error(errorMessage).stack;
  58. }
  59. function expectationResultFactory(options, initError) {
  60. const message = messageFormatter(options);
  61. const stack = stackFormatter(options, initError, message);
  62. if (options.passed) {
  63. return {
  64. error: options.error,
  65. matcherName: options.matcherName,
  66. message,
  67. passed: options.passed,
  68. stack
  69. };
  70. }
  71. return {
  72. actual: options.actual,
  73. error: options.error,
  74. expected: options.expected,
  75. matcherName: options.matcherName,
  76. message,
  77. passed: options.passed,
  78. stack
  79. };
  80. }