|
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 toHaveURL_exports = {}; |
|
20
|
__export(toHaveURL_exports, { |
|
21
|
toHaveURLWithPredicate: () => toHaveURLWithPredicate |
|
22
|
}); |
|
23
|
module.exports = __toCommonJS(toHaveURL_exports); |
|
24
|
var import_utils = require("playwright-core/lib/utils"); |
|
25
|
async function toHaveURLWithPredicate(page, expected, options) { |
|
26
|
const matcherName = "toHaveURL"; |
|
27
|
const timeout = options?.timeout ?? this.timeout; |
|
28
|
const baseURL = page.context()._options.baseURL; |
|
29
|
let conditionSucceeded = false; |
|
30
|
let lastCheckedURLString = void 0; |
|
31
|
try { |
|
32
|
await page.mainFrame().waitForURL( |
|
33
|
(url) => { |
|
34
|
lastCheckedURLString = url.toString(); |
|
35
|
if (options?.ignoreCase) { |
|
36
|
return !this.isNot === (0, import_utils.urlMatches)( |
|
37
|
baseURL?.toLocaleLowerCase(), |
|
38
|
lastCheckedURLString.toLocaleLowerCase(), |
|
39
|
expected |
|
40
|
); |
|
41
|
} |
|
42
|
return !this.isNot === (0, import_utils.urlMatches)(baseURL, lastCheckedURLString, expected); |
|
43
|
}, |
|
44
|
{ timeout } |
|
45
|
); |
|
46
|
conditionSucceeded = true; |
|
47
|
} catch (e) { |
|
48
|
conditionSucceeded = false; |
|
49
|
} |
|
50
|
if (conditionSucceeded) |
|
51
|
return { name: matcherName, pass: !this.isNot, message: () => "" }; |
|
52
|
return { |
|
53
|
name: matcherName, |
|
54
|
pass: this.isNot, |
|
55
|
message: () => toHaveURLMessage( |
|
56
|
this, |
|
57
|
matcherName, |
|
58
|
expected, |
|
59
|
lastCheckedURLString, |
|
60
|
this.isNot, |
|
61
|
true, |
|
62
|
timeout |
|
63
|
), |
|
64
|
actual: lastCheckedURLString, |
|
65
|
timeout |
|
66
|
}; |
|
67
|
} |
|
68
|
function toHaveURLMessage(state, matcherName, expected, received, pass, timedOut, timeout) { |
|
69
|
const receivedString = received || ""; |
|
70
|
let printedReceived; |
|
71
|
let printedExpected; |
|
72
|
let printedDiff; |
|
73
|
if (typeof expected === "function") { |
|
74
|
printedExpected = `Expected: predicate to ${!state.isNot ? "succeed" : "fail"}`; |
|
75
|
printedReceived = `Received: ${state.utils.printReceived(receivedString)}`; |
|
76
|
} else { |
|
77
|
if (pass) { |
|
78
|
printedExpected = `Expected pattern: not ${state.utils.printExpected(expected)}`; |
|
79
|
const formattedReceived = (0, import_utils.printReceivedStringContainExpectedResult)(state.utils, receivedString, null); |
|
80
|
printedReceived = `Received string: ${formattedReceived}`; |
|
81
|
} else { |
|
82
|
const labelExpected = `Expected ${typeof expected === "string" ? "string" : "pattern"}`; |
|
83
|
printedDiff = state.utils.printDiffOrStringify(expected, receivedString, labelExpected, "Received string", false); |
|
84
|
} |
|
85
|
} |
|
86
|
return (0, import_utils.formatMatcherMessage)(state.utils, { |
|
87
|
isNot: state.isNot, |
|
88
|
promise: state.promise, |
|
89
|
matcherName, |
|
90
|
expectation: "expected", |
|
91
|
timeout, |
|
92
|
timedOut, |
|
93
|
printedExpected, |
|
94
|
printedReceived, |
|
95
|
printedDiff |
|
96
|
}); |
|
97
|
} |
|
98
|
// Annotate the CommonJS export names for ESM import in node: |
|
99
|
0 && (module.exports = { |
|
100
|
toHaveURLWithPredicate |
|
101
|
}); |
|
102
|
|