ScuttleBot

scuttlebot / tests / e2e / node_modules / playwright / lib / matchers / toMatchText.js
Blame History Raw 100 lines
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 toMatchText_exports = {};
20
__export(toMatchText_exports, {
21
toMatchText: () => toMatchText
22
});
23
module.exports = __toCommonJS(toMatchText_exports);
24
var import_utils = require("playwright-core/lib/utils");
25
var import_util = require("../util");
26
async function toMatchText(matcherName, receiver, receiverType, query, expected, options = {}) {
27
(0, import_util.expectTypes)(receiver, [receiverType], matcherName);
28
const locator = receiverType === "Locator" ? receiver : void 0;
29
if (!(typeof expected === "string") && !(expected && typeof expected.test === "function")) {
30
const errorMessage2 = `Error: ${this.utils.EXPECTED_COLOR("expected")} value must be a string or regular expression
31
${this.utils.printWithType("Expected", expected, this.utils.printExpected)}`;
32
throw new Error((0, import_utils.formatMatcherMessage)(this.utils, { promise: this.promise, isNot: this.isNot, locator: locator?.toString(), matcherName, expectation: "expected", errorMessage: errorMessage2 }));
33
}
34
const timeout = options.timeout ?? this.timeout;
35
const { matches: pass, received, log, timedOut, errorMessage } = await query(!!this.isNot, timeout);
36
if (pass === !this.isNot) {
37
return {
38
name: matcherName,
39
message: () => "",
40
pass,
41
expected
42
};
43
}
44
const expectedSuffix = typeof expected === "string" ? options.matchSubstring ? " substring" : "" : " pattern";
45
const receivedSuffix = typeof expected === "string" ? options.matchSubstring ? " string" : "" : " string";
46
const receivedString = received || "";
47
let printedReceived;
48
let printedExpected;
49
let printedDiff;
50
if (pass) {
51
if (typeof expected === "string") {
52
printedExpected = `Expected${expectedSuffix}: not ${this.utils.printExpected(expected)}`;
53
if (!errorMessage) {
54
const formattedReceived = (0, import_utils.printReceivedStringContainExpectedSubstring)(this.utils, receivedString, receivedString.indexOf(expected), expected.length);
55
printedReceived = `Received${receivedSuffix}: ${formattedReceived}`;
56
}
57
} else {
58
printedExpected = `Expected${expectedSuffix}: not ${this.utils.printExpected(expected)}`;
59
if (!errorMessage) {
60
const formattedReceived = (0, import_utils.printReceivedStringContainExpectedResult)(this.utils, receivedString, typeof expected.exec === "function" ? expected.exec(receivedString) : null);
61
printedReceived = `Received${receivedSuffix}: ${formattedReceived}`;
62
}
63
}
64
} else {
65
if (errorMessage)
66
printedExpected = `Expected${expectedSuffix}: ${this.utils.printExpected(expected)}`;
67
else
68
printedDiff = this.utils.printDiffOrStringify(expected, receivedString, `Expected${expectedSuffix}`, `Received${receivedSuffix}`, false);
69
}
70
const message = () => {
71
return (0, import_utils.formatMatcherMessage)(this.utils, {
72
promise: this.promise,
73
isNot: this.isNot,
74
matcherName,
75
expectation: "expected",
76
locator: locator?.toString(),
77
timeout,
78
timedOut,
79
printedExpected,
80
printedReceived,
81
printedDiff,
82
log,
83
errorMessage
84
});
85
};
86
return {
87
name: matcherName,
88
expected,
89
message,
90
pass,
91
actual: received,
92
log,
93
timeout: timedOut ? timeout : void 0
94
};
95
}
96
// Annotate the CommonJS export names for ESM import in node:
97
0 && (module.exports = {
98
toMatchText
99
});
100

Keyboard Shortcuts

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