matcherHint.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.ExpectError = void 0;
  6. exports.matcherHint = matcherHint;
  7. var _utilsBundle = require("playwright-core/lib/utilsBundle");
  8. var _utils = require("playwright-core/lib/utils");
  9. /**
  10. * Copyright Microsoft Corporation. All rights reserved.
  11. *
  12. * Licensed under the Apache License, Version 2.0 (the "License");
  13. * you may not use this file except in compliance with the License.
  14. * You may obtain a copy of the License at
  15. *
  16. * http://www.apache.org/licenses/LICENSE-2.0
  17. *
  18. * Unless required by applicable law or agreed to in writing, software
  19. * distributed under the License is distributed on an "AS IS" BASIS,
  20. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  21. * See the License for the specific language governing permissions and
  22. * limitations under the License.
  23. */
  24. function matcherHint(state, locator, matcherName, expression, actual, matcherOptions, timeout) {
  25. let header = state.utils.matcherHint(matcherName, expression, actual, matcherOptions).replace(/ \/\/ deep equality/, '') + '\n\n';
  26. if (timeout) header = _utilsBundle.colors.red(`Timed out ${timeout}ms waiting for `) + header;
  27. if (locator) header += `Locator: ${locator}\n`;
  28. return header;
  29. }
  30. class ExpectError extends Error {
  31. constructor(jestError, customMessage, stackFrames) {
  32. super('');
  33. // Copy to erase the JestMatcherError constructor name from the console.log(error).
  34. this.matcherResult = void 0;
  35. this.name = jestError.name;
  36. this.message = jestError.message;
  37. this.matcherResult = jestError.matcherResult;
  38. if (customMessage) this.message = customMessage + '\n\n' + this.message;
  39. this.stack = this.name + ': ' + this.message + '\n' + (0, _utils.stringifyStackFrames)(stackFrames).join('\n');
  40. }
  41. }
  42. exports.ExpectError = ExpectError;