@ohos-ports/playwright 1.54.2-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +168 -0
- package/ThirdPartyNotices.txt +3984 -0
- package/cli.js +19 -0
- package/index.d.ts +17 -0
- package/index.js +17 -0
- package/index.mjs +18 -0
- package/jsx-runtime.js +42 -0
- package/jsx-runtime.mjs +21 -0
- package/lib/common/config.js +272 -0
- package/lib/common/configLoader.js +343 -0
- package/lib/common/esmLoaderHost.js +102 -0
- package/lib/common/expectBundle.js +49 -0
- package/lib/common/expectBundleImpl.js +389 -0
- package/lib/common/fixtures.js +302 -0
- package/lib/common/globals.js +58 -0
- package/lib/common/ipc.js +60 -0
- package/lib/common/poolBuilder.js +85 -0
- package/lib/common/process.js +104 -0
- package/lib/common/suiteUtils.js +149 -0
- package/lib/common/test.js +321 -0
- package/lib/common/testLoader.js +100 -0
- package/lib/common/testType.js +307 -0
- package/lib/fsWatcher.js +67 -0
- package/lib/index.js +670 -0
- package/lib/internalsForTest.js +42 -0
- package/lib/isomorphic/events.js +77 -0
- package/lib/isomorphic/folders.js +30 -0
- package/lib/isomorphic/stringInternPool.js +69 -0
- package/lib/isomorphic/teleReceiver.js +507 -0
- package/lib/isomorphic/teleSuiteUpdater.js +137 -0
- package/lib/isomorphic/testServerConnection.js +211 -0
- package/lib/isomorphic/testServerInterface.js +16 -0
- package/lib/isomorphic/testTree.js +307 -0
- package/lib/isomorphic/types.d.js +16 -0
- package/lib/loader/loaderMain.js +59 -0
- package/lib/matchers/expect.js +326 -0
- package/lib/matchers/matcherHint.js +59 -0
- package/lib/matchers/matchers.js +360 -0
- package/lib/matchers/toBeTruthy.js +71 -0
- package/lib/matchers/toEqual.js +94 -0
- package/lib/matchers/toHaveURL.js +117 -0
- package/lib/matchers/toMatchAriaSnapshot.js +164 -0
- package/lib/matchers/toMatchSnapshot.js +338 -0
- package/lib/matchers/toMatchText.js +105 -0
- package/lib/plugins/gitCommitInfoPlugin.js +198 -0
- package/lib/plugins/index.js +28 -0
- package/lib/plugins/webServerPlugin.js +207 -0
- package/lib/program.js +392 -0
- package/lib/reporters/base.js +604 -0
- package/lib/reporters/blob.js +135 -0
- package/lib/reporters/dot.js +82 -0
- package/lib/reporters/empty.js +32 -0
- package/lib/reporters/github.js +127 -0
- package/lib/reporters/html.js +627 -0
- package/lib/reporters/internalReporter.js +129 -0
- package/lib/reporters/json.js +254 -0
- package/lib/reporters/junit.js +230 -0
- package/lib/reporters/line.js +113 -0
- package/lib/reporters/list.js +230 -0
- package/lib/reporters/markdown.js +144 -0
- package/lib/reporters/merge.js +533 -0
- package/lib/reporters/multiplexer.js +104 -0
- package/lib/reporters/reporterV2.js +102 -0
- package/lib/reporters/teleEmitter.js +295 -0
- package/lib/reporters/versions/blobV1.js +16 -0
- package/lib/runner/dispatcher.js +484 -0
- package/lib/runner/failureTracker.js +62 -0
- package/lib/runner/lastRun.js +74 -0
- package/lib/runner/loadUtils.js +299 -0
- package/lib/runner/loaderHost.js +89 -0
- package/lib/runner/processHost.js +161 -0
- package/lib/runner/projectUtils.js +235 -0
- package/lib/runner/rebase.js +189 -0
- package/lib/runner/reporters.js +162 -0
- package/lib/runner/runner.js +110 -0
- package/lib/runner/sigIntWatcher.js +96 -0
- package/lib/runner/taskRunner.js +127 -0
- package/lib/runner/tasks.js +400 -0
- package/lib/runner/testGroups.js +117 -0
- package/lib/runner/testServer.js +483 -0
- package/lib/runner/uiModeReporter.js +30 -0
- package/lib/runner/vcs.js +72 -0
- package/lib/runner/watchMode.js +391 -0
- package/lib/runner/workerHost.js +93 -0
- package/lib/third_party/pirates.js +62 -0
- package/lib/third_party/tsconfig-loader.js +103 -0
- package/lib/transform/babelBundle.js +43 -0
- package/lib/transform/babelBundleImpl.js +477 -0
- package/lib/transform/compilationCache.js +255 -0
- package/lib/transform/esmLoader.js +104 -0
- package/lib/transform/portTransport.js +67 -0
- package/lib/transform/transform.js +293 -0
- package/lib/util.js +426 -0
- package/lib/utilsBundle.js +43 -0
- package/lib/utilsBundleImpl.js +100 -0
- package/lib/worker/fixtureRunner.js +253 -0
- package/lib/worker/testInfo.js +474 -0
- package/lib/worker/testTracing.js +343 -0
- package/lib/worker/timeoutManager.js +174 -0
- package/lib/worker/util.js +31 -0
- package/lib/worker/workerMain.js +511 -0
- package/package.json +64 -0
- package/test.d.ts +18 -0
- package/test.js +24 -0
- package/test.mjs +33 -0
- package/types/test.d.ts +10141 -0
- package/types/testReporter.d.ts +816 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var toMatchAriaSnapshot_exports = {};
|
|
30
|
+
__export(toMatchAriaSnapshot_exports, {
|
|
31
|
+
toMatchAriaSnapshot: () => toMatchAriaSnapshot
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(toMatchAriaSnapshot_exports);
|
|
34
|
+
var import_fs = __toESM(require("fs"));
|
|
35
|
+
var import_path = __toESM(require("path"));
|
|
36
|
+
var import_utils = require("@ohos-ports/playwright-core/lib/utils");
|
|
37
|
+
var import_matcherHint = require("./matcherHint");
|
|
38
|
+
var import_expectBundle = require("../common/expectBundle");
|
|
39
|
+
var import_util = require("../util");
|
|
40
|
+
var import_expect = require("./expect");
|
|
41
|
+
var import_globals = require("../common/globals");
|
|
42
|
+
async function toMatchAriaSnapshot(receiver, expectedParam, options = {}) {
|
|
43
|
+
const matcherName = "toMatchAriaSnapshot";
|
|
44
|
+
const testInfo = (0, import_globals.currentTestInfo)();
|
|
45
|
+
if (!testInfo)
|
|
46
|
+
throw new Error(`toMatchAriaSnapshot() must be called during the test`);
|
|
47
|
+
if (testInfo._projectInternal.ignoreSnapshots)
|
|
48
|
+
return { pass: !this.isNot, message: () => "", name: "toMatchAriaSnapshot", expected: "" };
|
|
49
|
+
const updateSnapshots = testInfo.config.updateSnapshots;
|
|
50
|
+
const matcherOptions = {
|
|
51
|
+
isNot: this.isNot,
|
|
52
|
+
promise: this.promise
|
|
53
|
+
};
|
|
54
|
+
let expected;
|
|
55
|
+
let timeout;
|
|
56
|
+
let expectedPath;
|
|
57
|
+
if ((0, import_utils.isString)(expectedParam)) {
|
|
58
|
+
expected = expectedParam;
|
|
59
|
+
timeout = options.timeout ?? this.timeout;
|
|
60
|
+
} else {
|
|
61
|
+
const legacyPath = testInfo._resolveSnapshotPaths("aria", expectedParam?.name, "dontUpdateSnapshotIndex", ".yml").absoluteSnapshotPath;
|
|
62
|
+
expectedPath = testInfo._resolveSnapshotPaths("aria", expectedParam?.name, "updateSnapshotIndex").absoluteSnapshotPath;
|
|
63
|
+
if (!await (0, import_util.fileExistsAsync)(expectedPath) && await (0, import_util.fileExistsAsync)(legacyPath))
|
|
64
|
+
expectedPath = legacyPath;
|
|
65
|
+
expected = await import_fs.default.promises.readFile(expectedPath, "utf8").catch(() => "");
|
|
66
|
+
timeout = expectedParam?.timeout ?? this.timeout;
|
|
67
|
+
}
|
|
68
|
+
const generateMissingBaseline = updateSnapshots === "missing" && !expected;
|
|
69
|
+
if (generateMissingBaseline) {
|
|
70
|
+
if (this.isNot) {
|
|
71
|
+
const message2 = `Matchers using ".not" can't generate new baselines`;
|
|
72
|
+
return { pass: this.isNot, message: () => message2, name: "toMatchAriaSnapshot" };
|
|
73
|
+
} else {
|
|
74
|
+
expected = `- none "Generating new baseline"`;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
expected = unshift(expected);
|
|
78
|
+
const { matches: pass, received, log, timedOut } = await receiver._expect("to.match.aria", { expectedValue: expected, isNot: this.isNot, timeout });
|
|
79
|
+
const typedReceived = received;
|
|
80
|
+
const messagePrefix = (0, import_matcherHint.matcherHint)(this, receiver, matcherName, "locator", void 0, matcherOptions, timedOut ? timeout : void 0);
|
|
81
|
+
const notFound = typedReceived === import_matcherHint.kNoElementsFoundError;
|
|
82
|
+
if (notFound) {
|
|
83
|
+
return {
|
|
84
|
+
pass: this.isNot,
|
|
85
|
+
message: () => messagePrefix + `Expected: ${this.utils.printExpected(expected)}
|
|
86
|
+
Received: ${(0, import_expectBundle.EXPECTED_COLOR)("<element not found>")}` + (0, import_util.callLogText)(log),
|
|
87
|
+
name: "toMatchAriaSnapshot",
|
|
88
|
+
expected
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
const receivedText = typedReceived.raw;
|
|
92
|
+
const message = () => {
|
|
93
|
+
if (pass) {
|
|
94
|
+
if (notFound)
|
|
95
|
+
return messagePrefix + `Expected: not ${this.utils.printExpected(expected)}
|
|
96
|
+
Received: ${receivedText}` + (0, import_util.callLogText)(log);
|
|
97
|
+
const printedReceived = (0, import_expect.printReceivedStringContainExpectedSubstring)(receivedText, receivedText.indexOf(expected), expected.length);
|
|
98
|
+
return messagePrefix + `Expected: not ${this.utils.printExpected(expected)}
|
|
99
|
+
Received: ${printedReceived}` + (0, import_util.callLogText)(log);
|
|
100
|
+
} else {
|
|
101
|
+
const labelExpected = `Expected`;
|
|
102
|
+
if (notFound)
|
|
103
|
+
return messagePrefix + `${labelExpected}: ${this.utils.printExpected(expected)}
|
|
104
|
+
Received: ${receivedText}` + (0, import_util.callLogText)(log);
|
|
105
|
+
return messagePrefix + this.utils.printDiffOrStringify(expected, receivedText, labelExpected, "Received", false) + (0, import_util.callLogText)(log);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
if (!this.isNot) {
|
|
109
|
+
if (updateSnapshots === "all" || updateSnapshots === "changed" && pass === this.isNot || generateMissingBaseline) {
|
|
110
|
+
if (expectedPath) {
|
|
111
|
+
await import_fs.default.promises.mkdir(import_path.default.dirname(expectedPath), { recursive: true });
|
|
112
|
+
await import_fs.default.promises.writeFile(expectedPath, typedReceived.regex, "utf8");
|
|
113
|
+
const relativePath = import_path.default.relative(process.cwd(), expectedPath);
|
|
114
|
+
if (updateSnapshots === "missing") {
|
|
115
|
+
const message2 = `A snapshot doesn't exist at ${relativePath}, writing actual.`;
|
|
116
|
+
testInfo._hasNonRetriableError = true;
|
|
117
|
+
testInfo._failWithError(new Error(message2));
|
|
118
|
+
} else {
|
|
119
|
+
const message2 = `A snapshot is generated at ${relativePath}.`;
|
|
120
|
+
console.log(message2);
|
|
121
|
+
}
|
|
122
|
+
return { pass: true, message: () => "", name: "toMatchAriaSnapshot" };
|
|
123
|
+
} else {
|
|
124
|
+
const suggestedRebaseline = `\`
|
|
125
|
+
${(0, import_utils.escapeTemplateString)(indent(typedReceived.regex, "{indent} "))}
|
|
126
|
+
{indent}\``;
|
|
127
|
+
if (updateSnapshots === "missing") {
|
|
128
|
+
const message2 = "A snapshot is not provided, generating new baseline.";
|
|
129
|
+
testInfo._hasNonRetriableError = true;
|
|
130
|
+
testInfo._failWithError(new Error(message2));
|
|
131
|
+
}
|
|
132
|
+
return { pass: false, message: () => "", name: "toMatchAriaSnapshot", suggestedRebaseline };
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
name: matcherName,
|
|
138
|
+
expected,
|
|
139
|
+
message,
|
|
140
|
+
pass,
|
|
141
|
+
actual: received,
|
|
142
|
+
log,
|
|
143
|
+
timeout: timedOut ? timeout : void 0
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function unshift(snapshot) {
|
|
147
|
+
const lines = snapshot.split("\n");
|
|
148
|
+
let whitespacePrefixLength = 100;
|
|
149
|
+
for (const line of lines) {
|
|
150
|
+
if (!line.trim())
|
|
151
|
+
continue;
|
|
152
|
+
const match = line.match(/^(\s*)/);
|
|
153
|
+
if (match && match[1].length < whitespacePrefixLength)
|
|
154
|
+
whitespacePrefixLength = match[1].length;
|
|
155
|
+
}
|
|
156
|
+
return lines.filter((t) => t.trim()).map((line) => line.substring(whitespacePrefixLength)).join("\n");
|
|
157
|
+
}
|
|
158
|
+
function indent(snapshot, indent2) {
|
|
159
|
+
return snapshot.split("\n").map((line) => indent2 + line).join("\n");
|
|
160
|
+
}
|
|
161
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
162
|
+
0 && (module.exports = {
|
|
163
|
+
toMatchAriaSnapshot
|
|
164
|
+
});
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var toMatchSnapshot_exports = {};
|
|
30
|
+
__export(toMatchSnapshot_exports, {
|
|
31
|
+
toHaveScreenshot: () => toHaveScreenshot,
|
|
32
|
+
toHaveScreenshotStepTitle: () => toHaveScreenshotStepTitle,
|
|
33
|
+
toMatchSnapshot: () => toMatchSnapshot
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(toMatchSnapshot_exports);
|
|
36
|
+
var import_fs = __toESM(require("fs"));
|
|
37
|
+
var import_path = __toESM(require("path"));
|
|
38
|
+
var import_utils = require("@ohos-ports/playwright-core/lib/utils");
|
|
39
|
+
var import_utils2 = require("@ohos-ports/playwright-core/lib/utils");
|
|
40
|
+
var import_utilsBundle = require("@ohos-ports/playwright-core/lib/utilsBundle");
|
|
41
|
+
var import_util = require("../util");
|
|
42
|
+
var import_matcherHint = require("./matcherHint");
|
|
43
|
+
var import_globals = require("../common/globals");
|
|
44
|
+
const NonConfigProperties = [
|
|
45
|
+
"clip",
|
|
46
|
+
"fullPage",
|
|
47
|
+
"mask",
|
|
48
|
+
"maskColor",
|
|
49
|
+
"omitBackground",
|
|
50
|
+
"timeout"
|
|
51
|
+
];
|
|
52
|
+
class SnapshotHelper {
|
|
53
|
+
constructor(testInfo, matcherName, locator, anonymousSnapshotExtension, configOptions, nameOrOptions, optOptions) {
|
|
54
|
+
let name;
|
|
55
|
+
if (Array.isArray(nameOrOptions) || typeof nameOrOptions === "string") {
|
|
56
|
+
name = nameOrOptions;
|
|
57
|
+
this.options = { ...optOptions };
|
|
58
|
+
} else {
|
|
59
|
+
const { name: nameFromOptions, ...options } = nameOrOptions;
|
|
60
|
+
this.options = options;
|
|
61
|
+
name = nameFromOptions;
|
|
62
|
+
}
|
|
63
|
+
this.name = Array.isArray(name) ? name.join(import_path.default.sep) : name || "";
|
|
64
|
+
const resolvedPaths = testInfo._resolveSnapshotPaths(matcherName === "toHaveScreenshot" ? "screenshot" : "snapshot", name, "updateSnapshotIndex", anonymousSnapshotExtension);
|
|
65
|
+
this.expectedPath = resolvedPaths.absoluteSnapshotPath;
|
|
66
|
+
this.attachmentBaseName = resolvedPaths.relativeOutputPath;
|
|
67
|
+
const outputBasePath = testInfo._getOutputPath(resolvedPaths.relativeOutputPath);
|
|
68
|
+
this.legacyExpectedPath = (0, import_util.addSuffixToFilePath)(outputBasePath, "-expected");
|
|
69
|
+
this.previousPath = (0, import_util.addSuffixToFilePath)(outputBasePath, "-previous");
|
|
70
|
+
this.actualPath = (0, import_util.addSuffixToFilePath)(outputBasePath, "-actual");
|
|
71
|
+
this.diffPath = (0, import_util.addSuffixToFilePath)(outputBasePath, "-diff");
|
|
72
|
+
const filteredConfigOptions = { ...configOptions };
|
|
73
|
+
for (const prop of NonConfigProperties)
|
|
74
|
+
delete filteredConfigOptions[prop];
|
|
75
|
+
this.options = {
|
|
76
|
+
...filteredConfigOptions,
|
|
77
|
+
...this.options
|
|
78
|
+
};
|
|
79
|
+
if (this.options._comparator) {
|
|
80
|
+
this.options.comparator = this.options._comparator;
|
|
81
|
+
delete this.options._comparator;
|
|
82
|
+
}
|
|
83
|
+
if (this.options.maxDiffPixels !== void 0 && this.options.maxDiffPixels < 0)
|
|
84
|
+
throw new Error("`maxDiffPixels` option value must be non-negative integer");
|
|
85
|
+
if (this.options.maxDiffPixelRatio !== void 0 && (this.options.maxDiffPixelRatio < 0 || this.options.maxDiffPixelRatio > 1))
|
|
86
|
+
throw new Error("`maxDiffPixelRatio` option value must be between 0 and 1");
|
|
87
|
+
this.matcherName = matcherName;
|
|
88
|
+
this.locator = locator;
|
|
89
|
+
this.updateSnapshots = testInfo.config.updateSnapshots;
|
|
90
|
+
this.mimeType = import_utilsBundle.mime.getType(import_path.default.basename(this.expectedPath)) ?? "application/octet-stream";
|
|
91
|
+
this.comparator = (0, import_utils.getComparator)(this.mimeType);
|
|
92
|
+
this.testInfo = testInfo;
|
|
93
|
+
this.kind = this.mimeType.startsWith("image/") ? "Screenshot" : "Snapshot";
|
|
94
|
+
}
|
|
95
|
+
createMatcherResult(message, pass, log) {
|
|
96
|
+
const unfiltered = {
|
|
97
|
+
name: this.matcherName,
|
|
98
|
+
expected: this.expectedPath,
|
|
99
|
+
actual: this.actualPath,
|
|
100
|
+
diff: this.diffPath,
|
|
101
|
+
pass,
|
|
102
|
+
message: () => message,
|
|
103
|
+
log
|
|
104
|
+
};
|
|
105
|
+
return Object.fromEntries(Object.entries(unfiltered).filter(([_, v]) => v !== void 0));
|
|
106
|
+
}
|
|
107
|
+
handleMissingNegated() {
|
|
108
|
+
const isWriteMissingMode = this.updateSnapshots !== "none";
|
|
109
|
+
const message = `A snapshot doesn't exist at ${this.expectedPath}${isWriteMissingMode ? `, matchers using ".not" won't write them automatically.` : "."}`;
|
|
110
|
+
return this.createMatcherResult(message, true);
|
|
111
|
+
}
|
|
112
|
+
handleDifferentNegated() {
|
|
113
|
+
return this.createMatcherResult("", false);
|
|
114
|
+
}
|
|
115
|
+
handleMatchingNegated() {
|
|
116
|
+
const message = [
|
|
117
|
+
import_utils2.colors.red(`${this.kind} comparison failed:`),
|
|
118
|
+
"",
|
|
119
|
+
indent("Expected result should be different from the actual one.", " ")
|
|
120
|
+
].join("\n");
|
|
121
|
+
return this.createMatcherResult(message, true);
|
|
122
|
+
}
|
|
123
|
+
handleMissing(actual, step) {
|
|
124
|
+
const isWriteMissingMode = this.updateSnapshots !== "none";
|
|
125
|
+
if (isWriteMissingMode)
|
|
126
|
+
writeFileSync(this.expectedPath, actual);
|
|
127
|
+
step?._attachToStep({ name: (0, import_util.addSuffixToFilePath)(this.attachmentBaseName, "-expected"), contentType: this.mimeType, path: this.expectedPath });
|
|
128
|
+
writeFileSync(this.actualPath, actual);
|
|
129
|
+
step?._attachToStep({ name: (0, import_util.addSuffixToFilePath)(this.attachmentBaseName, "-actual"), contentType: this.mimeType, path: this.actualPath });
|
|
130
|
+
const message = `A snapshot doesn't exist at ${this.expectedPath}${isWriteMissingMode ? ", writing actual." : "."}`;
|
|
131
|
+
if (this.updateSnapshots === "all" || this.updateSnapshots === "changed") {
|
|
132
|
+
console.log(message);
|
|
133
|
+
return this.createMatcherResult(message, true);
|
|
134
|
+
}
|
|
135
|
+
if (this.updateSnapshots === "missing") {
|
|
136
|
+
this.testInfo._hasNonRetriableError = true;
|
|
137
|
+
this.testInfo._failWithError(new Error(message));
|
|
138
|
+
return this.createMatcherResult("", true);
|
|
139
|
+
}
|
|
140
|
+
return this.createMatcherResult(message, false);
|
|
141
|
+
}
|
|
142
|
+
handleDifferent(actual, expected, previous, diff, header, diffError, log, step) {
|
|
143
|
+
const output = [`${header}${indent(diffError, " ")}`];
|
|
144
|
+
if (this.name) {
|
|
145
|
+
output.push("");
|
|
146
|
+
output.push(` Snapshot: ${this.name}`);
|
|
147
|
+
}
|
|
148
|
+
if (expected !== void 0) {
|
|
149
|
+
writeFileSync(this.legacyExpectedPath, expected);
|
|
150
|
+
step?._attachToStep({ name: (0, import_util.addSuffixToFilePath)(this.attachmentBaseName, "-expected"), contentType: this.mimeType, path: this.expectedPath });
|
|
151
|
+
}
|
|
152
|
+
if (previous !== void 0) {
|
|
153
|
+
writeFileSync(this.previousPath, previous);
|
|
154
|
+
step?._attachToStep({ name: (0, import_util.addSuffixToFilePath)(this.attachmentBaseName, "-previous"), contentType: this.mimeType, path: this.previousPath });
|
|
155
|
+
}
|
|
156
|
+
if (actual !== void 0) {
|
|
157
|
+
writeFileSync(this.actualPath, actual);
|
|
158
|
+
step?._attachToStep({ name: (0, import_util.addSuffixToFilePath)(this.attachmentBaseName, "-actual"), contentType: this.mimeType, path: this.actualPath });
|
|
159
|
+
}
|
|
160
|
+
if (diff !== void 0) {
|
|
161
|
+
writeFileSync(this.diffPath, diff);
|
|
162
|
+
step?._attachToStep({ name: (0, import_util.addSuffixToFilePath)(this.attachmentBaseName, "-diff"), contentType: this.mimeType, path: this.diffPath });
|
|
163
|
+
}
|
|
164
|
+
if (log?.length)
|
|
165
|
+
output.push((0, import_util.callLogText)(log));
|
|
166
|
+
else
|
|
167
|
+
output.push("");
|
|
168
|
+
return this.createMatcherResult(output.join("\n"), false, log);
|
|
169
|
+
}
|
|
170
|
+
handleMatching() {
|
|
171
|
+
return this.createMatcherResult("", true);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function toMatchSnapshot(received, nameOrOptions = {}, optOptions = {}) {
|
|
175
|
+
const testInfo = (0, import_globals.currentTestInfo)();
|
|
176
|
+
if (!testInfo)
|
|
177
|
+
throw new Error(`toMatchSnapshot() must be called during the test`);
|
|
178
|
+
if (received instanceof Promise)
|
|
179
|
+
throw new Error("An unresolved Promise was passed to toMatchSnapshot(), make sure to resolve it by adding await to it.");
|
|
180
|
+
if (testInfo._projectInternal.ignoreSnapshots)
|
|
181
|
+
return { pass: !this.isNot, message: () => "", name: "toMatchSnapshot", expected: nameOrOptions };
|
|
182
|
+
const configOptions = testInfo._projectInternal.expect?.toMatchSnapshot || {};
|
|
183
|
+
const helper = new SnapshotHelper(
|
|
184
|
+
testInfo,
|
|
185
|
+
"toMatchSnapshot",
|
|
186
|
+
void 0,
|
|
187
|
+
"." + determineFileExtension(received),
|
|
188
|
+
configOptions,
|
|
189
|
+
nameOrOptions,
|
|
190
|
+
optOptions
|
|
191
|
+
);
|
|
192
|
+
if (this.isNot) {
|
|
193
|
+
if (!import_fs.default.existsSync(helper.expectedPath))
|
|
194
|
+
return helper.handleMissingNegated();
|
|
195
|
+
const isDifferent = !!helper.comparator(received, import_fs.default.readFileSync(helper.expectedPath), helper.options);
|
|
196
|
+
return isDifferent ? helper.handleDifferentNegated() : helper.handleMatchingNegated();
|
|
197
|
+
}
|
|
198
|
+
if (!import_fs.default.existsSync(helper.expectedPath))
|
|
199
|
+
return helper.handleMissing(received, this._stepInfo);
|
|
200
|
+
const expected = import_fs.default.readFileSync(helper.expectedPath);
|
|
201
|
+
if (helper.updateSnapshots === "all") {
|
|
202
|
+
if (!(0, import_utils.compareBuffersOrStrings)(received, expected))
|
|
203
|
+
return helper.handleMatching();
|
|
204
|
+
writeFileSync(helper.expectedPath, received);
|
|
205
|
+
console.log(helper.expectedPath + " is not the same, writing actual.");
|
|
206
|
+
return helper.createMatcherResult(helper.expectedPath + " running with --update-snapshots, writing actual.", true);
|
|
207
|
+
}
|
|
208
|
+
if (helper.updateSnapshots === "changed") {
|
|
209
|
+
const result2 = helper.comparator(received, expected, helper.options);
|
|
210
|
+
if (!result2)
|
|
211
|
+
return helper.handleMatching();
|
|
212
|
+
writeFileSync(helper.expectedPath, received);
|
|
213
|
+
console.log(helper.expectedPath + " does not match, writing actual.");
|
|
214
|
+
return helper.createMatcherResult(helper.expectedPath + " running with --update-snapshots, writing actual.", true);
|
|
215
|
+
}
|
|
216
|
+
const result = helper.comparator(received, expected, helper.options);
|
|
217
|
+
if (!result)
|
|
218
|
+
return helper.handleMatching();
|
|
219
|
+
const receiver = (0, import_utils.isString)(received) ? "string" : "Buffer";
|
|
220
|
+
const header = (0, import_matcherHint.matcherHint)(this, void 0, "toMatchSnapshot", receiver, void 0, void 0);
|
|
221
|
+
return helper.handleDifferent(received, expected, void 0, result.diff, header, result.errorMessage, void 0, this._stepInfo);
|
|
222
|
+
}
|
|
223
|
+
function toHaveScreenshotStepTitle(nameOrOptions = {}, optOptions = {}) {
|
|
224
|
+
let name;
|
|
225
|
+
if (typeof nameOrOptions === "object" && !Array.isArray(nameOrOptions))
|
|
226
|
+
name = nameOrOptions.name;
|
|
227
|
+
else
|
|
228
|
+
name = nameOrOptions;
|
|
229
|
+
return Array.isArray(name) ? name.join(import_path.default.sep) : name || "";
|
|
230
|
+
}
|
|
231
|
+
async function toHaveScreenshot(pageOrLocator, nameOrOptions = {}, optOptions = {}) {
|
|
232
|
+
const testInfo = (0, import_globals.currentTestInfo)();
|
|
233
|
+
if (!testInfo)
|
|
234
|
+
throw new Error(`toHaveScreenshot() must be called during the test`);
|
|
235
|
+
if (testInfo._projectInternal.ignoreSnapshots)
|
|
236
|
+
return { pass: !this.isNot, message: () => "", name: "toHaveScreenshot", expected: nameOrOptions };
|
|
237
|
+
(0, import_util.expectTypes)(pageOrLocator, ["Page", "Locator"], "toHaveScreenshot");
|
|
238
|
+
const [page, locator] = pageOrLocator.constructor.name === "Page" ? [pageOrLocator, void 0] : [pageOrLocator.page(), pageOrLocator];
|
|
239
|
+
const configOptions = testInfo._projectInternal.expect?.toHaveScreenshot || {};
|
|
240
|
+
const helper = new SnapshotHelper(testInfo, "toHaveScreenshot", locator, void 0, configOptions, nameOrOptions, optOptions);
|
|
241
|
+
if (!helper.expectedPath.toLowerCase().endsWith(".png"))
|
|
242
|
+
throw new Error(`Screenshot name "${import_path.default.basename(helper.expectedPath)}" must have '.png' extension`);
|
|
243
|
+
(0, import_util.expectTypes)(pageOrLocator, ["Page", "Locator"], "toHaveScreenshot");
|
|
244
|
+
const style = await loadScreenshotStyles(helper.options.stylePath);
|
|
245
|
+
const timeout = helper.options.timeout ?? this.timeout;
|
|
246
|
+
const expectScreenshotOptions = {
|
|
247
|
+
locator,
|
|
248
|
+
animations: helper.options.animations ?? "disabled",
|
|
249
|
+
caret: helper.options.caret ?? "hide",
|
|
250
|
+
clip: helper.options.clip,
|
|
251
|
+
fullPage: helper.options.fullPage,
|
|
252
|
+
mask: helper.options.mask,
|
|
253
|
+
maskColor: helper.options.maskColor,
|
|
254
|
+
omitBackground: helper.options.omitBackground,
|
|
255
|
+
scale: helper.options.scale ?? "css",
|
|
256
|
+
style,
|
|
257
|
+
isNot: !!this.isNot,
|
|
258
|
+
timeout,
|
|
259
|
+
comparator: helper.options.comparator,
|
|
260
|
+
maxDiffPixels: helper.options.maxDiffPixels,
|
|
261
|
+
maxDiffPixelRatio: helper.options.maxDiffPixelRatio,
|
|
262
|
+
threshold: helper.options.threshold
|
|
263
|
+
};
|
|
264
|
+
const hasSnapshot = import_fs.default.existsSync(helper.expectedPath);
|
|
265
|
+
if (this.isNot) {
|
|
266
|
+
if (!hasSnapshot)
|
|
267
|
+
return helper.handleMissingNegated();
|
|
268
|
+
expectScreenshotOptions.expected = await import_fs.default.promises.readFile(helper.expectedPath);
|
|
269
|
+
const isDifferent = !(await page._expectScreenshot(expectScreenshotOptions)).errorMessage;
|
|
270
|
+
return isDifferent ? helper.handleDifferentNegated() : helper.handleMatchingNegated();
|
|
271
|
+
}
|
|
272
|
+
if (helper.updateSnapshots === "none" && !hasSnapshot)
|
|
273
|
+
return helper.createMatcherResult(`A snapshot doesn't exist at ${helper.expectedPath}.`, false);
|
|
274
|
+
const receiver = locator ? "locator" : "page";
|
|
275
|
+
if (!hasSnapshot) {
|
|
276
|
+
const { actual: actual2, previous: previous2, diff: diff2, errorMessage: errorMessage2, log: log2, timedOut: timedOut2 } = await page._expectScreenshot(expectScreenshotOptions);
|
|
277
|
+
if (errorMessage2) {
|
|
278
|
+
const header2 = (0, import_matcherHint.matcherHint)(this, locator, "toHaveScreenshot", receiver, void 0, void 0, timedOut2 ? timeout : void 0);
|
|
279
|
+
return helper.handleDifferent(actual2, void 0, previous2, diff2, header2, errorMessage2, log2, this._stepInfo);
|
|
280
|
+
}
|
|
281
|
+
return helper.handleMissing(actual2, this._stepInfo);
|
|
282
|
+
}
|
|
283
|
+
const expected = await import_fs.default.promises.readFile(helper.expectedPath);
|
|
284
|
+
expectScreenshotOptions.expected = helper.updateSnapshots === "all" ? void 0 : expected;
|
|
285
|
+
const { actual, previous, diff, errorMessage, log, timedOut } = await page._expectScreenshot(expectScreenshotOptions);
|
|
286
|
+
const writeFiles = () => {
|
|
287
|
+
writeFileSync(helper.expectedPath, actual);
|
|
288
|
+
writeFileSync(helper.actualPath, actual);
|
|
289
|
+
console.log(helper.expectedPath + " is re-generated, writing actual.");
|
|
290
|
+
return helper.createMatcherResult(helper.expectedPath + " running with --update-snapshots, writing actual.", true);
|
|
291
|
+
};
|
|
292
|
+
if (!errorMessage) {
|
|
293
|
+
if (helper.updateSnapshots === "all" && actual && (0, import_utils.compareBuffersOrStrings)(actual, expected)) {
|
|
294
|
+
console.log(helper.expectedPath + " is re-generated, writing actual.");
|
|
295
|
+
return writeFiles();
|
|
296
|
+
}
|
|
297
|
+
return helper.handleMatching();
|
|
298
|
+
}
|
|
299
|
+
if (helper.updateSnapshots === "changed" || helper.updateSnapshots === "all")
|
|
300
|
+
return writeFiles();
|
|
301
|
+
const header = (0, import_matcherHint.matcherHint)(this, void 0, "toHaveScreenshot", receiver, void 0, void 0, timedOut ? timeout : void 0);
|
|
302
|
+
return helper.handleDifferent(actual, expectScreenshotOptions.expected, previous, diff, header, errorMessage, log, this._stepInfo);
|
|
303
|
+
}
|
|
304
|
+
function writeFileSync(aPath, content) {
|
|
305
|
+
import_fs.default.mkdirSync(import_path.default.dirname(aPath), { recursive: true });
|
|
306
|
+
import_fs.default.writeFileSync(aPath, content);
|
|
307
|
+
}
|
|
308
|
+
function indent(lines, tab) {
|
|
309
|
+
return lines.replace(/^(?=.+$)/gm, tab);
|
|
310
|
+
}
|
|
311
|
+
function determineFileExtension(file) {
|
|
312
|
+
if (typeof file === "string")
|
|
313
|
+
return "txt";
|
|
314
|
+
if (compareMagicBytes(file, [137, 80, 78, 71, 13, 10, 26, 10]))
|
|
315
|
+
return "png";
|
|
316
|
+
if (compareMagicBytes(file, [255, 216, 255]))
|
|
317
|
+
return "jpg";
|
|
318
|
+
return "dat";
|
|
319
|
+
}
|
|
320
|
+
function compareMagicBytes(file, magicBytes) {
|
|
321
|
+
return Buffer.compare(Buffer.from(magicBytes), file.slice(0, magicBytes.length)) === 0;
|
|
322
|
+
}
|
|
323
|
+
async function loadScreenshotStyles(stylePath) {
|
|
324
|
+
if (!stylePath)
|
|
325
|
+
return;
|
|
326
|
+
const stylePaths = Array.isArray(stylePath) ? stylePath : [stylePath];
|
|
327
|
+
const styles = await Promise.all(stylePaths.map(async (stylePath2) => {
|
|
328
|
+
const text = await import_fs.default.promises.readFile(stylePath2, "utf8");
|
|
329
|
+
return text.trim();
|
|
330
|
+
}));
|
|
331
|
+
return styles.join("\n").trim() || void 0;
|
|
332
|
+
}
|
|
333
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
334
|
+
0 && (module.exports = {
|
|
335
|
+
toHaveScreenshot,
|
|
336
|
+
toHaveScreenshotStepTitle,
|
|
337
|
+
toMatchSnapshot
|
|
338
|
+
});
|
|
@@ -0,0 +1,105 @@
|
|
|
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("@ohos-ports/playwright-core/lib/utils");
|
|
25
|
+
var import_util = require("../util");
|
|
26
|
+
var import_expect = require("./expect");
|
|
27
|
+
var import_matcherHint = require("./matcherHint");
|
|
28
|
+
var import_expectBundle = require("../common/expectBundle");
|
|
29
|
+
async function toMatchText(matcherName, receiver, receiverType, query, expected, options = {}) {
|
|
30
|
+
(0, import_util.expectTypes)(receiver, [receiverType], matcherName);
|
|
31
|
+
const matcherOptions = {
|
|
32
|
+
isNot: this.isNot,
|
|
33
|
+
promise: this.promise
|
|
34
|
+
};
|
|
35
|
+
if (!(typeof expected === "string") && !(expected && typeof expected.test === "function")) {
|
|
36
|
+
throw new Error([
|
|
37
|
+
(0, import_matcherHint.matcherHint)(this, receiverType === "Locator" ? receiver : void 0, matcherName, options.receiverLabel ?? receiver, expected, matcherOptions),
|
|
38
|
+
`${import_utils.colors.bold("Matcher error")}: ${(0, import_expectBundle.EXPECTED_COLOR)("expected")} value must be a string or regular expression`,
|
|
39
|
+
this.utils.printWithType("Expected", expected, this.utils.printExpected)
|
|
40
|
+
].join("\n\n"));
|
|
41
|
+
}
|
|
42
|
+
const timeout = options.timeout ?? this.timeout;
|
|
43
|
+
const { matches: pass, received, log, timedOut } = await query(!!this.isNot, timeout);
|
|
44
|
+
if (pass === !this.isNot) {
|
|
45
|
+
return {
|
|
46
|
+
name: matcherName,
|
|
47
|
+
message: () => "",
|
|
48
|
+
pass,
|
|
49
|
+
expected
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const stringSubstring = options.matchSubstring ? "substring" : "string";
|
|
53
|
+
const receivedString = received || "";
|
|
54
|
+
const messagePrefix = (0, import_matcherHint.matcherHint)(this, receiverType === "Locator" ? receiver : void 0, matcherName, options.receiverLabel ?? "locator", void 0, matcherOptions, timedOut ? timeout : void 0);
|
|
55
|
+
const notFound = received === import_matcherHint.kNoElementsFoundError;
|
|
56
|
+
let printedReceived;
|
|
57
|
+
let printedExpected;
|
|
58
|
+
let printedDiff;
|
|
59
|
+
if (pass) {
|
|
60
|
+
if (typeof expected === "string") {
|
|
61
|
+
if (notFound) {
|
|
62
|
+
printedExpected = `Expected ${stringSubstring}: not ${this.utils.printExpected(expected)}`;
|
|
63
|
+
printedReceived = `Received: ${received}`;
|
|
64
|
+
} else {
|
|
65
|
+
printedExpected = `Expected ${stringSubstring}: not ${this.utils.printExpected(expected)}`;
|
|
66
|
+
const formattedReceived = (0, import_expect.printReceivedStringContainExpectedSubstring)(receivedString, receivedString.indexOf(expected), expected.length);
|
|
67
|
+
printedReceived = `Received string: ${formattedReceived}`;
|
|
68
|
+
}
|
|
69
|
+
} else {
|
|
70
|
+
if (notFound) {
|
|
71
|
+
printedExpected = `Expected pattern: not ${this.utils.printExpected(expected)}`;
|
|
72
|
+
printedReceived = `Received: ${received}`;
|
|
73
|
+
} else {
|
|
74
|
+
printedExpected = `Expected pattern: not ${this.utils.printExpected(expected)}`;
|
|
75
|
+
const formattedReceived = (0, import_expect.printReceivedStringContainExpectedResult)(receivedString, typeof expected.exec === "function" ? expected.exec(receivedString) : null);
|
|
76
|
+
printedReceived = `Received string: ${formattedReceived}`;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
const labelExpected = `Expected ${typeof expected === "string" ? stringSubstring : "pattern"}`;
|
|
81
|
+
if (notFound) {
|
|
82
|
+
printedExpected = `${labelExpected}: ${this.utils.printExpected(expected)}`;
|
|
83
|
+
printedReceived = `Received: ${received}`;
|
|
84
|
+
} else {
|
|
85
|
+
printedDiff = this.utils.printDiffOrStringify(expected, receivedString, labelExpected, "Received string", false);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const message = () => {
|
|
89
|
+
const resultDetails = printedDiff ? printedDiff : printedExpected + "\n" + printedReceived;
|
|
90
|
+
return messagePrefix + resultDetails + (0, import_util.callLogText)(log);
|
|
91
|
+
};
|
|
92
|
+
return {
|
|
93
|
+
name: matcherName,
|
|
94
|
+
expected,
|
|
95
|
+
message,
|
|
96
|
+
pass,
|
|
97
|
+
actual: received,
|
|
98
|
+
log,
|
|
99
|
+
timeout: timedOut ? timeout : void 0
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
103
|
+
0 && (module.exports = {
|
|
104
|
+
toMatchText
|
|
105
|
+
});
|