ScuttleBot

scuttlebot / tests / e2e / node_modules / playwright / lib / matchers / toHaveURL.js
Source Blame History 101 lines
f7eb47b… lmata 1 "use strict";
f7eb47b… lmata 2 var __defProp = Object.defineProperty;
f7eb47b… lmata 3 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
f7eb47b… lmata 4 var __getOwnPropNames = Object.getOwnPropertyNames;
f7eb47b… lmata 5 var __hasOwnProp = Object.prototype.hasOwnProperty;
f7eb47b… lmata 6 var __export = (target, all) => {
f7eb47b… lmata 7 for (var name in all)
f7eb47b… lmata 8 __defProp(target, name, { get: all[name], enumerable: true });
f7eb47b… lmata 9 };
f7eb47b… lmata 10 var __copyProps = (to, from, except, desc) => {
f7eb47b… lmata 11 if (from && typeof from === "object" || typeof from === "function") {
f7eb47b… lmata 12 for (let key of __getOwnPropNames(from))
f7eb47b… lmata 13 if (!__hasOwnProp.call(to, key) && key !== except)
f7eb47b… lmata 14 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
f7eb47b… lmata 15 }
f7eb47b… lmata 16 return to;
f7eb47b… lmata 17 };
f7eb47b… lmata 18 var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
f7eb47b… lmata 19 var toHaveURL_exports = {};
f7eb47b… lmata 20 __export(toHaveURL_exports, {
f7eb47b… lmata 21 toHaveURLWithPredicate: () => toHaveURLWithPredicate
f7eb47b… lmata 22 });
f7eb47b… lmata 23 module.exports = __toCommonJS(toHaveURL_exports);
f7eb47b… lmata 24 var import_utils = require("playwright-core/lib/utils");
f7eb47b… lmata 25 async function toHaveURLWithPredicate(page, expected, options) {
f7eb47b… lmata 26 const matcherName = "toHaveURL";
f7eb47b… lmata 27 const timeout = options?.timeout ?? this.timeout;
f7eb47b… lmata 28 const baseURL = page.context()._options.baseURL;
f7eb47b… lmata 29 let conditionSucceeded = false;
f7eb47b… lmata 30 let lastCheckedURLString = void 0;
f7eb47b… lmata 31 try {
f7eb47b… lmata 32 await page.mainFrame().waitForURL(
f7eb47b… lmata 33 (url) => {
f7eb47b… lmata 34 lastCheckedURLString = url.toString();
f7eb47b… lmata 35 if (options?.ignoreCase) {
f7eb47b… lmata 36 return !this.isNot === (0, import_utils.urlMatches)(
f7eb47b… lmata 37 baseURL?.toLocaleLowerCase(),
f7eb47b… lmata 38 lastCheckedURLString.toLocaleLowerCase(),
f7eb47b… lmata 39 expected
f7eb47b… lmata 40 );
f7eb47b… lmata 41 }
f7eb47b… lmata 42 return !this.isNot === (0, import_utils.urlMatches)(baseURL, lastCheckedURLString, expected);
f7eb47b… lmata 43 },
f7eb47b… lmata 44 { timeout }
f7eb47b… lmata 45 );
f7eb47b… lmata 46 conditionSucceeded = true;
f7eb47b… lmata 47 } catch (e) {
f7eb47b… lmata 48 conditionSucceeded = false;
f7eb47b… lmata 49 }
f7eb47b… lmata 50 if (conditionSucceeded)
f7eb47b… lmata 51 return { name: matcherName, pass: !this.isNot, message: () => "" };
f7eb47b… lmata 52 return {
f7eb47b… lmata 53 name: matcherName,
f7eb47b… lmata 54 pass: this.isNot,
f7eb47b… lmata 55 message: () => toHaveURLMessage(
f7eb47b… lmata 56 this,
f7eb47b… lmata 57 matcherName,
f7eb47b… lmata 58 expected,
f7eb47b… lmata 59 lastCheckedURLString,
f7eb47b… lmata 60 this.isNot,
f7eb47b… lmata 61 true,
f7eb47b… lmata 62 timeout
f7eb47b… lmata 63 ),
f7eb47b… lmata 64 actual: lastCheckedURLString,
f7eb47b… lmata 65 timeout
f7eb47b… lmata 66 };
f7eb47b… lmata 67 }
f7eb47b… lmata 68 function toHaveURLMessage(state, matcherName, expected, received, pass, timedOut, timeout) {
f7eb47b… lmata 69 const receivedString = received || "";
f7eb47b… lmata 70 let printedReceived;
f7eb47b… lmata 71 let printedExpected;
f7eb47b… lmata 72 let printedDiff;
f7eb47b… lmata 73 if (typeof expected === "function") {
f7eb47b… lmata 74 printedExpected = `Expected: predicate to ${!state.isNot ? "succeed" : "fail"}`;
f7eb47b… lmata 75 printedReceived = `Received: ${state.utils.printReceived(receivedString)}`;
f7eb47b… lmata 76 } else {
f7eb47b… lmata 77 if (pass) {
f7eb47b… lmata 78 printedExpected = `Expected pattern: not ${state.utils.printExpected(expected)}`;
f7eb47b… lmata 79 const formattedReceived = (0, import_utils.printReceivedStringContainExpectedResult)(state.utils, receivedString, null);
f7eb47b… lmata 80 printedReceived = `Received string: ${formattedReceived}`;
f7eb47b… lmata 81 } else {
f7eb47b… lmata 82 const labelExpected = `Expected ${typeof expected === "string" ? "string" : "pattern"}`;
f7eb47b… lmata 83 printedDiff = state.utils.printDiffOrStringify(expected, receivedString, labelExpected, "Received string", false);
f7eb47b… lmata 84 }
f7eb47b… lmata 85 }
f7eb47b… lmata 86 return (0, import_utils.formatMatcherMessage)(state.utils, {
f7eb47b… lmata 87 isNot: state.isNot,
f7eb47b… lmata 88 promise: state.promise,
f7eb47b… lmata 89 matcherName,
f7eb47b… lmata 90 expectation: "expected",
f7eb47b… lmata 91 timeout,
f7eb47b… lmata 92 timedOut,
f7eb47b… lmata 93 printedExpected,
f7eb47b… lmata 94 printedReceived,
f7eb47b… lmata 95 printedDiff
f7eb47b… lmata 96 });
f7eb47b… lmata 97 }
f7eb47b… lmata 98 // Annotate the CommonJS export names for ESM import in node:
f7eb47b… lmata 99 0 && (module.exports = {
f7eb47b… lmata 100 toHaveURLWithPredicate
f7eb47b… lmata 101 });

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button