matcherHint.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. "use strict";
  2. var __defProp = Object.defineProperty;
  3. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  4. var __getOwnPropNames = Object.getOwnPropertyNames;
  5. var __hasOwnProp = Object.prototype.hasOwnProperty;
  6. var __export = (target, all) => {
  7. for (var name in all)
  8. __defProp(target, name, { get: all[name], enumerable: true });
  9. };
  10. var __copyProps = (to, from, except, desc) => {
  11. if (from && typeof from === "object" || typeof from === "function") {
  12. for (let key of __getOwnPropNames(from))
  13. if (!__hasOwnProp.call(to, key) && key !== except)
  14. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  15. }
  16. return to;
  17. };
  18. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  19. var matcherHint_exports = {};
  20. __export(matcherHint_exports, {
  21. ExpectError: () => ExpectError,
  22. isJestError: () => isJestError,
  23. kNoElementsFoundError: () => kNoElementsFoundError,
  24. matcherHint: () => matcherHint
  25. });
  26. module.exports = __toCommonJS(matcherHint_exports);
  27. var import_utils = require("playwright-core/lib/utils");
  28. const kNoElementsFoundError = "<element(s) not found>";
  29. function matcherHint(state, locator, matcherName, expression, actual, matcherOptions, timeout, expectedReceivedString, preventExtraStatIndent = false) {
  30. let header = state.utils.matcherHint(matcherName, expression, actual, matcherOptions).replace(/ \/\/ deep equality/, "") + " failed\n\n";
  31. const extraSpace = preventExtraStatIndent ? "" : " ";
  32. if (locator)
  33. header += `Locator: ${extraSpace}${String(locator)}
  34. `;
  35. if (expectedReceivedString)
  36. header += `${expectedReceivedString}
  37. `;
  38. if (timeout)
  39. header += `Timeout: ${extraSpace}${timeout}ms
  40. `;
  41. return header;
  42. }
  43. class ExpectError extends Error {
  44. constructor(jestError, customMessage, stackFrames) {
  45. super("");
  46. this.name = jestError.name;
  47. this.message = jestError.message;
  48. this.matcherResult = jestError.matcherResult;
  49. if (customMessage)
  50. this.message = customMessage + "\n\n" + this.message;
  51. this.stack = this.name + ": " + this.message + "\n" + (0, import_utils.stringifyStackFrames)(stackFrames).join("\n");
  52. }
  53. }
  54. function isJestError(e) {
  55. return e instanceof Error && "matcherResult" in e;
  56. }
  57. // Annotate the CommonJS export names for ESM import in node:
  58. 0 && (module.exports = {
  59. ExpectError,
  60. isJestError,
  61. kNoElementsFoundError,
  62. matcherHint
  63. });